List of usage examples for org.springframework.security.acls.model AlreadyExistsException AlreadyExistsException
public AlreadyExistsException(String msg)
AlreadyExistsException
with the specified message. From source file:org.jtalks.common.security.acl.JtalksMutableAcService.java
/** * {@inheritDoc}//from ww w . ja v a2 s . c o m */ @Override public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException { Assert.notNull(objectIdentity, "Object Identity required"); // Check this object identity hasn't already been persisted if (retrieveObjectIdentityPrimaryKey(objectIdentity) != null) { throw new AlreadyExistsException("Object identity '" + objectIdentity + "' already exists"); } // Need to retrieve the current principal, in order to know who "owns" this ACL (can be changed later on) Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Sid sid = sidFactory.createPrincipal(auth); createObjectIdentity(objectIdentity, sid); // Retrieve the ACL via superclass (ensures cache registration, proper retrieval etc) Acl acl = readAclById(objectIdentity); Assert.isInstanceOf(MutableAcl.class, acl, "MutableAcl should be been returned"); return (MutableAcl) acl; }
From source file:com.cedac.security.acls.mongo.MongoMutableAclService.java
@Override public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException { Assert.notNull(objectIdentity, "Object Identity required"); LOG.trace(ACL, "Checking that object identity {} hasn't already been persisted", objectIdentity); DBObject result = getAclCollection().findOne(queryByObjectIdentity(objectIdentity)); if (result != null) { LOG.warn(ACL, "An ACL entry for object identity {} already exists.", objectIdentity); throw new AlreadyExistsException("Object identity '" + objectIdentity + "' already exists"); }// w w w .j a v a 2 s. c o m LOG.trace(ACL, "Retrieving current principal in order to know who owns this ACL."); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); PrincipalSid sid = new PrincipalSid(auth); LOG.debug(ACL, "Creating ACL entry."); DBObject ownerSid = new BasicDBObject(principalFieldName, true).append(sidFieldName, sid.getPrincipal()); DBObject objectId = new BasicDBObject(classFieldName, objectIdentity.getType()).append(identityFieldName, objectIdentity.getIdentifier()); DBObject acl = new BasicDBObject(ownerFieldName, ownerSid).append(objectIdFieldName, objectId) .append(entriesInheritingFieldName, true); getAclCollection().insert(acl, writeConcern); LOG.trace(ACL, "Retrieving back ACL using superclass."); return (MutableAcl) readAclById(objectIdentity); }
From source file:net.projectmonkey.spring.acl.service.SimpleACLService.java
@Override public SimpleMutableAcl createAcl(final ObjectIdentity identity) throws AlreadyExistsException { Assert.notNull(identity, "identity must not be null"); if (aclRepository.isThereAnAclFor(identity)) { throw new AlreadyExistsException("Acl already exists for identity " + identity + " this implementation requires globally unique identifiers"); }/*from ww w .ja va 2 s. c o m*/ return aclRepository.create(identity); }
From source file:com.kylinolap.rest.service.AclService.java
@Override public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException { Acl acl = null;// w w w . ja va 2 s . c o m try { acl = readAclById(objectIdentity); } catch (NotFoundException e) { } if (null != acl) { throw new AlreadyExistsException("ACL of " + objectIdentity + " exists!"); } Authentication auth = SecurityContextHolder.getContext().getAuthentication(); PrincipalSid sid = new PrincipalSid(auth); HTableInterface htable = null; try { htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName); Put put = new Put(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier()))); put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN), Bytes.toBytes(objectIdentity.getType())); put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_OWNER_COLUMN), sidSerializer.serialize(new SidInfo(sid))); put.add(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_ENTRY_INHERIT_COLUMN), Bytes.toBytes(true)); htable.put(put); htable.flushCommits(); logger.debug("ACL of " + objectIdentity + " created successfully."); } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); } finally { IOUtils.closeQuietly(htable); } return (MutableAcl) readAclById(objectIdentity); }
From source file:org.aon.esolutions.appconfig.web.controller.EnvironmentController.java
@Transactional @RequestMapping(value = "/{environmentName}", method = RequestMethod.PUT) public Environment addEnvironment(@PathVariable String applicationName, @PathVariable String environmentName, @RequestParam("parentId") String parentId) throws Exception { try {// w w w .ja va 2 s. c om getEnvironment(applicationName, environmentName); throw new AlreadyExistsException( "Environment " + environmentName + " already exists for Application " + applicationName); } catch (NotFoundException e) { // Good, it doesn't exist....lets go add one. } Application app = applicationRepository.findByName(applicationName); Environment parent = null; if (parentId != null) parent = environmentRepository.findOne(Long.parseLong(parentId)); Environment newEnv = new Environment(); newEnv.setName(environmentName); newEnv.setParent(parent); app.addEnvironment(newEnv); updateKeys(newEnv); newEnv = environmentRepository.save(newEnv); return newEnv; }
From source file:org.apache.kylin.rest.service.AclService.java
@Override public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException { Acl acl = null;// w ww. j a va 2 s . c om try { acl = readAclById(objectIdentity); } catch (NotFoundException e) { //do nothing? } if (null != acl) { throw new AlreadyExistsException("ACL of " + objectIdentity + " exists!"); } Authentication auth = SecurityContextHolder.getContext().getAuthentication(); PrincipalSid sid = new PrincipalSid(auth); HTableInterface htable = null; try { htable = aclHBaseStorage.getTable(aclTableName); Put put = new Put(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier()))); put.add(Bytes.toBytes(AclHBaseStorage.ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN), Bytes.toBytes(objectIdentity.getType())); put.add(Bytes.toBytes(AclHBaseStorage.ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_OWNER_COLUMN), sidSerializer.serialize(new SidInfo(sid))); put.add(Bytes.toBytes(AclHBaseStorage.ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_ENTRY_INHERIT_COLUMN), Bytes.toBytes(true)); htable.put(put); htable.flushCommits(); logger.debug("ACL of " + objectIdentity + " created successfully."); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } return (MutableAcl) readAclById(objectIdentity); }
From source file:org.apache.kylin.rest.service.LegacyAclService.java
@Override public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException { Acl acl = null;/*from w w w .jav a 2s .c om*/ try { acl = readAclById(objectIdentity); } catch (NotFoundException e) { //do nothing? } if (null != acl) { throw new AlreadyExistsException("ACL of " + objectIdentity + " exists!"); } Authentication auth = SecurityContextHolder.getContext().getAuthentication(); PrincipalSid sid = new PrincipalSid(auth); Table htable = null; try { htable = aclHBaseStorage.getTable(aclTableName); Put put = new Put(Bytes.toBytes(String.valueOf(objectIdentity.getIdentifier()))); put.addColumn(Bytes.toBytes(AclHBaseStorage.ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN), Bytes.toBytes(objectIdentity.getType())); put.addColumn(Bytes.toBytes(AclHBaseStorage.ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_OWNER_COLUMN), sidSerializer.serialize(new SidInfo(sid))); put.addColumn(Bytes.toBytes(AclHBaseStorage.ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_ENTRY_INHERIT_COLUMN), Bytes.toBytes(true)); htable.put(put); logger.debug("ACL of " + objectIdentity + " created successfully."); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } return (MutableAcl) readAclById(objectIdentity); }