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
8c24e32f
Commit
8c24e32f
authored
Mar 31, 2020
by
Matija Obreza
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '31-hibernate-5' into 'master'
Resolve "Hibernate 5" Closes #31 See merge request genesys-pgr/application-blocks!44
parents
87ca0951
e30abcca
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
118 additions
and
94 deletions
+118
-94
auditlog/pom.xml
auditlog/pom.xml
+4
-4
auditlog/src/main/java/org/genesys/blocks/auditlog/component/AuditTrailInterceptor.java
...esys/blocks/auditlog/component/AuditTrailInterceptor.java
+4
-3
auditlog/src/main/java/org/genesys/blocks/auditlog/persistence/AuditLogRepository.java
...nesys/blocks/auditlog/persistence/AuditLogRepository.java
+2
-2
auditlog/src/main/java/org/genesys/blocks/auditlog/persistence/AuditLogRepositoryCustomImpl.java
...ks/auditlog/persistence/AuditLogRepositoryCustomImpl.java
+2
-2
auditlog/src/main/java/org/genesys/blocks/auditlog/service/impl/AuditTrailServiceImpl.java
...s/blocks/auditlog/service/impl/AuditTrailServiceImpl.java
+1
-1
auditlog/src/main/java/org/genesys/blocks/auditlog/service/impl/ClassPKServiceImpl.java
...esys/blocks/auditlog/service/impl/ClassPKServiceImpl.java
+4
-2
auditlog/src/test/java/org/genesys/blocks/auditlog/model/AuditLogEntityTest.java
...org/genesys/blocks/auditlog/model/AuditLogEntityTest.java
+1
-1
auditlog/src/test/java/org/genesys/blocks/auditlog/model/ClassPKEntityTest.java
.../org/genesys/blocks/auditlog/model/ClassPKEntityTest.java
+3
-1
auditlog/src/test/java/org/genesys/blocks/auditlog/service/AuditTrailServiceTest.java
...enesys/blocks/auditlog/service/AuditTrailServiceTest.java
+2
-2
auditlog/src/test/java/org/genesys/blocks/auditlog/service/impl/ExampleAuditedEntityServiceImpl.java
...uditlog/service/impl/ExampleAuditedEntityServiceImpl.java
+1
-1
auditlog/src/test/java/org/genesys/blocks/auditlog/test/DatabaseConfig.java
...java/org/genesys/blocks/auditlog/test/DatabaseConfig.java
+2
-2
auditlog/src/test/resources/hibernate.properties
auditlog/src/test/resources/hibernate.properties
+1
-0
core/pom.xml
core/pom.xml
+2
-2
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModel.java
.../java/org/genesys/blocks/model/AuditedVersionedModel.java
+2
-3
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModelWithoutId.java
.../genesys/blocks/model/AuditedVersionedModelWithoutId.java
+2
-3
core/src/main/java/org/genesys/blocks/model/UuidModel.java
core/src/main/java/org/genesys/blocks/model/UuidModel.java
+1
-2
core/src/test/java/org/genesys/blocks/config/DatabaseConfig.java
...c/test/java/org/genesys/blocks/config/DatabaseConfig.java
+1
-1
parent/pom.xml
parent/pom.xml
+12
-13
pom.xml
pom.xml
+1
-1
security/pom.xml
security/pom.xml
+19
-5
security/src/main/java/org/genesys/blocks/oauth/persistence/OAuthClientRepository.java
...nesys/blocks/oauth/persistence/OAuthClientRepository.java
+2
-2
security/src/main/java/org/genesys/blocks/oauth/service/OAuthServiceImpl.java
...va/org/genesys/blocks/oauth/service/OAuthServiceImpl.java
+6
-4
security/src/main/java/org/genesys/blocks/security/SpringSecurityAuditorAware.java
...g/genesys/blocks/security/SpringSecurityAuditorAware.java
+6
-4
security/src/main/java/org/genesys/blocks/security/component/AclAssignerAspect.java
.../genesys/blocks/security/component/AclAssignerAspect.java
+5
-2
security/src/main/java/org/genesys/blocks/security/persistence/AclObjectIdentityPersistence.java
...ks/security/persistence/AclObjectIdentityPersistence.java
+2
-2
security/src/main/java/org/genesys/blocks/security/service/impl/BasicUserServiceImpl.java
...ys/blocks/security/service/impl/BasicUserServiceImpl.java
+6
-4
security/src/main/java/org/genesys/blocks/security/service/impl/CustomAclServiceImpl.java
...ys/blocks/security/service/impl/CustomAclServiceImpl.java
+12
-12
security/src/test/java/org/genesys/blocks/oauth/OAuth2GrantTypeTest.java
...st/java/org/genesys/blocks/oauth/OAuth2GrantTypeTest.java
+2
-2
security/src/test/java/org/genesys/blocks/oauth/OAuthClientTest.java
...c/test/java/org/genesys/blocks/oauth/OAuthClientTest.java
+1
-1
security/src/test/java/org/genesys/blocks/security/component/AclAssignerTest.java
...rg/genesys/blocks/security/component/AclAssignerTest.java
+4
-4
security/src/test/java/org/genesys/blocks/security/config/DatabaseConfig.java
...va/org/genesys/blocks/security/config/DatabaseConfig.java
+1
-1
security/src/test/java/org/genesys/blocks/security/rest/AbstractRestTest.java
...va/org/genesys/blocks/security/rest/AbstractRestTest.java
+4
-5
No files found.
auditlog/pom.xml
View file @
8c24e32f
...
...
@@ -19,7 +19,7 @@
<parent>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-parent
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
<relativePath>
../parent/pom.xml
</relativePath>
</parent>
<artifactId>
application-blocks-auditlog
</artifactId>
...
...
@@ -79,13 +79,13 @@
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-security
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-core
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
</dependency>
<dependency>
...
...
@@ -112,7 +112,7 @@
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-
entitymanager
</artifactId>
<artifactId>
hibernate-
core
</artifactId>
<version>
${hibernate.version}
</version>
<scope>
provided
</scope>
</dependency>
...
...
auditlog/src/main/java/org/genesys/blocks/auditlog/component/AuditTrailInterceptor.java
View file @
8c24e32f
...
...
@@ -53,6 +53,7 @@ import org.hibernate.CallbackException;
import
org.hibernate.EmptyInterceptor
;
import
org.hibernate.Transaction
;
import
org.hibernate.collection.spi.PersistentCollection
;
import
org.hibernate.resource.transaction.spi.TransactionStatus
;
import
org.hibernate.type.Type
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -746,7 +747,7 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ
currentAuditLogs
.
stream
().
forEach
(
auditLog
->
{
LOG
.
debug
(
"Audit log to save: {}"
,
auditLog
);
});
if
(
tx
.
wasRolledBack
(
))
{
if
(
tx
.
getStatus
().
equals
(
TransactionStatus
.
ROLLED_BACK
))
{
LOG
.
warn
(
"Transaction was rolled back. Audit logs likely won't be persisted"
);
}
this
.
auditTrailService
.
addAuditLogs
(
currentAuditLogs
);
...
...
@@ -773,9 +774,9 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ
final
long
level
=
auditLogStack
.
get
().
size
();
LOG
.
trace
(
"afterTransactionCompletion transaction level={}"
,
level
);
if
(
tx
.
wasCommitted
(
))
{
if
(
tx
.
getStatus
().
equals
(
TransactionStatus
.
COMMITTED
))
{
LOG
.
trace
(
"Transaction was committed, level={}"
,
level
);
}
else
if
(
tx
.
wasRolledBack
(
))
{
}
else
if
(
tx
.
getStatus
().
equals
(
TransactionStatus
.
ROLLED_BACK
))
{
LOG
.
trace
(
"Transaction was rolled back, level={}"
,
level
);
}
...
...
auditlog/src/main/java/org/genesys/blocks/auditlog/persistence/AuditLogRepository.java
View file @
8c24e32f
...
...
@@ -22,7 +22,7 @@ import org.genesys.blocks.auditlog.model.AuditLog;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.querydsl.Query
D
slPredicateExecutor
;
import
org.springframework.data.querydsl.Query
d
slPredicateExecutor
;
import
org.springframework.stereotype.Repository
;
/**
...
...
@@ -31,7 +31,7 @@ import org.springframework.stereotype.Repository;
* @author Matija Obreza
*/
@Repository
public
interface
AuditLogRepository
extends
AuditLogCustomRepository
,
JpaRepository
<
AuditLog
,
Long
>,
Query
D
slPredicateExecutor
<
AuditLog
>
{
public
interface
AuditLogRepository
extends
AuditLogCustomRepository
,
JpaRepository
<
AuditLog
,
Long
>,
Query
d
slPredicateExecutor
<
AuditLog
>
{
/**
* List audit log entries in descending order (most recent first).
...
...
auditlog/src/main/java/org/genesys/blocks/auditlog/persistence/AuditLogRepositoryCustomImpl.java
View file @
8c24e32f
...
...
@@ -69,7 +69,7 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository {
*/
@Override
public
AuditLog
getLastAuditLog
(
final
EntityId
entity
)
{
final
List
<
AuditLog
>
l
=
repository
.
listAuditLogs
(
entity
.
getClass
().
getName
(),
entity
.
getId
(),
new
PageRequest
(
0
,
1
));
final
List
<
AuditLog
>
l
=
repository
.
listAuditLogs
(
entity
.
getClass
().
getName
(),
entity
.
getId
(),
PageRequest
.
of
(
0
,
1
));
return
(
l
==
null
)
||
l
.
isEmpty
()
?
null
:
l
.
get
(
0
);
}
...
...
@@ -80,7 +80,7 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository {
*/
@Override
public
AuditLog
getLastAuditLog
(
final
EntityId
entity
,
final
String
propertyName
)
{
final
List
<
AuditLog
>
l
=
repository
.
listAuditLogs
(
entity
.
getClass
().
getName
(),
entity
.
getId
(),
propertyName
,
new
PageRequest
(
0
,
1
));
final
List
<
AuditLog
>
l
=
repository
.
listAuditLogs
(
entity
.
getClass
().
getName
(),
entity
.
getId
(),
propertyName
,
PageRequest
.
of
(
0
,
1
));
return
(
l
==
null
)
||
l
.
isEmpty
()
?
null
:
l
.
get
(
0
);
}
...
...
auditlog/src/main/java/org/genesys/blocks/auditlog/service/impl/AuditTrailServiceImpl.java
View file @
8c24e32f
...
...
@@ -72,7 +72,7 @@ public class AuditTrailServiceImpl implements AuditTrailService {
@Override
@Transactional
(
isolation
=
Isolation
.
READ_UNCOMMITTED
,
propagation
=
Propagation
.
REQUIRED
)
public
List
<
AuditLog
>
addAuditLogs
(
final
Set
<
TransactionAuditLog
>
auditLogs
)
{
return
auditLogRepository
.
save
(
auditLogs
.
stream
().
map
(
tlog
->
toAuditLog
(
tlog
)).
collect
(
Collectors
.
toList
()));
return
auditLogRepository
.
save
All
(
auditLogs
.
stream
().
map
(
tlog
->
toAuditLog
(
tlog
)).
collect
(
Collectors
.
toList
()));
}
/*
...
...
auditlog/src/main/java/org/genesys/blocks/auditlog/service/impl/ClassPKServiceImpl.java
View file @
8c24e32f
...
...
@@ -15,6 +15,8 @@
*/
package
org.genesys.blocks.auditlog.service.impl
;
import
java.util.Optional
;
import
javax.persistence.PersistenceException
;
import
org.genesys.blocks.auditlog.service.ClassPKService
;
...
...
@@ -96,8 +98,8 @@ public class ClassPKServiceImpl implements ClassPKService {
@Override
@Transactional
(
isolation
=
Isolation
.
DEFAULT
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
String
getClassName
(
final
Long
id
)
{
final
ClassPK
classPK
=
classPkRepository
.
findOne
(
id
);
return
classPK
.
getClassname
(
);
Optional
<
ClassPK
>
classPK
=
classPkRepository
.
findById
(
id
);
return
classPK
.
map
(
ClassPK:
:
getClassname
).
orElse
(
null
);
}
/*
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/model/AuditLogEntityTest.java
View file @
8c24e32f
...
...
@@ -71,7 +71,7 @@ public class AuditLogEntityTest extends EntityTest<AuditLog, AuditLogRepository>
repository
.
save
(
log
);
assertThat
(
log
.
getId
(),
not
(
nullValue
()));
final
AuditLog
l
=
repository
.
find
One
(
log
.
getId
()
);
final
AuditLog
l
=
repository
.
find
ById
(
log
.
getId
()).
orElse
(
null
);
assertThat
(
l
,
not
(
nullValue
()));
assertThat
(
l
.
getId
(),
equalTo
(
log
.
getId
()));
assertThat
(
l
.
getClassPk
(),
not
(
nullValue
()));
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/model/ClassPKEntityTest.java
View file @
8c24e32f
...
...
@@ -16,6 +16,7 @@
package
org.genesys.blocks.auditlog.model
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
org.genesys.blocks.auditlog.test.EntityTest
;
...
...
@@ -60,7 +61,8 @@ public class ClassPKEntityTest extends EntityTest<ClassPK, ClassPKRepository> {
public
void
successfulPersist
()
{
final
ClassPK
cpk
=
repository
.
save
(
makeClassPK
(
Long
.
class
));
final
ClassPK
l
=
repository
.
findOne
(
cpk
.
getId
());
final
ClassPK
l
=
repository
.
findById
(
cpk
.
getId
()).
orElse
(
null
);
assertThat
(
l
,
notNullValue
());
assertThat
(
l
.
getId
(),
equalTo
(
cpk
.
getId
()));
assertThat
(
l
.
getClassname
(),
equalTo
(
cpk
.
getClassname
()));
}
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/service/AuditTrailServiceTest.java
View file @
8c24e32f
...
...
@@ -291,12 +291,12 @@ public class AuditTrailServiceTest extends ServiceTest {
other1
=
otherEntityRepository
.
save
(
other1
);
OtherEntity
other2
=
new
OtherEntity
(
"Other2"
);
other2
=
otherEntityRepository
.
save
(
other2
);
ExampleAuditedEntity
entity
=
new
ExampleAuditedEntity
();
entity
.
setName
(
"Test 1"
);
entity
=
exampleAuditedEntityService
.
save
(
entity
);
assertThat
(
listAuditLogs
(
entity
),
hasSize
(
0
));
entity
.
setOthers
(
Arrays
.
asList
(
other1
));
entity
=
exampleAuditedEntityService
.
save
(
entity
);
assertThat
(
listAuditLogs
(
entity
),
hasSize
(
1
));
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/service/impl/ExampleAuditedEntityServiceImpl.java
View file @
8c24e32f
...
...
@@ -64,7 +64,7 @@ public class ExampleAuditedEntityServiceImpl implements ExampleAuditedEntityServ
@Override
public
ExampleAuditedEntity
get
(
Long
id
)
{
return
exampleAuditedEntityRepository
.
find
One
(
id
);
return
exampleAuditedEntityRepository
.
find
ById
(
id
).
orElse
(
null
);
}
}
auditlog/src/test/java/org/genesys/blocks/auditlog/test/DatabaseConfig.java
View file @
8c24e32f
...
...
@@ -37,7 +37,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
import
org.springframework.data.jpa.repository.config.EnableJpaAuditing
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.orm.hibernate
4
.HibernateExceptionTranslator
;
import
org.springframework.orm.hibernate
5
.HibernateExceptionTranslator
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
;
...
...
@@ -140,7 +140,7 @@ public class DatabaseConfig {
// LOG.trace("JPA: " + key + " = " + jpaProperties.get(key));
// }
jpaProperties
.
put
(
"hibernate.
ejb
.interceptor"
,
new
EmptyInterceptor
()
{
jpaProperties
.
put
(
"hibernate.
session_factory
.interceptor"
,
new
EmptyInterceptor
()
{
private
static
final
long
serialVersionUID
=
412280557897728434L
;
// NOTE We're using the auditTrailInterceptor() to fetch the lazy-initialized
...
...
auditlog/src/test/resources/hibernate.properties
View file @
8c24e32f
...
...
@@ -24,3 +24,4 @@ hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFa
hibernate.cache.use_structured_entries
=
false
hibernate.generate_statistics
=
false
hibernate.id.new_generator_mappings
=
false
core/pom.xml
View file @
8c24e32f
...
...
@@ -19,7 +19,7 @@
<parent>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-parent
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
<relativePath>
../parent/pom.xml
</relativePath>
</parent>
<artifactId>
application-blocks-core
</artifactId>
...
...
@@ -105,7 +105,7 @@
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-
entitymanager
</artifactId>
<artifactId>
hibernate-
core
</artifactId>
<version>
${hibernate.version}
</version>
<scope>
provided
</scope>
</dependency>
...
...
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModel.java
View file @
8c24e32f
...
...
@@ -26,7 +26,6 @@ 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
org.springframework.data.elasticsearch.annotations.FieldType
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
...
...
@@ -48,7 +47,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@CreatedBy
@Column
(
updatable
=
false
)
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
type
=
FieldType
.
String
,
index
=
FieldIndex
.
not_analyzed
)
@Field
(
type
=
FieldType
.
Text
,
index
=
false
)
@JsonProperty
(
access
=
Access
.
READ_ONLY
)
private
Long
createdBy
;
...
...
@@ -62,7 +61,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@JsonView
(
JsonViews
.
Protected
.
class
)
@LastModifiedBy
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
type
=
FieldType
.
String
,
index
=
FieldIndex
.
not_analyzed
)
@Field
(
type
=
FieldType
.
Text
,
index
=
false
)
@JsonProperty
(
access
=
Access
.
READ_ONLY
)
private
Long
lastModifiedBy
;
...
...
core/src/main/java/org/genesys/blocks/model/AuditedVersionedModelWithoutId.java
View file @
8c24e32f
...
...
@@ -26,7 +26,6 @@ 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
org.springframework.data.elasticsearch.annotations.FieldType
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
...
...
@@ -48,7 +47,7 @@ public abstract class AuditedVersionedModelWithoutId extends VersionedModelWitho
@CreatedBy
@Column
(
updatable
=
false
)
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
type
=
FieldType
.
String
,
index
=
FieldIndex
.
not_analyzed
)
@Field
(
type
=
FieldType
.
Text
,
index
=
false
)
@JsonProperty
(
access
=
Access
.
READ_ONLY
)
private
Long
createdBy
;
...
...
@@ -62,7 +61,7 @@ public abstract class AuditedVersionedModelWithoutId extends VersionedModelWitho
@JsonView
(
JsonViews
.
Protected
.
class
)
@LastModifiedBy
@JsonSerialize
(
converter
=
JsonSidConverter
.
class
)
@Field
(
type
=
FieldType
.
String
,
index
=
FieldIndex
.
not_analyzed
)
@Field
(
type
=
FieldType
.
Text
,
index
=
false
)
@JsonProperty
(
access
=
Access
.
READ_ONLY
)
private
Long
lastModifiedBy
;
...
...
core/src/main/java/org/genesys/blocks/model/UuidModel.java
View file @
8c24e32f
...
...
@@ -23,7 +23,6 @@ import javax.persistence.PrePersist;
import
org.hibernate.annotations.Type
;
import
org.springframework.data.elasticsearch.annotations.Field
;
import
org.springframework.data.elasticsearch.annotations.FieldIndex
;
import
org.springframework.data.elasticsearch.annotations.FieldType
;
import
com.fasterxml.jackson.annotation.JsonIdentityInfo
;
...
...
@@ -42,7 +41,7 @@ public abstract class UuidModel extends AuditedVersionedModel implements IdUUID
/** The uuid. */
@Column
(
unique
=
true
,
updatable
=
false
,
nullable
=
false
)
@Type
(
type
=
"uuid-binary"
)
@Field
(
type
=
FieldType
.
String
,
store
=
false
,
index
=
FieldIndex
.
not_analyzed
)
@Field
(
type
=
FieldType
.
Text
,
index
=
false
)
protected
UUID
uuid
;
/**
...
...
core/src/test/java/org/genesys/blocks/config/DatabaseConfig.java
View file @
8c24e32f
...
...
@@ -28,7 +28,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
import
org.springframework.data.jpa.repository.config.EnableJpaAuditing
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.orm.hibernate
4
.HibernateExceptionTranslator
;
import
org.springframework.orm.hibernate
5
.HibernateExceptionTranslator
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
;
...
...
parent/pom.xml
View file @
8c24e32f
...
...
@@ -19,7 +19,7 @@
<parent>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
</parent>
<artifactId>
application-blocks-parent
</artifactId>
<packaging>
pom
</packaging>
...
...
@@ -40,17 +40,16 @@
<nexus-staging-maven-plugin.version>
1.6.8
</nexus-staging-maven-plugin.version>
<
aspectj.version>
1.7.2
</aspectj
.version>
<
jackson.version>
2.7.7
</jackson
.version>
<spring.
version>
4.3.2.RELEASE
</spring
.version>
<spring.
data.version>
1.10.4.RELEASE
</spring.data
.version>
<spring.security.oauth2.version>
2.0.11.RELEASE
</spring.security.oauth2
.version>
<
querydsl.version>
4.1.4
</querydsl
.version>
<
spring.security.version>
4.1.3.RELEASE
</spring.security.version
>
<hibernate.version>
4.3.11
.Final
</hibernate.version>
<hsqldb.version>
2.
4
.0
</hsqldb.version>
<
jackson.version>
2.10.1
</jackson
.version>
<
spring.version>
5.2.4.RELEASE
</spring
.version>
<spring.
data.version>
2.2.5.RELEASE
</spring.data
.version>
<spring.
security.oauth2.version>
2.3.4.RELEASE
</spring.security.oauth2
.version>
<querydsl.version>
4.2.1
</querydsl
.version>
<
spring.security.version>
5.2.2.RELEASE
</spring.security
.version>
<
!--<hibernate.version>5.3.15.Final</hibernate.version>--
>
<hibernate.version>
5.4.12
.Final
</hibernate.version>
<hsqldb.version>
2.
5
.0
</hsqldb.version>
<tomcat-jdbc.version>
8.5.8
</tomcat-jdbc.version>
<ehcache.version>
2.7.4
</ehcache.version>
</properties>
<repositories>
...
...
@@ -185,7 +184,7 @@
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-
entitymanager
</artifactId>
<artifactId>
hibernate-
core
</artifactId>
<version>
${hibernate.version}
</version>
<scope>
provided
</scope>
</dependency>
...
...
@@ -221,7 +220,7 @@
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-elasticsearch
</artifactId>
<version>
2.1.1
5.RELEASE
</version>
<version>
3.2.
5.RELEASE
</version>
<scope>
provided
</scope>
<exclusions>
<exclusion>
...
...
pom.xml
View file @
8c24e32f
...
...
@@ -18,7 +18,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
<packaging>
pom
</packaging>
<name>
Application Building Blocks
</name>
<description>
This is the shared project pom.
</description>
...
...
security/pom.xml
View file @
8c24e32f
...
...
@@ -19,7 +19,7 @@
<parent>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-parent
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
<relativePath>
../parent/pom.xml
</relativePath>
</parent>
<artifactId>
application-blocks-security
</artifactId>
...
...
@@ -80,12 +80,12 @@
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
application-blocks-core
</artifactId>
<version>
1.6
-SNAPSHOT
</version>
<version>
2.0
-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-
entitymanager
</artifactId>
<artifactId>
hibernate-
core
</artifactId>
<version>
${hibernate.version}
</version>
<scope>
provided
</scope>
</dependency>
...
...
@@ -103,7 +103,14 @@
<version>
${spring.security.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-config
</artifactId>
<version>
${spring.security.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-test
</artifactId>
...
...
@@ -139,6 +146,13 @@
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<version>
${spring.version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-aspects
</artifactId>
...
...
@@ -155,7 +169,7 @@
<dependency>
<groupId>
com.fasterxml.jackson.datatype
</groupId>
<artifactId>
jackson-datatype-hibernate
4
</artifactId>
<artifactId>
jackson-datatype-hibernate
5
</artifactId>
<version>
${jackson.version}
</version>
<scope>
test
</scope>
</dependency>
...
...
security/src/main/java/org/genesys/blocks/oauth/persistence/OAuthClientRepository.java
View file @
8c24e32f
...
...
@@ -19,14 +19,14 @@ import org.genesys.blocks.oauth.model.OAuthClient;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.querydsl.Query
D
slPredicateExecutor
;
import
org.springframework.data.querydsl.Query
d
slPredicateExecutor
;
import
org.springframework.stereotype.Repository
;
/**
* The Interface OAuthClientRepository.
*/
@Repository
public
interface
OAuthClientRepository
extends
JpaRepository
<
OAuthClient
,
Long
>,
Query
D
slPredicateExecutor
<
OAuthClient
>
{
public
interface
OAuthClientRepository
extends
JpaRepository
<
OAuthClient
,
Long
>,
Query
d
slPredicateExecutor
<
OAuthClient
>
{
/**
* Find by client id.
...
...
security/src/main/java/org/genesys/blocks/oauth/service/OAuthServiceImpl.java
View file @
8c24e32f
...
...
@@ -44,6 +44,8 @@ import org.springframework.transaction.annotation.Transactional;
import
com.querydsl.core.types.Predicate
;
import
javax.persistence.EntityNotFoundException
;
/**
* The Class OAuthServiceImpl.
*/
...
...
@@ -97,7 +99,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
*/
@Override
public
List
<
OAuthClient
>
listClientDetails
()
{
return
oauthClientRepository
.
findAll
(
new
Sort
(
"clientId"
));
return
oauthClientRepository
.
findAll
(
Sort
.
by
(
"clientId"
));
}
@Override
...
...
@@ -212,14 +214,14 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
// description contains
.
or
(
QOAuthClient
.
oAuthClient
.
description
.
contains
(
term
));
return
oauthClientRepository
.
findAll
(
predicate
,
new
PageRequest
(
0
,
Math
.
min
(
100
,
limit
),
new
Sort
(
"title"
))).
getContent
();
return
oauthClientRepository
.
findAll
(
predicate
,
PageRequest
.
of
(
0
,
Math
.
min
(
100
,
limit
),
Sort
.
by
(
"title"
))).
getContent
();
}
@Override
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')"
)
public
final
String
resetSecret
(
OAuthClient
oauthClient
)
{
oauthClient
=
oauthClientRepository
.
find
One
(
oauthClient
.
getId
(
));
oauthClient
=
oauthClientRepository
.
find
ById
(
oauthClient
.
getId
()).
orElseThrow
(()
->
new
EntityNotFoundException
(
"Record not found."
));
String
oldHash
=
oauthClient
.
getClientSecret
();
String
newHash
=
null
;
...
...
@@ -238,7 +240,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')"
)
public
final
OAuthClient
removeSecret
(
OAuthClient
oauthClient
)
{
oauthClient
=
oauthClientRepository
.
find
One
(
oauthClient
.
getId
(
));
oauthClient
=
oauthClientRepository
.
find
ById
(
oauthClient
.
getId
()).
orElseThrow
(()
->
new
EntityNotFoundException
(
"Record not found."
));
if
(
oauthClient
.
getAuthorizedGrantTypes
().
contains
(
"client_credentials"
))
{
throw
new
RuntimeException
(
"OAuth Client with client_credentials grant must have a secret"
);
}
...
...
security/src/main/java/org/genesys/blocks/security/SpringSecurityAuditorAware.java
View file @
8c24e32f
...
...
@@ -15,6 +15,8 @@
*/
package
org.genesys.blocks.security
;
import
java.util.Optional
;
import
org.genesys.blocks.security.model.AclSid
;
import
org.genesys.blocks.security.service.CustomAclService
;
import
org.slf4j.Logger
;
...
...
@@ -42,22 +44,22 @@ public class SpringSecurityAuditorAware implements AuditorAware<Long> {
* @see org.springframework.data.domain.AuditorAware#getCurrentAuditor()
*/
@Override
public
Long
getCurrentAuditor
()
{
public
Optional
<
Long
>
getCurrentAuditor
()
{
final
Authentication
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
if
(
authentication
!=
null
)
{
Object
principal
=
authentication
.
getPrincipal
();
if
(
principal
instanceof
AclSid
)
{
return
((
AclSid
)
principal
).
getId
(
);
return
Optional
.
of
(((
AclSid
)
principal
).
getId
()
);
}
else
if
(
principal
instanceof
String
)
{
return
aclService
.
getSidId
((
String
)
principal
);
return
Optional
.
of
(
aclService
.
getSidId
((
String
)
principal
)
);
}
else
{
LOG
.
warn
(
"Principal {} is not AclSid, but type {}. Auth of type {}"
,
principal
,
principal
.
getClass
(),
authentication
.
getClass
());
}
}
LOG
.
info
(
"No security principal available."
);
return
null
;
return
Optional
.
empty
()
;
}
}
security/src/main/java/org/genesys/blocks/security/component/AclAssignerAspect.java
View file @
8c24e32f
...
...
@@ -60,7 +60,7 @@ public class AclAssignerAspect {
* @param result the result
* @return the object
*/
@AfterReturning
(
pointcut
=
"execution(* org.springframework.data.repository.*.save(..)) || execution(* org.springframework.data.jpa.repository.*.save(..)) || execution(* org.springframework.data.jpa.repository.*.saveAndFlush(..))"
,
returning
=
"result"
)
@AfterReturning
(
pointcut
=
"execution(* org.springframework.data.repository.*.save(..)) || execution(* org.springframework.data.
repository.*.saveAll(..)) || execution(* org.springframework.data.
jpa.repository.*.save(..)) || execution(* org.springframework.data.jpa.repository.*.saveAndFlush(..))"
,
returning
=
"result"
)
public
Object
afterSaveAclObject
(
final
Object
result
)
{
final
Authentication
auth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
...
...
@@ -99,8 +99,11 @@ public class AclAssignerAspect {
*
* @param joinPoint the join point
*/
@Before
(
"execution(* org.springframework.data.repository.*.delete(..)) || execution(* org.springframework.data.jpa.repository.*.deleteInBatch(..))"
)
@Before
(
"execution(* org.springframework.data.repository.*.delete(..)) || execution(* org.springframework.data.
repository.*.deleteAll(..)) || execution(* org.springframework.data.
jpa.repository.*.deleteInBatch(..))"
)
public
void
afterDeleteAclObject
(
final
JoinPoint
joinPoint
)
{
if
(
joinPoint
.
getArgs
().
length
==
0
)
{
return
;
}
final
Object
arg0
=
joinPoint
.
getArgs
()[
0
];
try
{
...
...
security/src/main/java/org/genesys/blocks/security/persistence/AclObjectIdentityPersistence.java
View file @
8c24e32f
...
...
@@ -21,13 +21,13 @@ import org.genesys.blocks.security.model.AclObjectIdentity;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.querydsl.Query
D
slPredicateExecutor
;
import
org.springframework.data.querydsl.Query
d
slPredicateExecutor
;
import
org.springframework.data.repository.query.Param
;
/**
* The Interface AclObjectIdentityPersistence.
*/
public
interface
AclObjectIdentityPersistence
extends
JpaRepository
<
AclObjectIdentity
,
Long
>,
Query
D
slPredicateExecutor
<
AclObjectIdentity
>
{
public
interface
AclObjectIdentityPersistence
extends
JpaRepository
<
AclObjectIdentity
,
Long
>,
Query
d
slPredicateExecutor
<
AclObjectIdentity
>
{
/**
* Find by object id identity and class name.
...
...
security/src/main/java/org/genesys/blocks/security/service/impl/BasicUserServiceImpl.java
View file @
8c24e32f
...
...
@@ -43,6 +43,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.EntityNotFoundException
;
/**
* The Class BasicUserServiceImpl.
*
...
...
@@ -174,7 +176,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
*/
@Override
public
T
getUser
(
final
long
id
)
{
final
T
user
=
_repository
.
find
One
(
id
);
final
T
user
=
_repository
.
find
ById
(
id
).
orElse
(
null
);
return
deepLoad
(
user
);
}