/** * Get the role names * * @return */ public Collection<String> getRoleNames() { Set<String> roleNames = new HashSet<String>(); for (Role userRole : getRoles()) { roleNames.add(userRole.getName()); } return Collections.unmodifiableCollection(roleNames); }
/** * <p> * Creates a new {@link Role} instance using the API. This method also checks if the user was properly created by retrieving * his information from the store. * </p> * * @throws Exception */ @Test public void testCreate() throws Exception { Role newRoleInstance = loadOrCreateRole("someRole", true); IdentityManager identityManager = getIdentityManager(); Role storedRoleInstance = identityManager.getRole(newRoleInstance.getName()); assertNotNull(storedRoleInstance); assertEquals(newRoleInstance.getKey(), storedRoleInstance.getKey()); assertEquals(newRoleInstance.getName(), storedRoleInstance.getName()); }
Role someRole = loadOrCreateRole("someRole", true); someRole.setAttribute(new Attribute<String>("someAttribute", "someAttributeValue")); assertTrue(contains(result, someRole.getName())); someRole.setAttribute(new Attribute<String>("someAttribute", "someAttributeValueChanged")); assertFalse(contains(result, someRole.getName())); someRole.setAttribute(new Attribute<String>("someAttribute2", "someAttributeValue2")); assertTrue(contains(result, someRole.getName()));
/** * <p> * Finds roles by the expiration date. * </p> * * @throws Exception */ @Test public void testFindExpiryDate() throws Exception { Role role = loadOrCreateRole("someRole", true); Date expirationDate = new Date(); IdentityManager identityManager = getIdentityManager(); role = identityManager.getRole("someRole"); role.setExpirationDate(expirationDate); identityManager.update(role); IdentityQuery<Role> query = identityManager.<Role> createQuery(Role.class); query.setParameter(Role.EXPIRY_DATE, role.getExpirationDate()); // all expired roles List<Role> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(contains(result, role.getName())); assertEquals("someRole", result.get(0).getName()); query = identityManager.<Role> createQuery(Role.class); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, 1); query.setParameter(Role.EXPIRY_DATE, calendar.getTime()); // no roles result = query.getResultList(); assertTrue(result.isEmpty()); }
/** * <p> * Finds roles by the creation date. * </p> * * @throws Exception */ @Test public void testFindCreationDate() throws Exception { Role role = loadOrCreateRole("someRole", false); IdentityManager identityManager = getIdentityManager(); IdentityQuery<Role> query = identityManager.<Role> createQuery(Role.class); query.setParameter(Role.CREATED_DATE, role.getCreatedDate()); Thread.sleep(500); // only the previously created role List<Role> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(result.size() == 1); assertEquals("someRole", result.get(0).getName()); query = identityManager.<Role> createQuery(Role.class); query.setParameter(Role.CREATED_DATE, new Date()); // no roles result = query.getResultList(); assertTrue(result.isEmpty()); }
Role someRole = loadOrCreateRole("someRole", true); someRole.setExpirationDate(new Date()); someAnotherRole.setExpirationDate(new Date()); someFutureRole.setExpirationDate(new Date()); someAnotherFutureRole.setExpirationDate(new Date()); assertTrue(contains(result, someRole.getName())); assertTrue(contains(result, someAnotherRole.getName())); assertTrue(contains(result, someRole.getName())); assertTrue(contains(result, someAnotherRole.getName())); assertTrue(contains(result, someFutureRole.getName())); assertTrue(contains(result, someAnotherFutureRole.getName())); assertTrue(contains(result, someRole.getName())); assertTrue(contains(result, someAnotherRole.getName())); assertTrue(contains(result, someFutureRole.getName())); assertTrue(contains(result, someAnotherFutureRole.getName()));
Role someAnotherRole = loadOrCreateRole("someAnotherRole", true); someRole.setEnabled(true); someAnotherRole.setEnabled(true); assertTrue(contains(result, someRole.getName())); assertTrue(contains(result, someAnotherRole.getName())); someRole.setEnabled(false); assertTrue(contains(result, someRole.getName())); assertFalse(contains(result, someAnotherRole.getName())); someAnotherRole.setEnabled(false); assertFalse(contains(result, someRole.getName())); assertFalse(contains(result, someAnotherRole.getName()));
/** * <p> * Finds roles using the IDM specific attributes and role defined attributes. * </p> * * @throws Exception */ @Test public void testFindUsingMultipleParameters() throws Exception { Role role = loadOrCreateRole("admin", true); IdentityManager identityManager = getIdentityManager(); identityManager.update(role); role.setAttribute(new Attribute<String>("someAttribute", "someAttributeValue")); identityManager.update(role); IdentityQuery<Role> query = identityManager.<Role> createQuery(Role.class); query.setParameter(Role.NAME, "admin"); query.setParameter(IdentityType.ATTRIBUTE.byName("someAttribute"), "someAttributeValue"); List<Role> result = query.getResultList(); assertFalse(result.isEmpty()); assertTrue(contains(result, role.getName())); assertEquals(1, result.size()); query = identityManager.<Role> createQuery(Role.class); query.setParameter(Role.NAME, "admin"); query.setParameter(IdentityType.ATTRIBUTE.byName("someAttribute"), "someAttributeValue2"); result = query.getResultList(); assertTrue(result.isEmpty()); }
@Override protected void doPopulateIdentityInstance(Object toIdentity, Role fromRole, JPAIdentityStore store) { store.setModelProperty(toIdentity, PROPERTY_IDENTITY_NAME, fromRole.getName(), true); }
/** * <p> * Loads from the LDAP tree an already stored role. * </p> * * @throws Exception */ @Test public void testGet() throws Exception { Role storedRoleInstance = getIdentityType(true); assertNotNull(storedRoleInstance); IdentityManager identityManager = getIdentityManager(); storedRoleInstance = identityManager.getRole(storedRoleInstance.getName()); assertNotNull(storedRoleInstance); assertEquals("ROLE://Administrator", storedRoleInstance.getKey()); assertEquals("Administrator", storedRoleInstance.getName()); }
Role someRole = loadOrCreateRole("someRole", true); someRole.setAttribute(new Attribute<String[]>("someAttribute", new String[] { "someAttributeValue1", "someAttributeValue2" })); assertTrue(contains(result, someRole.getName())); assertFalse(contains(result, someRole.getName())); someRole.setAttribute(new Attribute<String[]>("someAttribute", new String[] { "someAttributeValue1", "someAttributeValueChanged" })); someRole.setAttribute(new Attribute<String[]>("someAttribute2", new String[] { "someAttribute2Value1", "someAttribute2Value2" })); assertTrue(contains(result, someRole.getName()));
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof Role)) { return false; } Role other = (Role) obj; // FIXME The Partition should also be taken into account. return other.getName() != null && this.getName() != null && other.getName().equals(this.getName()); } }
Role role = (Role) storedIdentityType; if (!isQueryParameterEquals(identityQuery.getParameters(), Role.NAME, role.getName())) { continue; && groupRole.getRole().getName().equals(membership.getRole().getName())) { valuesMatchCount--; if (roleNames.equals(membership.getRole().getName())) { valuesMatchCount--; && membership.getRole().getKey().equals(fileUser.getKey())) { valuesMatchCount--;
private boolean contains(List<Role> result, String roleId) { for (Role resultRole : result) { if (resultRole.getName().equals(roleId)) { return true; } } return false; }
private boolean contains(List<Role> result, String roleId) { for (Role resultRole : result) { if (resultRole.getName().equals(roleId)) { return true; } } return false; } }
private boolean contains(List<Role> result, String roleId) { for (Role resultRole : result) { if (resultRole.getName().equals(roleId)) { return true; } } return false; }
private Role removeRole(Role role) { getConfig().getRoles().remove(role.getName()); for (GroupRole membership : new ArrayList<GroupRole>(getConfig().getMemberships())) { Role roleMembership = membership.getRole(); if (roleMembership != null && roleMembership.getName().equals(role.getName())) { getConfig().getMemberships().remove(membership); } } flushRoles(); flushMemberships(); return role; }
private Role updateRole(Role updatedRole, Role storedRole) { if (storedRole != updatedRole) { updateCommonProperties(updatedRole, storedRole); } getConfig().getRoles().put(storedRole.getName(), storedRole); flushRoles(); return storedRole; }
/** * <p> * Checks if the user has the specified role. * </p> * * @param role * @return */ public boolean hasRole(String role) { if (!isAuthenticated()) { throw PicketBoxMessages.MESSAGES.userNotAuthenticated(); } for (Role userRole : getRoles()) { if (role.equals(userRole.getName())) { return true; } } return false; }