List of usage examples for org.springframework.security.util FieldUtils getField
public static Field getField(Class<?> clazz, String fieldName) throws IllegalStateException
From source file:org.gaixie.micrite.security.service.impl.AclServiceImpl.java
@SuppressWarnings("unchecked") public Map readAclsById(ObjectIdentity[] objects, Sid[] sids) throws NotFoundException { final Map acls = new HashMap(); for (ObjectIdentity object : objects) { // ?Object?acl // ?ObjectclassNameid String javaType = object.getJavaType().getName(); AclClass aclClass = aclClassDAO.findByClass(javaType); // No need to check for nulls, as guaranteed non-null by ObjectIdentity.getIdentifier() interface contract String identifier = object.getIdentifier().toString(); long id = (Long.valueOf(identifier)).longValue(); AclObjectIdentity aclObjectIdentity = aclObjectIdentityDAO.findByObjectId(aclClass.getId(), id); // ?acl?aclaces // spring securityacl? if (aclObjectIdentity == null) { throw new NotFoundException("Could not found specified aclObjectIdentity."); // AclImpl acl = new AclImpl(object, 0, // aclAuthorizationStrategy, auditLogger, // null, null, false, new GrantedAuthoritySid("ROLE_ADMIN")); // acls.put(object, acl); // continue; }//from w w w. jav a2s .c o m AclSid aclOwnerSid = aclObjectIdentity.getAclSid(); Sid owner; if (aclOwnerSid.isPrincipal()) { owner = new PrincipalSid(aclOwnerSid.getSid()); } else { owner = new GrantedAuthoritySid(aclOwnerSid.getSid()); } AclImpl acl = new AclImpl(object, aclObjectIdentity.getId(), aclAuthorizationStrategy, auditLogger, null, null, false, owner); acls.put(object, acl); Field acesField = FieldUtils.getField(AclImpl.class, "aces"); List aces; try { acesField.setAccessible(true); aces = (List) acesField.get(acl); } catch (IllegalAccessException ex) { throw new IllegalStateException( "Could not obtain AclImpl.ace field: cause[" + ex.getMessage() + "]"); } List<AclEntry> aclEntrys = aclEntryDAO.findByIdentityId(aclObjectIdentity.getId()); for (AclEntry aclEntry : aclEntrys) { AclSid aclSid = aclEntry.getAclSid(); Sid recipient; if (aclSid.isPrincipal()) { recipient = new PrincipalSid(aclSid.getSid()); } else { recipient = new GrantedAuthoritySid(aclSid.getSid()); } int mask = aclEntry.getMask(); Permission permission = convertMaskIntoPermission(mask); boolean granting = aclEntry.isGranting(); boolean auditSuccess = aclEntry.isAuditSuccess(); boolean auditFailure = aclEntry.isAuditFailure(); AccessControlEntryImpl ace = new AccessControlEntryImpl(aclEntry.getId(), acl, recipient, permission, granting, auditSuccess, auditFailure); // Add the ACE if it doesn't already exist in the ACL.aces field if (!aces.contains(ace)) { aces.add(ace); } } } return acls; }