74
74
*
75
75
* @author Ben Alex
76
76
*/
77
- public final class BasicLookupStrategy implements LookupStrategy {
77
+ public class BasicLookupStrategy implements LookupStrategy {
78
78
79
79
public final static String DEFAULT_SELECT_CLAUSE = "select acl_object_identity.object_id_identity, "
80
80
+ "acl_entry.ace_order, "
@@ -256,7 +256,7 @@ public void setValues(PreparedStatement ps) throws SQLException {
256
256
* should not throw {@link NotFoundException}, as a chain of {@link LookupStrategy}s may be used
257
257
* to automatically create entries if required)
258
258
*/
259
- public Map <ObjectIdentity , Acl > readAclsById (List <ObjectIdentity > objects , List <Sid > sids ) {
259
+ public final Map <ObjectIdentity , Acl > readAclsById (List <ObjectIdentity > objects , List <Sid > sids ) {
260
260
Assert .isTrue (batchSize >= 1 , "BatchSize must be >= 1" );
261
261
Assert .notEmpty (objects , "Objects to lookup required" );
262
262
@@ -428,17 +428,33 @@ private AclImpl convert(Map<Serializable, Acl> inputMap, Long currentIdentity) {
428
428
return result ;
429
429
}
430
430
431
+ /**
432
+ * Creates a particular implementation of {@link Sid} depending on the arguments.
433
+ *
434
+ * @param sid the name of the sid representing its unique identifier. In typical ACL database schema it's
435
+ * located in table {@code acl_sid} table, {@code sid} column.
436
+ * @param isPrincipal whether it's a user or granted authority like role
437
+ * @return the instance of Sid with the {@code sidName} as an identifier
438
+ */
439
+ protected Sid createSid (boolean isPrincipal , String sid ) {
440
+ if (isPrincipal ) {
441
+ return new PrincipalSid (sid );
442
+ } else {
443
+ return new GrantedAuthoritySid (sid );
444
+ }
445
+ }
446
+
431
447
/**
432
448
* Sets the {@code PermissionFactory} instance which will be used to convert loaded permission
433
449
* data values to {@code Permission}s. A {@code DefaultPermissionFactory} will be used by default.
434
450
*
435
451
* @param permissionFactory
436
452
*/
437
- public void setPermissionFactory (PermissionFactory permissionFactory ) {
453
+ public final void setPermissionFactory (PermissionFactory permissionFactory ) {
438
454
this .permissionFactory = permissionFactory ;
439
455
}
440
456
441
- public void setBatchSize (int batchSize ) {
457
+ public final void setBatchSize (int batchSize ) {
442
458
this .batchSize = batchSize ;
443
459
}
444
460
@@ -448,28 +464,28 @@ public void setBatchSize(int batchSize) {
448
464
*
449
465
* @param selectClause the select clause, which defaults to {@link #DEFAULT_SELECT_CLAUSE}.
450
466
*/
451
- public void setSelectClause (String selectClause ) {
467
+ public final void setSelectClause (String selectClause ) {
452
468
this .selectClause = selectClause ;
453
469
}
454
470
455
471
/**
456
472
* The SQL for the where clause used in the <tt>lookupPrimaryKey</tt> method.
457
473
*/
458
- public void setLookupPrimaryKeysWhereClause (String lookupPrimaryKeysWhereClause ) {
474
+ public final void setLookupPrimaryKeysWhereClause (String lookupPrimaryKeysWhereClause ) {
459
475
this .lookupPrimaryKeysWhereClause = lookupPrimaryKeysWhereClause ;
460
476
}
461
477
462
478
/**
463
479
* The SQL for the where clause used in the <tt>lookupObjectIdentities</tt> method.
464
480
*/
465
- public void setLookupObjectIdentitiesWhereClause (String lookupObjectIdentitiesWhereClause ) {
481
+ public final void setLookupObjectIdentitiesWhereClause (String lookupObjectIdentitiesWhereClause ) {
466
482
this .lookupObjectIdentitiesWhereClause = lookupObjectIdentitiesWhereClause ;
467
483
}
468
484
469
485
/**
470
486
* The SQL for the "order by" clause used in both queries.
471
487
*/
472
- public void setOrderByClause (String orderByClause ) {
488
+ public final void setOrderByClause (String orderByClause ) {
473
489
this .orderByClause = orderByClause ;
474
490
}
475
491
@@ -556,13 +572,7 @@ private void convertCurrentResultIntoObject(Map<Serializable, Acl> acls, ResultS
556
572
}
557
573
558
574
boolean entriesInheriting = rs .getBoolean ("entries_inheriting" );
559
- Sid owner ;
560
-
561
- if (rs .getBoolean ("acl_principal" )) {
562
- owner = new PrincipalSid (rs .getString ("acl_sid" ));
563
- } else {
564
- owner = new GrantedAuthoritySid (rs .getString ("acl_sid" ));
565
- }
575
+ Sid owner = createSid (rs .getBoolean ("acl_principal" ), rs .getString ("acl_sid" ));
566
576
567
577
acl = new AclImpl (objectIdentity , id , aclAuthorizationStrategy , grantingStrategy , parentAcl , null ,
568
578
entriesInheriting , owner );
@@ -574,13 +584,7 @@ private void convertCurrentResultIntoObject(Map<Serializable, Acl> acls, ResultS
574
584
// It is permissible to have no ACEs in an ACL (which is detected by a null ACE_SID)
575
585
if (rs .getString ("ace_sid" ) != null ) {
576
586
Long aceId = new Long (rs .getLong ("ace_id" ));
577
- Sid recipient ;
578
-
579
- if (rs .getBoolean ("ace_principal" )) {
580
- recipient = new PrincipalSid (rs .getString ("ace_sid" ));
581
- } else {
582
- recipient = new GrantedAuthoritySid (rs .getString ("ace_sid" ));
583
- }
587
+ Sid recipient = createSid (rs .getBoolean ("ace_principal" ), rs .getString ("ace_sid" ));
584
588
585
589
int mask = rs .getInt ("mask" );
586
590
Permission permission = permissionFactory .buildFromMask (mask );
0 commit comments