List of usage examples for org.springframework.security.access AuthorizationServiceException AuthorizationServiceException
public AuthorizationServiceException(String msg, Throwable t)
AuthorizationServiceException with the specified message and root cause. From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
/** * Creates an acl./*from www. j av a2 s .c o m*/ * * @param identity which must not be null. * @throws AuthorizationServiceException if an unexpected exception occurred */ @Override public SimpleMutableAcl create(final ObjectIdentity identity) { Assert.notNull(identity, "identity must not be null"); HTableInterface table = getTable(); try { // Need to retrieve the current principal, in order to know who // "owns" this ACL (can be changed later on) Authentication auth = SecurityContextHolder.getContext().getAuthentication(); PrincipalSid owner = new PrincipalSid(auth); SimpleAcl acl = new SimpleAcl(identity, owner, new ArrayList<AccessControlEntry>(), null, util); save(acl, table, new AclRecord(identity, owner, resolveConverter(identity))); return acl; } catch (IOException e) { throw new AuthorizationServiceException("An unexpected exception occurred", e); } finally { close(table); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.AclRecord.java
private Class<?> resolveClass(final byte[] idTypeBytes) { String idString = new String(idTypeBytes); try {//www . ja va2s. c o m return Class.forName(idString); } catch (ClassNotFoundException e) { throw new AuthorizationServiceException("Unable to find class " + idString, e); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
/** * Deletes an acl./*ww w. j av a 2s . co m*/ * * @param identity which must not be null. * @throws AuthorizationServiceException if an unexpected exception occurred */ @Override public void delete(final ObjectIdentity identity) { Assert.notNull(identity, "identity must not be null"); HTableInterface table = getTable(); try { deleteInternal(identity, table); } catch (IOException e) { throw new AuthorizationServiceException("An unexpected exception occurred", e); } finally { close(table); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.AclRecord.java
@SuppressWarnings({ "unchecked", "rawtypes" })
private byte[] createKey(final Serializable identifier, final AclIdentifierConverter converter) {
byte[] toReturn;
if (identifier instanceof byte[]) {
toReturn = (byte[]) identifier;
} else if (converter != null) {
verifyConverterType(converter, identifier.getClass());
try {/*from ww w .j a v a2 s .c om*/
toReturn = converter.toByteArray(identifier);
} catch (Exception e) {
throw new AuthorizationServiceException("An unexpected exception occurred converting from "
+ identifier + " to byte[] using converter " + converter, e);
}
} else {
throw new AuthorizationServiceException(
"No converter configured for identifier type " + identifier.getClass());
}
if (toReturn == null) {
throw new AuthorizationServiceException(
"Null key returned for " + identifier + " and converter " + converter);
}
return toReturn;
}
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
/** * Updates an existing acl. This deletes the existing acl and completely * replaces the row with the new acl./* w w w .java2 s .c om*/ * * @param acl which must not be null. * @throws AuthorizationServiceException if some mandatory aspect of * the supplied acl is null or if an unexpected exception * occurred */ @Override public void update(final MutableAcl acl) { Assert.notNull(acl, "acl must not be null"); HTableInterface table = getTable(); try { ObjectIdentity identity = acl.getObjectIdentity(); AclRecord aclRecord = new AclRecord(identity, acl.getOwner(), resolveConverter(identity)); deleteInternal(aclRecord, table); save(acl, table, aclRecord); } catch (IOException e) { throw new AuthorizationServiceException("An unexpected exception occurred", e); } finally { close(table); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
/** * Returns the corresponding ACL's mapped by the relevant ObjectIdentity. * ObjectIdentities.identifier objects are required to implement one of the * configured keyRetrievalMethods.//w w w . jav a 2 s.com * * @param objectIdentities which must not be null * @param sids which may be null * @return map of ObjectIdentities against the corresponding ACL objects. * @throws AuthorizationServiceException if no zero argument key retrieval * method returning a byte[] could be located for an identifier * or the located method returned a null key or an unexpected * exception occurred. * */ @Override public Map<ObjectIdentity, Acl> getAclsById(final List<ObjectIdentity> objectIdentities, final List<Sid> sids) { Assert.notNull(objectIdentities, "At least one Object Identity required"); Assert.isTrue(objectIdentities.size() > 0, "At least one Object Identity required"); Assert.noNullElements(objectIdentities.toArray(new ObjectIdentity[0]), "Null object identities are not permitted"); HTableInterface table = getTable(); Map<ObjectIdentity, Acl> toReturn = new HashMap<ObjectIdentity, Acl>(); try { Map<Long, ObjectIdentity> identitiesByByteId = new HashMap<Long, ObjectIdentity>(); List<Get> gets = new ArrayList<Get>(); for (ObjectIdentity identity : objectIdentities) { if (!toReturn.containsKey(identity)) { MutableAcl acl = aclCache.getFromCache(identity); if (acl != null) { toReturn.put(identity, acl); } else { AclRecord aclKey = new AclRecord(identity, resolveConverter(identity)); byte[] key = aclKey.getKey(); Long rowId = createRowId(key); if (!identitiesByByteId.containsKey(rowId)) { gets.add(new Get(key)); identitiesByByteId.put(rowId, identity); } } } } if (!gets.isEmpty()) { Result[] results = table.get(gets); Map<ObjectIdentity, Acl> resultsFromDB = mapResults(sids, identitiesByByteId, results); toReturn.putAll(resultsFromDB); } return toReturn; } catch (IOException e) { throw new AuthorizationServiceException("An unexpected exception occurred", e); } finally { close(table); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
@Override public boolean isThereAnAclFor(final ObjectIdentity identity) { Assert.notNull(identity, "Object Identity required"); HTableInterface table = getTable();/* ww w. j a va 2s.c om*/ try { AclRecord aclKey = new AclRecord(identity, resolveConverter(identity)); Get get = new Get(aclKey.getKey()); return table.exists(get); } catch (IOException e) { throw new AuthorizationServiceException("An unexpected exception occurred", e); } finally { close(table); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.HBaseACLRepository.java
/** * Closes the provided table. This should always be called within a finally * block whenever a table is being used. * /*from ww w. j a v a 2 s. c o m*/ * @param table */ private void close(final HTableInterface table) { try { table.close(); } catch (IOException e) { throw new AuthorizationServiceException("Unable to close table " + ACL_TABLE, e); } }