| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.afterinvocation; |
| 17 |
|
|
| 18 |
|
import org.acegisecurity.Authentication; |
| 19 |
|
import org.acegisecurity.ConfigAttribute; |
| 20 |
|
|
| 21 |
|
import org.acegisecurity.acls.Acl; |
| 22 |
|
import org.acegisecurity.acls.AclService; |
| 23 |
|
import org.acegisecurity.acls.NotFoundException; |
| 24 |
|
import org.acegisecurity.acls.Permission; |
| 25 |
|
import org.acegisecurity.acls.domain.BasePermission; |
| 26 |
|
import org.acegisecurity.acls.objectidentity.ObjectIdentity; |
| 27 |
|
import org.acegisecurity.acls.objectidentity.ObjectIdentityRetrievalStrategy; |
| 28 |
|
import org.acegisecurity.acls.objectidentity.ObjectIdentityRetrievalStrategyImpl; |
| 29 |
|
import org.acegisecurity.acls.sid.Sid; |
| 30 |
|
import org.acegisecurity.acls.sid.SidRetrievalStrategy; |
| 31 |
|
import org.acegisecurity.acls.sid.SidRetrievalStrategyImpl; |
| 32 |
|
|
| 33 |
|
import org.springframework.util.Assert; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
public abstract class AbstractAclProvider implements AfterInvocationProvider { |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
private AclService aclService; |
| 46 |
0 |
private Class processDomainObjectClass = Object.class; |
| 47 |
0 |
private ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl(); |
| 48 |
0 |
private SidRetrievalStrategy sidRetrievalStrategy = new SidRetrievalStrategyImpl(); |
| 49 |
|
private String processConfigAttribute; |
| 50 |
0 |
private Permission[] requirePermission = {BasePermission.READ}; |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
0 |
public AbstractAclProvider(AclService aclService, String processConfigAttribute, Permission[] requirePermission) { |
| 55 |
0 |
Assert.hasText(processConfigAttribute, "A processConfigAttribute is mandatory"); |
| 56 |
0 |
Assert.notNull(aclService, "An AclService is mandatory"); |
| 57 |
|
|
| 58 |
0 |
if ((requirePermission == null) || (requirePermission.length == 0)) { |
| 59 |
0 |
throw new IllegalArgumentException("One or more requirePermission entries is mandatory"); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
0 |
this.aclService = aclService; |
| 63 |
0 |
this.processConfigAttribute = processConfigAttribute; |
| 64 |
0 |
this.requirePermission = requirePermission; |
| 65 |
0 |
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
protected Class getProcessDomainObjectClass() { |
| 70 |
0 |
return processDomainObjectClass; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
protected boolean hasPermission(Authentication authentication, Object domainObject) { |
| 74 |
|
|
| 75 |
0 |
ObjectIdentity objectIdentity = objectIdentityRetrievalStrategy.getObjectIdentity(domainObject); |
| 76 |
|
|
| 77 |
|
|
| 78 |
0 |
Sid[] sids = sidRetrievalStrategy.getSids(authentication); |
| 79 |
|
|
| 80 |
0 |
Acl acl = null; |
| 81 |
|
|
| 82 |
|
try { |
| 83 |
|
|
| 84 |
0 |
acl = aclService.readAclById(objectIdentity, sids); |
| 85 |
|
|
| 86 |
0 |
return acl.isGranted(requirePermission, sids, false); |
| 87 |
0 |
} catch (NotFoundException ignore) { |
| 88 |
0 |
return false; |
| 89 |
|
} |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
public void setObjectIdentityRetrievalStrategy(ObjectIdentityRetrievalStrategy objectIdentityRetrievalStrategy) { |
| 93 |
0 |
Assert.notNull(objectIdentityRetrievalStrategy, "ObjectIdentityRetrievalStrategy required"); |
| 94 |
0 |
this.objectIdentityRetrievalStrategy = objectIdentityRetrievalStrategy; |
| 95 |
0 |
} |
| 96 |
|
|
| 97 |
|
protected void setProcessConfigAttribute(String processConfigAttribute) { |
| 98 |
0 |
Assert.hasText(processConfigAttribute, "A processConfigAttribute is mandatory"); |
| 99 |
0 |
this.processConfigAttribute = processConfigAttribute; |
| 100 |
0 |
} |
| 101 |
|
|
| 102 |
|
public void setProcessDomainObjectClass(Class processDomainObjectClass) { |
| 103 |
0 |
Assert.notNull(processDomainObjectClass, "processDomainObjectClass cannot be set to null"); |
| 104 |
0 |
this.processDomainObjectClass = processDomainObjectClass; |
| 105 |
0 |
} |
| 106 |
|
|
| 107 |
|
public void setSidRetrievalStrategy(SidRetrievalStrategy sidRetrievalStrategy) { |
| 108 |
0 |
Assert.notNull(sidRetrievalStrategy, "SidRetrievalStrategy required"); |
| 109 |
0 |
this.sidRetrievalStrategy = sidRetrievalStrategy; |
| 110 |
0 |
} |
| 111 |
|
|
| 112 |
|
public boolean supports(ConfigAttribute attribute) { |
| 113 |
0 |
if ((attribute.getAttribute() != null) && attribute.getAttribute().equals(this.processConfigAttribute)) { |
| 114 |
0 |
return true; |
| 115 |
|
} else { |
| 116 |
0 |
return false; |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
public boolean supports(Class clazz) { |
| 128 |
0 |
return true; |
| 129 |
|
} |
| 130 |
|
} |