Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
App Blocks
Commits
a66c7405
Commit
a66c7405
authored
May 31, 2017
by
Matija Obreza
Browse files
Refactored for Genesys
parent
9e3f5da5
Changes
15
Hide whitespace changes
Inline
Side-by-side
auditlog/src/main/java/org/genesys/blocks/auditlog/service/ClassPKService.java
View file @
a66c7405
...
...
@@ -32,14 +32,6 @@ public interface ClassPKService {
*/
ClassPK
getClassPk
(
Class
<?>
class1
);
/**
* Get classPk id
*
* @param classname
* @return id of persisted class
*/
Long
getClassPkId
(
String
classname
);
/**
* Get classPk classname
*
...
...
@@ -48,4 +40,6 @@ public interface ClassPKService {
*/
String
getClassName
(
Long
id
);
ClassPK
findByShortName
(
String
classPKShortName
);
}
auditlog/src/main/java/org/genesys/blocks/auditlog/service/impl/ClassPKServiceImpl.java
View file @
a66c7405
...
...
@@ -15,9 +15,11 @@
*/
package
org.genesys.blocks.auditlog.service.impl
;
import
org.genesys.blocks.auditlog.persistence.ClassPKRepository
;
import
javax.persistence.PersistenceException
;
import
org.genesys.blocks.auditlog.service.ClassPKService
;
import
org.genesys.blocks.model.ClassPK
;
import
org.genesys.blocks.persistence.ClassPKRepository
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -53,6 +55,7 @@ public class ClassPKServiceImpl implements ClassPKService {
}
classPk
=
new
ClassPK
();
classPk
.
setClassname
(
class1
.
getName
());
classPk
.
setShortName
(
generateShortPkName
(
class1
.
getSimpleName
().
toLowerCase
()));
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Persisting new ClassPK for classname={}"
,
classPk
.
getClassname
());
...
...
@@ -61,23 +64,27 @@ public class ClassPKServiceImpl implements ClassPKService {
return
classPkRepository
.
save
(
classPk
);
}
@Override
@Transactional
(
isolation
=
Isolation
.
DEFAULT
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
Long
getClassPkId
(
final
String
classname
)
{
ClassPK
classPK
=
classPkRepository
.
getByClassname
(
classname
);
if
(
classPK
!=
null
)
{
return
classPK
.
getId
();
}
classPK
=
new
ClassPK
();
classPK
.
setClassname
(
classname
);
private
String
generateShortPkName
(
String
shortName
)
{
ClassPK
classPk
=
null
;
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Persisting new ClassPK for classname={}"
,
classname
);
}
classPK
=
classPkRepository
.
save
(
classPK
);
return
classPK
.
getId
();
String
candidate
=
shortName
;
int
i
=
0
;
do
{
classPk
=
classPkRepository
.
findByShortName
(
candidate
);
if
(
classPk
==
null
)
{
// No other candidate, we're good!
return
candidate
;
}
i
++;
// "shortName1", "shortName2"...
candidate
=
shortName
+
i
;
}
while
(
i
<
10
);
throw
new
PersistenceException
(
"Can't generate a shortName for ClassPK for "
+
shortName
);
}
@Override
@Transactional
(
isolation
=
Isolation
.
DEFAULT
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
String
getClassName
(
final
Long
id
)
{
...
...
@@ -85,4 +92,9 @@ public class ClassPKServiceImpl implements ClassPKService {
return
classPK
.
getClassname
();
}
@Override
public
ClassPK
findByShortName
(
String
classPKShortName
)
{
return
classPkRepository
.
findByShortName
(
classPKShortName
);
}
}
auditlog/src/test/java/org/genesys/blocks/auditlog/model/AuditLogEntityTest.java
View file @
a66c7405
...
...
@@ -23,9 +23,9 @@ import java.util.Date;
import
org.genesys.blocks.auditlog.model.AuditAction
;
import
org.genesys.blocks.auditlog.model.AuditLog
;
import
org.genesys.blocks.auditlog.persistence.AuditLogRepository
;
import
org.genesys.blocks.auditlog.persistence.ClassPKRepository
;
import
org.genesys.blocks.auditlog.test.EntityTest
;
import
org.genesys.blocks.model.ClassPK
;
import
org.genesys.blocks.persistence.ClassPKRepository
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataIntegrityViolationException
;
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/model/ClassPKEntityTest.java
View file @
a66c7405
...
...
@@ -18,9 +18,9 @@ package org.genesys.blocks.auditlog.model;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
org.genesys.blocks.auditlog.persistence.ClassPKRepository
;
import
org.genesys.blocks.auditlog.test.EntityTest
;
import
org.genesys.blocks.model.ClassPK
;
import
org.genesys.blocks.persistence.ClassPKRepository
;
import
org.junit.Test
;
import
org.springframework.dao.DataIntegrityViolationException
;
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/test/BaseTest.java
View file @
a66c7405
...
...
@@ -23,9 +23,9 @@ import java.util.List;
import
org.genesys.blocks.auditlog.model.AuditLog
;
import
org.genesys.blocks.auditlog.persistence.AuditLogRepository
;
import
org.genesys.blocks.auditlog.persistence.ClassPKRepository
;
import
org.genesys.blocks.auditlog.service.ClassPKService
;
import
org.genesys.blocks.model.EntityId
;
import
org.genesys.blocks.persistence.ClassPKRepository
;
import
org.junit.runner.RunWith
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/test/DatabaseConfig.java
View file @
a66c7405
...
...
@@ -48,7 +48,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableJpaRepositories
(
basePackages
=
{
"org.genesys.blocks.security.persistence"
,
"org.genesys.blocks.auditlog.persistence"
},
repositoryImplementationPostfix
=
"CustomImpl"
,
entityManagerFactoryRef
=
"entityManagerFactory"
,
transactionManagerRef
=
"transactionManager"
)
"org.genesys.blocks.persistence"
,
"org.genesys.blocks.security.persistence"
,
"org.genesys.blocks.auditlog.persistence"
},
repositoryImplementationPostfix
=
"CustomImpl"
,
entityManagerFactoryRef
=
"entityManagerFactory"
,
transactionManagerRef
=
"transactionManager"
)
@EnableTransactionManagement
@EnableJpaAuditing
(
auditorAwareRef
=
"auditorAware"
,
modifyOnCreate
=
true
)
public
class
DatabaseConfig
{
...
...
core/src/main/java/org/genesys/blocks/model/ClassPK.java
View file @
a66c7405
...
...
@@ -48,6 +48,17 @@ public class ClassPK implements Serializable {
@Column
(
length
=
200
,
updatable
=
false
,
unique
=
true
,
nullable
=
false
)
protected
String
classname
;
@Column
(
length
=
50
,
unique
=
true
)
private
String
shortName
;
public
String
getShortName
()
{
return
shortName
;
}
public
void
setShortName
(
String
shortName
)
{
this
.
shortName
=
shortName
;
}
/**
* Gets the id.
*
...
...
core/src/main/java/org/genesys/blocks/model/EntityId.java
View file @
a66c7405
...
...
@@ -15,10 +15,8 @@
*/
package
org.genesys.blocks.model
;
import
java.io.Serializable
;
public
interface
EntityId
{
Serializable
getId
();
Long
getId
();
}
core/src/main/java/org/genesys/blocks/model/IdUUID.java
View file @
a66c7405
...
...
@@ -43,6 +43,6 @@ import java.util.UUID;
public
interface
IdUUID
{
UUID
getUuid
();
void
setUuid
(
UUID
uuid
);
//
void setUuid(UUID uuid);
}
core/src/main/java/org/genesys/blocks/model/UuidEntity.java
View file @
a66c7405
...
...
@@ -43,7 +43,6 @@ public abstract class UuidEntity extends AuditedVersionedModel implements IdUUID
return
this
.
uuid
;
}
@Override
public
void
setUuid
(
UUID
uuid
)
{
this
.
uuid
=
uuid
;
}
...
...
auditlog
/src/main/java/org/genesys/blocks/
auditlog/
persistence/ClassPKRepository.java
→
core
/src/main/java/org/genesys/blocks/persistence/ClassPKRepository.java
View file @
a66c7405
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys.blocks.
auditlog.
persistence
;
package
org.genesys.blocks.persistence
;
import
org.genesys.blocks.model.ClassPK
;
import
org.springframework.data.jpa.repository.JpaRepository
;
...
...
@@ -35,4 +35,6 @@ public interface ClassPKRepository extends JpaRepository<ClassPK, Long> {
*/
ClassPK
getByClassname
(
String
classname
);
ClassPK
findByShortName
(
String
shortName
);
}
security/src/main/java/org/genesys/blocks/security/model/AclAwareModel.java
View file @
a66c7405
/*
* Copyright 2017 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.security.model
;
import
java.io.Serializable
;
import
org.genesys.blocks.model.EntityId
;
/**
* Interface label for entities that require ACL security
*/
public
interface
AclAwareModel
extends
Serializable
,
EntityId
{
}
security/src/main/java/org/genesys/blocks/security/model/AclClass.java
View file @
a66c7405
/*
* Copyright 2017 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.security.model
;
import
javax.persistence.Column
;
...
...
security/src/main/java/org/genesys/blocks/security/service/CustomAclService.java
View file @
a66c7405
...
...
@@ -8,6 +8,7 @@ import org.genesys.blocks.security.model.AclEntry;
import
org.genesys.blocks.security.model.AclObjectIdentity
;
import
org.genesys.blocks.security.model.AclSid
;
import
org.springframework.security.acls.model.Permission
;
import
org.springframework.security.core.userdetails.UserDetails
;
public
interface
CustomAclService
{
...
...
@@ -44,4 +45,6 @@ public interface CustomAclService {
AclObjectIdentity
ensureObjectIdentity
(
String
className
,
long
objectIdIdentity
);
List
<
Integer
>
permissionsBySid
(
String
className
,
Long
id
,
String
sid
);
List
<
Long
>
listIdentitiesForSid
(
Class
<?
extends
AclAwareModel
>
clazz
,
UserDetails
authUser
,
Permission
permission
);
}
security/src/main/java/org/genesys/blocks/security/service/impl/CustomAclServiceImpl.java
View file @
a66c7405
...
...
@@ -23,6 +23,7 @@ import org.springframework.cache.CacheManager;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.acls.domain.BasePermission
;
import
org.springframework.security.acls.model.Permission
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -315,4 +316,13 @@ public class CustomAclServiceImpl implements CustomAclService {
}
return
list
;
}
@Override
@Transactional
(
readOnly
=
true
)
public
List
<
Long
>
listIdentitiesForSid
(
Class
<?
extends
AclAwareModel
>
clazz
,
UserDetails
authUser
,
Permission
permission
)
{
return
aclEntryPersistence
.
findObjectIdentitiesBySidAndAclClassAndMask
(
authUser
.
getUsername
(),
clazz
.
getName
(),
permission
.
getMask
());
}
}
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