Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
App Blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Genesys PGR
App Blocks
Commits
e136701b
Commit
e136701b
authored
Dec 24, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serialize Audited `lastModifiedBy` and `createdBy` using JsonSidConverter
- Fields are marked as not indexed in ES
parent
a3c4dfd2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
3 deletions
+108
-3
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModel.java
.../java/org/genesys/blocks/model/AuditedVersionedModel.java
+10
-2
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModelWithoutId.java
.../genesys/blocks/model/AuditedVersionedModelWithoutId.java
+8
-0
core/src/main/java/org/genesys/blocks/util/JsonSidConverter.java
...c/main/java/org/genesys/blocks/util/JsonSidConverter.java
+55
-0
parent/pom.xml
parent/pom.xml
+13
-0
security/src/main/java/org/genesys/blocks/security/service/CustomAclService.java
...org/genesys/blocks/security/service/CustomAclService.java
+10
-1
security/src/main/java/org/genesys/blocks/security/service/impl/CustomAclServiceImpl.java
...ys/blocks/security/service/impl/CustomAclServiceImpl.java
+12
-0
No files found.
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModel.java
View file @
e136701b
...
...
@@ -20,12 +20,16 @@ import java.util.Date;
import
javax.persistence.Column
;
import
javax.persistence.MappedSuperclass
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
org.genesys.blocks.util.JsonSidConverter
;
import
org.springframework.data.annotation.CreatedBy
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedBy
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.elasticsearch.annotations.Field
;
import
org.springframework.data.elasticsearch.annotations.FieldIndex
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
/**
* The Class AuditedVersionedModel.
...
...
@@ -40,6 +44,8 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@JsonView
(
JsonViews
.
Protected
.
class
)
@CreatedBy
@Column
(
updatable
=
false
)
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
index
=
FieldIndex
.
no
)
private
Long
createdBy
;
/** The created date. */
...
...
@@ -51,6 +57,8 @@ public abstract class AuditedVersionedModel extends VersionedModel {
/** The last modified by. */
@JsonView
(
JsonViews
.
Protected
.
class
)
@LastModifiedBy
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
index
=
FieldIndex
.
no
)
private
Long
lastModifiedBy
;
/** The last modified date. */
...
...
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModelWithoutId.java
View file @
e136701b
...
...
@@ -21,11 +21,15 @@ import javax.persistence.Column;
import
javax.persistence.MappedSuperclass
;
import
com.fasterxml.jackson.annotation.JsonView
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
org.genesys.blocks.util.JsonSidConverter
;
import
org.springframework.data.annotation.CreatedBy
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedBy
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.elasticsearch.annotations.Field
;
import
org.springframework.data.elasticsearch.annotations.FieldIndex
;
/**
* The Class AuditedVersionedModelWithoutId.
...
...
@@ -40,6 +44,8 @@ public abstract class AuditedVersionedModelWithoutId extends VersionedModelWitho
@JsonView
(
JsonViews
.
Protected
.
class
)
@CreatedBy
@Column
(
updatable
=
false
)
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
index
=
FieldIndex
.
no
)
private
Long
createdBy
;
/** The created date. */
...
...
@@ -51,6 +57,8 @@ public abstract class AuditedVersionedModelWithoutId extends VersionedModelWitho
/** The last modified by. */
@JsonView
(
JsonViews
.
Protected
.
class
)
@LastModifiedBy
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
index
=
FieldIndex
.
no
)
private
Long
lastModifiedBy
;
/** The last modified date. */
...
...
core/src/main/java/org/genesys/blocks/util/JsonSidConverter.java
0 → 100644
View file @
e136701b
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys.blocks.util
;
import
com.fasterxml.jackson.databind.util.StdConverter
;
/**
* The JsonSidConverter converts SID IDs to SID names.
*/
public
class
JsonSidConverter
extends
StdConverter
<
Long
,
Object
>
{
private
static
SidProvider
SID_PROVIDER
;
public
static
interface
SidProvider
{
String
getSidName
(
long
id
);
}
/**
* Sets the sid provider.
*
* @param sidProvider the new sid provider
*/
public
static
void
setSidProvider
(
SidProvider
sidProvider
)
{
SID_PROVIDER
=
sidProvider
;
}
/**
* Convert SID ID to SID name using SID_PROVIDER (when available)
*/
@Override
public
Object
convert
(
Long
value
)
{
if
(
value
==
null
)
{
return
null
;
}
else
{
if
(
SID_PROVIDER
==
null
)
{
return
value
;
}
else
{
return
SID_PROVIDER
.
getSidName
(
value
);
}
}
}
}
parent/pom.xml
View file @
e136701b
...
...
@@ -218,6 +218,19 @@
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-elasticsearch
</artifactId>
<version>
2.1.15.RELEASE
</version>
<scope>
provided
</scope>
<exclusions>
<exclusion>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>
junit
</groupId>
...
...
security/src/main/java/org/genesys/blocks/security/service/CustomAclService.java
View file @
e136701b
...
...
@@ -17,6 +17,7 @@ package org.genesys.blocks.security.service;
import
java.util.List
;
import
org.genesys.blocks.util.JsonSidConverter
;
import
org.genesys.blocks.security.model.AclAwareModel
;
import
org.genesys.blocks.security.model.AclClass
;
import
org.genesys.blocks.security.model.AclEntry
;
...
...
@@ -29,7 +30,7 @@ import org.springframework.security.acls.model.Permission;
/**
* The Interface CustomAclService.
*/
public
interface
CustomAclService
{
public
interface
CustomAclService
extends
JsonSidConverter
.
SidProvider
{
/**
* Gets the available permissions.
...
...
@@ -236,4 +237,12 @@ public interface CustomAclService {
* @return the sid id
*/
Long
getSidId
(
String
sid
);
/**
* Gets the sid name.
*
* @param id the id
* @return the sid name
*/
String
getSidName
(
long
id
);
}
security/src/main/java/org/genesys/blocks/security/service/impl/CustomAclServiceImpl.java
View file @
e136701b
...
...
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.acls.domain.BasePermission
;
...
...
@@ -94,9 +95,19 @@ public class CustomAclServiceImpl implements CustomAclService {
public
AclSid
getSid
(
Long
id
)
{
return
aclSidPersistence
.
findOne
(
id
);
}
@Override
@Transactional
(
readOnly
=
true
)
@Cacheable
(
cacheNames
=
{
"aclSidNames"
},
key
=
"#id"
,
unless
=
"#result == null"
)
public
String
getSidName
(
long
id
)
{
AclSid
sid
=
aclSidPersistence
.
findOne
(
id
);
return
sid
==
null
?
null
:
sid
.
getSid
();
}
@Override
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
REQUIRES_NEW
,
isolation
=
Isolation
.
READ_UNCOMMITTED
)
@Cacheable
(
cacheNames
=
{
"aclSidNames"
},
key
=
"#sid"
,
unless
=
"#result == null"
)
public
Long
getSidId
(
String
sid
)
{
return
aclSidPersistence
.
getSidId
(
sid
);
}
...
...
@@ -688,4 +699,5 @@ public class CustomAclServiceImpl implements CustomAclService {
}
LOG
.
warn
(
"Done cleaning ACL for {} ACL classes"
,
aclClasses
.
size
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment