List of usage examples for org.springframework.security.acls.model ObjectIdentity getType
String getType();
From source file:org.jtalks.common.service.security.DtoLookupStrategyTest.java
@Test public void testReadAclsByIdUsingMapping() { when(mapper.getMapping(c1.class.getCanonicalName())).thenReturn(c2.class); ObjectIdentity mappedIdentity = mock(ObjectIdentity.class); when(mappedIdentity.getType()).thenReturn(c2.class.getCanonicalName()); when(mappedIdentity.getIdentifier()).thenReturn(1L); List<ObjectIdentity> mappedObjects = new ArrayList<ObjectIdentity>(); mappedObjects.add(mappedIdentity);//w w w . j a v a 2s .co m Map<ObjectIdentity, Acl> result = sut.readAclsById(objects, sids); ObjectIdentity actualArgument = stragegyCallArgument.get(0); assertEquals(actualArgument.getType(), mappedIdentity.getType()); assertEquals(actualArgument.getIdentifier(), mappedIdentity.getIdentifier()); assertEquals(result.keySet().iterator().next().getType(), c1.class.getCanonicalName()); }
From source file:org.jtalks.common.service.security.DtoLookupStrategyTest.java
@BeforeMethod public void setUp() { mapper = mock(DtoMapper.class); strategy = mock(LookupStrategy.class); when(strategy.readAclsById(anyListOf(ObjectIdentity.class), anyListOf(Sid.class))) .thenAnswer(new Answer<Map<ObjectIdentity, Acl>>() { @Override/*from ww w . ja v a2s . co m*/ public Map<ObjectIdentity, Acl> answer(InvocationOnMock invocation) throws Throwable { stragegyCallArgument = (List<ObjectIdentity>) invocation.getArguments()[0]; Map<ObjectIdentity, Acl> result = new HashMap<ObjectIdentity, Acl>(); result.put(stragegyCallArgument.get(0), null); return result; } }); ObjectIdentity identity = mock(ObjectIdentity.class); when(identity.getType()).thenReturn(c1.class.getCanonicalName()); when(identity.getIdentifier()).thenReturn(1L); objects = new ArrayList<ObjectIdentity>(); objects.add(identity); sids = new ArrayList<Sid>(); sut = new DtoLookupStrategy(strategy, mapper); }
From source file:org.jtalks.common.service.security.DtoLookupStrategyTest.java
@Test public void testMultipleDtoOnSameEntityMappings() { when(mapper.getMapping(c1.class.getCanonicalName())).thenReturn(c2.class); when(mapper.getMapping(c3.class.getCanonicalName())).thenReturn(c2.class); ObjectIdentity mappedIdentity = mock(ObjectIdentity.class); when(mappedIdentity.getType()).thenReturn(c1.class.getCanonicalName()); when(mappedIdentity.getIdentifier()).thenReturn(1L); ObjectIdentity secondMappedIdentity = mock(ObjectIdentity.class); when(secondMappedIdentity.getType()).thenReturn(c3.class.getCanonicalName()); when(secondMappedIdentity.getIdentifier()).thenReturn(1L); List<ObjectIdentity> mappedObjects = new ArrayList<ObjectIdentity>(); mappedObjects.add(mappedIdentity);//from w ww.j ava 2 s . c om mappedObjects.add(secondMappedIdentity); Map<ObjectIdentity, Acl> result = sut.readAclsById(mappedObjects, sids); assertEquals(stragegyCallArgument.size(), mappedObjects.size()); assertEquals(stragegyCallArgument.get(0).getType(), c2.class.getCanonicalName()); assertEquals(stragegyCallArgument.get(1).getType(), c2.class.getCanonicalName()); assertTrue(result.containsKey(mappedIdentity)); assertTrue(result.containsKey(secondMappedIdentity)); }
From source file:org.jtalks.common.security.DtoLookupStrategy.java
/** * This method returns {@link ObjectIdentity} mapped to provided one using the following logic: * <ul>// w w w . j ava 2s . c o m * <li>If no mapping found for the identity type, same object is returned;</li> * <li>Instead, a new {@link ObjectIdentity} is created with the type mapped to the type of the original * identity and with the same identifier.</li> * </ul> * * @param identity Original identity * @return Mapped identity as described above. */ private ObjectIdentity getMappedIdentity(ObjectIdentity identity) { ObjectIdentity result = identity; String identityClass = identity.getType(); Class identityMappedTo = mapper.getMapping(identityClass); if (identityMappedTo != null) { result = new ObjectIdentityImpl(identityMappedTo.getCanonicalName(), identity.getIdentifier()); } return result; }
From source file:com.cedac.security.acls.mongo.MongoMutableAclService.java
protected DBObject toDBObject(ObjectIdentity oid) { return new BasicDBObject(classFieldName, oid.getType()).append(identityFieldName, oid.getIdentifier()); }
From source file:com.excilys.ebi.bank.service.impl.security.BankAclService.java
@Override @Cacheable(cacheName = IConstants.Cache.ACL_CACHE, keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator")) @Transactional(readOnly = true)/* www . j a v a2 s. c om*/ public Acl readAclById(ObjectIdentity object, List<Sid> sids) throws NotFoundException { SimpleAclImpl acl = new SimpleAclImpl(object); logger.info("type={} id={}", object.getType(), object.getIdentifier()); for (Sid sid : sids) { if (sid instanceof GrantedAuthoritySid && GrantedAuthoritySid.class.cast(sid).getGrantedAuthority().equals(Role.ROLE_ADMIN.name())) { acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.READ, true)); acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.WRITE, true)); acl.getEntries() .add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.ADMINISTRATION, true)); } else if (sid instanceof PrincipalSid) { Integer accountId = Integer.class.cast(object.getIdentifier()); String login = ((PrincipalSid) sid).getPrincipal(); Assert.notNull(accountId, "accountId is required"); Assert.notNull(login, "login is required"); if (accountDao.isAccountOfUser(accountId, login)) { acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.READ, true)); acl.getEntries().add(new SimpleAccessControlEntryImpl(acl, sid, BasePermission.WRITE, true)); } } } return acl; }
From source file:com.cedac.security.acls.mongo.MongoAclService.java
protected final DBObject queryByObjectIdentity(ObjectIdentity oid) { return new BasicDBObject(qualifiedObjectIdClassFieldName, oid.getType()) .append(qualifiedObjectIdIdentityFieldName, oid.getIdentifier().toString()); }
From source file:com.cedac.security.acls.mongo.MongoAclService.java
protected final DBObject queryByParentIdentity(ObjectIdentity oid) { return new BasicDBObject(qualifiedParentObjectClassFieldName, oid.getType()) .append(qualifiedParentObjectIdentityFieldName, oid.getIdentifier().toString()); }
From source file:org.bremersee.common.security.acls.jdbc.BasicLookupStrategy.java
/** * Looks up a batch of <code>ObjectIdentity</code>s directly from the database. * <p>// ww w . ja v a 2s .c o m * The caller is responsible for optimization issues, such as selecting the identities * to lookup, ensuring the cache doesn't contain them already, and adding the returned * elements to the cache etc. * <p> * This subclass is required to return fully valid <code>Acl</code>s, including * properly-configured parent ACLs. * */ private Map<ObjectIdentity, Acl> lookupObjectIdentities(final Collection<ObjectIdentity> objectIdentities, List<Sid> sids) { Assert.notEmpty(objectIdentities, "Must provide identities to lookup"); final Map<Serializable, Acl> acls = new HashMap<>(); // contains // Acls // with // StubAclParents // Make the "acls" map contain all requested objectIdentities // (including markers to each parent in the hierarchy) String sql = computeRepeatingSql(lookupObjectIdentitiesWhereClause, objectIdentities.size()); Set<Long> parentsToLookup = jdbcTemplate.query(sql, new PreparedStatementSetter() { // NOSONAR @Override public void setValues(PreparedStatement ps) throws SQLException { int i = 0; for (ObjectIdentity oid : objectIdentities) { // Determine prepared statement values for this iteration String type = oid.getType(); // No need to check for nulls, as guaranteed non-null by // ObjectIdentity.getIdentifier() interface contract String identifier = oid.getIdentifier().toString(); // Changed by Christian Bremer (cbr) //long id = (Long.valueOf(identifier)).longValue(); // NOSONAR // Inject values //ps.setString((2 * i) + 1, id); // NOSONAR ps.setString((2 * i) + 1, identifier); ps.setString((2 * i) + 2, type); i++; } } }, new ProcessResultSet(acls, sids)); // Lookup the parents, now that our JdbcTemplate has released the database // connection (SEC-547) if (!parentsToLookup.isEmpty()) { lookupPrimaryKeys(acls, parentsToLookup, sids); } // Finally, convert our "acls" containing StubAclParents into true Acls Map<ObjectIdentity, Acl> resultMap = new HashMap<>(); for (Acl inputAcl : acls.values()) { Assert.isInstanceOf(AclImpl.class, inputAcl, "Map should have contained an AclImpl"); Assert.isInstanceOf(Long.class, ((AclImpl) inputAcl).getId(), "Acl.getId() must be Long"); Acl result = convert(acls, (Long) ((AclImpl) inputAcl).getId()); resultMap.put(result.getObjectIdentity(), result); } return resultMap; }
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 va 2s .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); }