-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add ObjectIdentityGenerator customization to JdbcAclService #10081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,14 +35,14 @@ | |
import org.springframework.core.convert.ConversionService; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.ResultSetExtractor; | ||
import org.springframework.security.acls.domain.*; | ||
import org.springframework.security.acls.domain.AccessControlEntryImpl; | ||
import org.springframework.security.acls.domain.AclAuthorizationStrategy; | ||
import org.springframework.security.acls.domain.AclImpl; | ||
import org.springframework.security.acls.domain.AuditLogger; | ||
import org.springframework.security.acls.domain.DefaultPermissionFactory; | ||
import org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy; | ||
import org.springframework.security.acls.domain.GrantedAuthoritySid; | ||
import org.springframework.security.acls.domain.ObjectIdentityImpl; | ||
import org.springframework.security.acls.domain.PermissionFactory; | ||
import org.springframework.security.acls.domain.PrincipalSid; | ||
import org.springframework.security.acls.model.AccessControlEntry; | ||
|
@@ -51,6 +51,7 @@ | |
import org.springframework.security.acls.model.MutableAcl; | ||
import org.springframework.security.acls.model.NotFoundException; | ||
import org.springframework.security.acls.model.ObjectIdentity; | ||
import org.springframework.security.acls.model.ObjectIdentityGenerator; | ||
import org.springframework.security.acls.model.Permission; | ||
import org.springframework.security.acls.model.PermissionGrantingStrategy; | ||
import org.springframework.security.acls.model.Sid; | ||
|
@@ -109,6 +110,8 @@ public class BasicLookupStrategy implements LookupStrategy { | |
|
||
private final AclAuthorizationStrategy aclAuthorizationStrategy; | ||
|
||
private ObjectIdentityGenerator objectIdentityGenerator; | ||
|
||
private PermissionFactory permissionFactory = new DefaultPermissionFactory(); | ||
|
||
private final AclCache aclCache; | ||
|
@@ -134,6 +137,7 @@ public class BasicLookupStrategy implements LookupStrategy { | |
|
||
private AclClassIdUtils aclClassIdUtils; | ||
|
||
|
||
/** | ||
* Constructor accepting mandatory arguments | ||
* @param dataSource to access the database | ||
|
@@ -152,8 +156,9 @@ public BasicLookupStrategy(DataSource dataSource, AclCache aclCache, | |
* @param aclAuthorizationStrategy authorization strategy (required) | ||
* @param grantingStrategy the PermissionGrantingStrategy | ||
*/ | ||
public BasicLookupStrategy(DataSource dataSource, AclCache aclCache, | ||
AclAuthorizationStrategy aclAuthorizationStrategy, PermissionGrantingStrategy grantingStrategy) { | ||
public BasicLookupStrategy(DataSource dataSource, AclCache aclCache, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a constructor parameter breaks backward compatibility, so I would recommend that this be moved to a setter. Additionally, it's quite common in Spring Security for required members to be constructor parameters and optional members to have setters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setter should also confirm that the provided strategy is not null. |
||
AclAuthorizationStrategy aclAuthorizationStrategy, PermissionGrantingStrategy grantingStrategy) { | ||
|
||
Assert.notNull(dataSource, "DataSource required"); | ||
Assert.notNull(aclCache, "AclCache required"); | ||
Assert.notNull(aclAuthorizationStrategy, "AclAuthorizationStrategy required"); | ||
|
@@ -162,6 +167,7 @@ public BasicLookupStrategy(DataSource dataSource, AclCache aclCache, | |
this.aclCache = aclCache; | ||
this.aclAuthorizationStrategy = aclAuthorizationStrategy; | ||
this.grantingStrategy = grantingStrategy; | ||
this.objectIdentityGenerator = new ObjectIdentityRetrievalStrategyImpl(); | ||
this.aclClassIdUtils = new AclClassIdUtils(); | ||
this.fieldAces.setAccessible(true); | ||
this.fieldAcl.setAccessible(true); | ||
|
@@ -488,6 +494,11 @@ public final void setAclClassIdSupported(boolean aclClassIdSupported) { | |
} | ||
} | ||
|
||
public void setObjectIdentityGenerator(ObjectIdentityGenerator objectIdentityGenerator) { | ||
Assert.notNull(objectIdentityGenerator,"The provided strategy has to be not null!"); | ||
this.objectIdentityGenerator = objectIdentityGenerator; | ||
} | ||
|
||
public final void setConversionService(ConversionService conversionService) { | ||
this.aclClassIdUtils = new AclClassIdUtils(conversionService); | ||
} | ||
|
@@ -569,7 +580,7 @@ private void convertCurrentResultIntoObject(Map<Serializable, Acl> acls, ResultS | |
// target id type, e.g. UUID. | ||
Serializable identifier = (Serializable) rs.getObject("object_id_identity"); | ||
identifier = BasicLookupStrategy.this.aclClassIdUtils.identifierFrom(identifier, rs); | ||
ObjectIdentity objectIdentity = new ObjectIdentityImpl(rs.getString("class"), identifier); | ||
ObjectIdentity objectIdentity = objectIdentityGenerator.createObjectIdentity(identifier,rs.getString("class")); | ||
|
||
Acl parentAcl = null; | ||
long parentAclId = rs.getLong("parent_object"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies, I didn't notice this earlier. Let's please leave package imports exploded. Ideally, import ordering should not change in a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for that, that happens when you press strg+ shift + o too much. Will fix this!