@Override public Group getGroup(String name, Group parent) { Group ldapGroup = getGroup(name); Group ldapGroupParent = ldapGroup.getParentGroup(); if (parent != null && ldapGroup != null && ldapGroupParent != null && ldapGroupParent.getName().equals(parent.getName())) { return ldapGroup; } return null; }
/** * Get the group names * * @return */ public Collection<String> getGroupNames() { Set<String> groupNames = new HashSet<String>(); for (Group userRole : getGroups()) { groupNames.add(userRole.getName()); } return Collections.unmodifiableCollection(groupNames); }
private boolean contains(List<Group> result, String roleId) { for (Group resultGroup : result) { if (resultGroup.getName().equals(roleId)) { return true; } } return false; } }
private boolean contains(List<Group> result, String roleId) { for (Group resultGroup : result) { if (resultGroup.getName().equals(roleId)) { return true; } } return false; } }
private boolean contains(List<Group> result, String groupName) { for (Group resultGroup : result) { if (resultGroup.getName().equals(groupName)) { return true; } } return false; } }
private Group removeGroup(Group group) { getConfig().getGroups().remove(group.getName()); for (GroupRole membership : new ArrayList<GroupRole>(getConfig().getMemberships())) { Group groupMembership = membership.getGroup(); if (groupMembership != null && groupMembership.getName().equals(group.getName())) { getConfig().getMemberships().remove(membership); } } flushGroups(); flushMemberships(); return group; }
private Group updateGroup(Group updatedGroup, Group storedGroup) { if (storedGroup != updatedGroup) { updateCommonProperties(updatedGroup, storedGroup); } getConfig().getGroups().put(storedGroup.getName(), storedGroup); flushGroups(); return storedGroup; }
private Group addGroup(Group group) { SimpleGroup fileGroup = null; if (group.getParentGroup() != null) { fileGroup = new SimpleGroup(group.getName(), getGroup(group.getParentGroup().getName())); } else { fileGroup = new SimpleGroup(group.getName()); } updateCommonProperties(group, fileGroup); getConfig().getGroups().put(fileGroup.getName(), fileGroup); flushGroups(); return fileGroup; }
/** * <p> * Checks if the user is member of the specified group. * </p> * * @param role * @return */ public boolean hasGroup(String group) { if (!isAuthenticated()) { throw PicketBoxMessages.MESSAGES.userNotAuthenticated(); } for (Group userGroup : getGroups()) { if (group.equals(userGroup.getName())) { return true; } } return false; }
protected Group addGroup(Group group) { if (group.getName() == null) { throw new IdentityManagementException("No identifier was provided."); } LDAPGroup ldapGroup = new LDAPGroup(this.configuration.getGroupDNSuffix()); ldapGroup.setName(group.getName()); if (group.getParentGroup() != null) { String parentName = group.getParentGroup().getName(); LDAPGroup parentGroup = (LDAPGroup) getGroup(parentName); if (parentGroup == null) { throw new RuntimeException("Parent group [" + parentName + "] does not exists."); } parentGroup.addChildGroup(ldapGroup); ldapGroup.setParentGroup(parentGroup); getLdapManager().modifyAttribute(parentGroup.getDN(), parentGroup.getLDAPAttributes().get(MEMBER)); } store(ldapGroup); return ldapGroup; }
/** * <p> * Finds groups by the creation date. * </p> * * @throws Exception */ @Test public void testFindWithParent() throws Exception { Group group = loadOrCreateGroup("someGroup", "Parent Group", true); IdentityManager identityManager = getIdentityManager(); IdentityQuery<Group> query = identityManager.<Group> createQuery(Group.class); query.setParameter(Group.PARENT, group.getParentGroup().getName()); List<Group> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(result.size() == 1); assertEquals(group.getName(), result.get(0).getName()); assertEquals(group.getParentGroup().getName(), result.get(0).getParentGroup().getName()); }
/** * <p> * Creates a new {@link Group} instance using the API. This method also checks if the group was properly created by * retrieving his information from the store. * </p> * * @throws Exception */ @Test public void testCreate() throws Exception { Group newGroupInstance = loadOrCreateGroup("someGroup", null, true); IdentityManager identityManager = getIdentityManager(); Group storedGroupInstance = identityManager.getGroup(newGroupInstance.getName()); assertNotNull(storedGroupInstance); assertEquals(newGroupInstance.getKey(), storedGroupInstance.getKey()); assertEquals(newGroupInstance.getName(), storedGroupInstance.getName()); }
/** * <p> * Creates a new {@link Group} instance as a child of another {@link Group} using the API. This method also checks if the * group was properly created by retrieving his information from the store. * </p> * * @throws Exception */ @Test public void testCreateWithParentGroup() throws Exception { Group childGroup = loadOrCreateGroup("childGroup", "parentGroup", true); // let's retrieve the group information and see if it was properly stored IdentityManager identityManager = getIdentityManager(); Group storedChildGroup = identityManager.getGroup(childGroup.getName()); assertNotNull(storedChildGroup); assertNotNull(storedChildGroup.getParentGroup()); assertEquals(childGroup.getKey(), storedChildGroup.getKey()); assertEquals(childGroup.getName(), storedChildGroup.getName()); assertEquals(childGroup.getParentGroup().getName(), storedChildGroup.getParentGroup().getName()); }
/** * <p> * Find an {@link Group} by id. * </p> * * @throws Exception */ @Test public void testFindByName() throws Exception { loadOrCreateGroup("admin", null, true); IdentityManager identityManager = getIdentityManager(); IdentityQuery<Group> query = identityManager.<Group> createQuery(Group.class); query.setParameter(Group.NAME, "admin"); List<Group> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(result.size() == 1); assertEquals("admin", result.get(0).getName()); }
/** * <p> * Loads from the LDAP tree an already stored group. * </p> * * @throws Exception */ @Test public void testGet() throws Exception { Group storedGroupInstance = getIdentityType(true); IdentityManager identityManager = getIdentityManager(); storedGroupInstance = identityManager.getGroup(storedGroupInstance.getName()); assertNotNull(storedGroupInstance); assertNotNull(storedGroupInstance.getParentGroup()); assertEquals("GROUP:///Test Parent Group/Test Group", storedGroupInstance.getKey()); assertEquals("Test Group", storedGroupInstance.getName()); }
@Override protected void doPopulateIdentityInstance(Object toIdentity, Group fromGroup, JPAIdentityStore store) { store.setModelProperty(toIdentity, PROPERTY_IDENTITY_NAME, fromGroup.getName(), true); if (fromGroup.getParentGroup() != null) { Object parentIdentity = store.lookupIdentityObjectById(fromGroup.getParentGroup()); if (parentIdentity == null) { store.add(fromGroup.getParentGroup()); parentIdentity = store.lookupIdentityObjectById(fromGroup.getParentGroup()); } store.setModelProperty(toIdentity, PROPERTY_PARENT_GROUP, parentIdentity, true); } }
/** * <p> * Remove from the LDAP tree an already stored group. * </p> * * @throws Exception */ @Test public void testRemove() throws Exception { Group storedGroupInstance = getIdentityType(true); assertNotNull(storedGroupInstance); IdentityManager identityManager = getIdentityManager(); identityManager.remove(storedGroupInstance); Group removedGroupInstance = identityManager.getGroup(storedGroupInstance.getName()); assertNull(removedGroupInstance); }
/** * <p> * Loads from the LDAP tree an already stored group. * </p> * * @throws Exception */ @Test public void testGetWithParent() throws Exception { Group storedGroupInstance = getIdentityType(true); IdentityManager identityManager = getIdentityManager(); storedGroupInstance = identityManager.getGroup("Test Group", new SimpleGroup("Test Parent Group")); assertNotNull(storedGroupInstance); assertNotNull(storedGroupInstance.getParentGroup()); assertEquals("GROUP:///Test Parent Group/Test Group", storedGroupInstance.getKey()); assertEquals("Test Group", storedGroupInstance.getName()); Group invalidGroupInstance = identityManager.getGroup("Test Group", new SimpleGroup("Invalid Parent Group")); assertNull(invalidGroupInstance); }