@Test public void testRemove() throws Exception { IdentityManager identityManager = getIdentityManager(); Agent someAgent = createIdentityType(); Agent anotherAgent = createAgent("someAnotherAgent"); identityManager.remove(someAgent); Agent removedUserInstance = getAgent(someAgent.getLoginName()); assertNull(removedUserInstance); anotherAgent = getAgent(anotherAgent.getLoginName()); assertNotNull(anotherAgent); Role role = createRole("role"); Group group = createGroup("group", null); RelationshipManager relationshipManager = getPartitionManager().createRelationshipManager(); BasicModel.grantRole(relationshipManager, anotherAgent, role); BasicModel.addToGroup(relationshipManager, anotherAgent, group); RelationshipQuery<?> relationshipQuery = relationshipManager.createRelationshipQuery(Grant.class); relationshipQuery.setParameter(Grant.ASSIGNEE, anotherAgent); assertFalse(relationshipQuery.getResultList().isEmpty()); relationshipQuery = relationshipManager.createRelationshipQuery(GroupMembership.class); relationshipQuery.setParameter(GroupMembership.MEMBER, anotherAgent); assertFalse(relationshipQuery.getResultList().isEmpty()); identityManager.remove(anotherAgent); relationshipQuery = relationshipManager.createRelationshipQuery(Grant.class); relationshipQuery.setParameter(Grant.ASSIGNEE, anotherAgent); assertTrue(relationshipQuery.getResultList().isEmpty()); relationshipQuery = relationshipManager.createRelationshipQuery(GroupMembership.class); relationshipQuery.setParameter(GroupMembership.MEMBER, anotherAgent); assertTrue(relationshipQuery.getResultList().isEmpty()); }
@Override public void deleteRoleMapping(UserModel user, RoleModel role) { RelationshipQuery<Grant> query = getRelationshipManager().createRelationshipQuery(Grant.class); query.setParameter(Grant.ASSIGNEE, ((UserAdapter) user).getUser()); query.setParameter(Grant.ROLE, ((RoleAdapter) role).getRole()); List<Grant> grants = query.getResultList(); for (Grant grant : grants) { getRelationshipManager().remove(grant); } }
@Override public void deleteScopeMapping(UserModel user, RoleModel role) { RelationshipQuery<ScopeRelationship> query = getRelationshipManager().createRelationshipQuery(ScopeRelationship.class); query.setParameter(ScopeRelationship.CLIENT, ((UserAdapter) user).getUser()); query.setParameter(ScopeRelationship.SCOPE, ((RoleAdapter) role).getRole()); List<ScopeRelationship> grants = query.getResultList(); for (ScopeRelationship grant : grants) { getRelationshipManager().remove(grant); } }
@Override public List<RoleModel> getRoleMappings(UserModel user) { RelationshipQuery<Grant> query = getRelationshipManager().createRelationshipQuery(Grant.class); query.setParameter(Grant.ASSIGNEE, ((UserAdapter) user).getUser()); List<Grant> grants = query.getResultList(); List<RoleModel> set = new ArrayList<RoleModel>(); for (Grant grant : grants) { if (grant.getRole().getPartition().getId().equals(applicationData.getId())) set.add(new RoleAdapter(grant.getRole(), getIdm())); } return set; }
@Override public Set<String> getRoleMappingValues(UserModel user) { RelationshipQuery<Grant> query = getRelationshipManager().createRelationshipQuery(Grant.class); query.setParameter(Grant.ASSIGNEE, ((UserAdapter) user).getUser()); List<Grant> grants = query.getResultList(); HashSet<String> set = new HashSet<String>(); for (Grant grant : grants) { if (grant.getRole().getPartition().getId().equals(applicationData.getId())) set.add(grant.getRole().getName()); } return set; }
@Override public List<RoleModel> getScopeMappings(UserModel agent) { RelationshipQuery<ScopeRelationship> query = getRelationshipManager().createRelationshipQuery(ScopeRelationship.class); query.setParameter(ScopeRelationship.CLIENT, ((UserAdapter) agent).getUser()); List<ScopeRelationship> scope = query.getResultList(); List<RoleModel> roles = new ArrayList<RoleModel>(); for (ScopeRelationship rel : scope) { if (rel.getScope().getPartition().getId().equals(applicationData.getId())) roles.add(new RoleAdapter(rel.getScope(), getIdm())); } return roles; }
@Override public Set<String> getScopeMappingValues(UserModel agent) { RelationshipQuery<ScopeRelationship> query = getRelationshipManager().createRelationshipQuery(ScopeRelationship.class); query.setParameter(ScopeRelationship.CLIENT, ((UserAdapter) agent).getUser()); List<ScopeRelationship> scope = query.getResultList(); HashSet<String> set = new HashSet<String>(); for (ScopeRelationship rel : scope) { if (rel.getScope().getPartition().getId().equals(applicationData.getId())) set.add(rel.getScope().getName()); } return set; }