/** * 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); }
public String getId() { if (id == null) { id = parentGroup == null ? String.format("/%s", this.name) : String.format("%s/%s", parentGroup.getId(), this.name); } return id; }
/** * <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()); }
@Override public Group getGroup(String name, Group parent) { if (name == null || parent == null) { return null; } Group group = getGroup(name); if (group.getParentGroup() == null || !group.getParentGroup().getName().equals(parent.getName())) { group = null; } return group; }
/** * <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()); }
Group someGroup = loadOrCreateGroup("someGroup", null, true); someGroup.setAttribute(new Attribute<String>("someAttribute", "someAttributeValue")); assertTrue(contains(result, someGroup.getName())); someGroup.setAttribute(new Attribute<String>("someAttribute", "someAttributeValueChanged")); assertFalse(contains(result, someGroup.getName())); someGroup.setAttribute(new Attribute<String>("someAttribute2", "someAttributeValue2")); assertTrue(contains(result, someGroup.getName()));
/** * <p> * Finds groups by the expiration date. * </p> * * @throws Exception */ @Test public void testFindExpiryDate() throws Exception { Group group = loadOrCreateGroup("someGroup", null, true); Date expirationDate = new Date(); IdentityManager identityManager = getIdentityManager(); group = identityManager.getGroup("someGroup"); group.setExpirationDate(expirationDate); identityManager.update(group); IdentityQuery<Group> query = identityManager.<Group> createQuery(Group.class); query.setParameter(Group.EXPIRY_DATE, expirationDate); List<Group> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(contains(result, group.getName())); assertEquals("someGroup", result.get(0).getName()); query = identityManager.<Group> createQuery(Group.class); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, 1); query.setParameter(Group.EXPIRY_DATE, calendar.getTime()); result = query.getResultList(); assertTrue(result.isEmpty()); }
/** * <p> * Finds groups by the creation date. * </p> * * @throws Exception */ @Test public void testFindCreationDate() throws Exception { Group group = loadOrCreateGroup("someGroup", null, true); IdentityManager identityManager = getIdentityManager(); IdentityQuery<Group> query = identityManager.<Group> createQuery(Group.class); query.setParameter(Group.CREATED_DATE, group.getCreatedDate()); List<Group> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(result.size() == 1); assertEquals("someGroup", result.get(0).getName()); query = identityManager.<Group> createQuery(Group.class); Thread.sleep(500); query.setParameter(Group.CREATED_DATE, new Date()); result = query.getResultList(); assertTrue(result.isEmpty()); }
Group someAnotherGroup = loadOrCreateGroup("someAnotherGroup", null, true); someGroup.setEnabled(true); someAnotherGroup.setEnabled(true); assertTrue(contains(result, someGroup.getName())); assertTrue(contains(result, someAnotherGroup.getName())); someGroup.setEnabled(false); assertTrue(contains(result, someGroup.getName())); assertFalse(contains(result, someAnotherGroup.getName())); someAnotherGroup.setEnabled(false); assertFalse(contains(result, someGroup.getName())); assertFalse(contains(result, someAnotherGroup.getName()));
@Override public Group getGroup(String name, Group parent) { Group group = getGroup(name); Group parentGroup = group.getParentGroup(); if (parentGroup == null || !parentGroup.getName().equals(parent.getName())) { group = null; } return group; }
/** * <p> * Finds groups using the IDM specific attributes and group defined attributes. * </p> * * @throws Exception */ @Test public void testFindUsingMultipleParameters() throws Exception { Group group = loadOrCreateGroup("admin", null, true); IdentityManager identityManager = getIdentityManager(); identityManager.update(group); group.setAttribute(new Attribute<String>("someAttribute", "someAttributeValue")); identityManager.update(group); IdentityQuery<Group> query = identityManager.<Group> createQuery(Group.class); query.setParameter(Group.NAME, "admin"); query.setParameter(IdentityType.ATTRIBUTE.byName("someAttribute"), "someAttributeValue"); List<Group> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(contains(result, group.getName())); assertEquals(1, result.size()); query = identityManager.<Group> createQuery(Group.class); query.setParameter(Group.NAME, "admin"); query.setParameter(IdentityType.ATTRIBUTE.byName("someAttribute"), "someAttributeValue2"); result = query.getResultList(); assertTrue(result.isEmpty()); }
Group someGroup = loadOrCreateGroup("someGroup", null, true); someGroup.setExpirationDate(new Date()); someAnotherGroup.setExpirationDate(new Date()); someFutureGroup.setExpirationDate(new Date()); someAnotherFutureGroup.setExpirationDate(new Date()); assertTrue(contains(result, someGroup.getName())); assertTrue(contains(result, someAnotherGroup.getName())); assertTrue(contains(result, someGroup.getName())); assertTrue(contains(result, someAnotherGroup.getName())); assertTrue(contains(result, someFutureGroup.getName())); assertTrue(contains(result, someAnotherFutureGroup.getName())); assertTrue(contains(result, someGroup.getName())); assertTrue(contains(result, someAnotherGroup.getName())); assertTrue(contains(result, someFutureGroup.getName())); assertTrue(contains(result, someAnotherFutureGroup.getName()));
private boolean contains(List<Group> result, String roleId) { for (Group resultGroup : result) { if (resultGroup.getName().equals(roleId)) { return true; } } return false; } }
/** * <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 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; }
Group someGroup = loadOrCreateGroup("someGroup", null, true); someGroup.setAttribute(new Attribute<String[]>("someAttribute", new String[] { "someAttributeValue1", "someAttributeValue2" })); assertTrue(contains(result, someGroup.getName())); assertFalse(contains(result, someGroup.getName())); someGroup.setAttribute(new Attribute<String[]>("someAttribute", new String[] { "someAttributeValue1", "someAttributeValueChanged" })); someGroup.setAttribute(new Attribute<String[]>("someAttribute2", new String[] { "someAttribute2Value1", "someAttribute2Value2" })); assertTrue(contains(result, someGroup.getName()));
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof Group)) { return false; } Group other = (Group) obj; // FIXME The Partition should also be taken into account return other.getId() != null && this.getId() != null && other.getId().equals(this.getId()); } }
private boolean contains(List<Group> result, String roleId) { for (Group resultGroup : result) { if (resultGroup.getName().equals(roleId)) { return true; } } return false; } }
/** * <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); }
@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); } }