@Override public void add(IdentityType identityType) throws IdentityManagementException { decorated.add(identityType); }
@Override public void remove(IdentityType identityType) { this.delegate.remove(identityType); }
@Override public void validateCredentials(Credentials credentials) { decorated.validateCredentials(credentials); }
/** * This method creates a new User * * @param user */ @Override public void create(User user, String password) { identityManager.add(user); identityManager.updateCredential(user, new Password(password)); }
Password firstPassword = new Password("password1".toCharArray()); identityManager.updateCredential(user, firstPassword); identityManager.validateCredentials(firstCredential); identityManager.updateCredential(user, secondPassword); identityManager.validateCredentials(secondCredential); identityManager.validateCredentials(firstCredential);
@Override public void update(IdentityType identityType) { this.delegate.update(identityType); }
@Override protected Principal doAuthenticate(UserCredential credential, AuthenticationResult result) throws AuthenticationException { UsernamePasswordCredential userCredential = (UsernamePasswordCredential) credential; // try to retrieve the user from the configured identity store User user = getIdentityManager().getUser(userCredential.getUserName()); Credentials passwordCredential = userCredential.getCredential(); getIdentityManager().validateCredentials(passwordCredential); if (user != null && passwordCredential.getStatus().equals(Status.VALID)) { return new PicketBoxPrincipal(userCredential.getUserName()); } return null; } }
/** * <p> * Loads or creates a new {@link Group} instance depending on the <code>alwaysCreate</code> argument value. If this argument * is true and the provided {@link User} exists it will be re-created (remove/add). Otherwise the stored instance is always * returned. * </p> * * @param userName * @param alwaysCreate * @return */ protected User loadOrCreateUser(String userName, boolean alwaysCreate) { User user = getIdentityManager().getUser(userName); if (user != null && alwaysCreate) { getIdentityManager().remove(user); user = null; } if (user == null) { user = new SimpleUser(userName); getIdentityManager().add(user); } return getIdentityManager().getUser(userName); }
@Override public <T extends IdentityType> IdentityQuery<T> createIdentityQuery(Class<T> identityType) { return decorated.createIdentityQuery(identityType); }
@Override public void updateCredential(Agent agent, Object value) { this.delegate.updateCredential(agent, value); }
@Override public IdentityQueryBuilder getQueryBuilder() { return decorated.getQueryBuilder(); } }
@Override protected void doRemove(Partition attributedType) { checkPartitionManagementSupported(); IdentityManager identityManager = createIdentityManager(attributedType); IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder(); IdentityQuery<IdentityType> query = queryBuilder.createIdentityQuery(IdentityType.class); for (IdentityType identityType : query.getResultList()) { identityManager.remove(identityType); } IdentityContext identityContext = getIdentityContext(); getStoreSelector().getStoreForPartitionOperation(identityContext, attributedType.getClass()).remove(identityContext, attributedType); }
@Override public boolean deleteGroup(String id) { verifyIdentityManager(); IdentityQuery<Group> query = identityManager.<Group> createIdentityQuery(Group.class); query.setParameter(AttributedType.ID, id); List<Group> result = query.getResultList(); Group group = null; if(result.size() == 1){ group = result.get(0); } else if(result.size() == 0){ log.error("No group instances with id:" + id); } else { log.error("Multiple group instances with id:" + id); } if (group != null) { identityManager.remove(group); return true; } return false; }
/** * <p> * Loads or creates a new {@link Group} instance depending on the <code>alwaysCreate</code> argument value. If this argument * is true and the provided {@link User} exists it will be re-created (remove/add). Otherwise the stored instance is always * returned. * </p> * * @param id * @param alwaysCreate * @return */ protected Agent loadOrCreateAgent(String id, boolean alwaysCreate) { Agent agent = getIdentityManager().getAgent(id); if (agent != null && alwaysCreate) { getIdentityManager().remove(agent); agent = null; } if (agent == null) { agent = new SimpleAgent(id); getIdentityManager().add(agent); } return getIdentityManager().getAgent(id); }
/** * <p> * Loads or creates a new {@link Role} instance depending on the <code>alwaysCreate</code> argument value. If this argument * is true and the provided {@link Role} exists it will be re-created (remove/add). Otherwise the stored instance is always * returned. * </p> * * @param userName * @param alwaysCreate * @return */ protected Role loadOrCreateRole(String name, boolean alwaysCreate) { Role role = getIdentityManager().getRole(name); if (role != null && alwaysCreate) { getIdentityManager().remove(role); role = null; } if (role == null) { role = new SimpleRole(name); getIdentityManager().add(role); } return getIdentityManager().getRole(name); }
@Override public void bootstrap(IdentityConfiguration configuration, IdentityStoreInvocationContextFactory contextFactory) { this.delegate.bootstrap(configuration, contextFactory); }
/** * <p> * Creates a new {@link User} 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 { User newUserInstance = loadOrCreateUser("jduke", true); newUserInstance.setEmail("jduke@jboss.org"); newUserInstance.setFirstName("Java"); newUserInstance.setLastName("Duke"); IdentityManager identityManager = getIdentityManager(); identityManager.update(newUserInstance); // let's retrieve the user information and see if they are properly stored User storedUserInstance = identityManager.getUser(newUserInstance.getId()); assertNotNull(storedUserInstance); assertEquals(newUserInstance.getId(), storedUserInstance.getId()); assertEquals(newUserInstance.getFirstName(), storedUserInstance.getFirstName()); assertEquals(newUserInstance.getLastName(), storedUserInstance.getLastName()); assertEquals(newUserInstance.getEmail(), storedUserInstance.getEmail()); assertTrue(storedUserInstance.isEnabled()); assertTrue(new Date().compareTo(storedUserInstance.getCreatedDate()) > 0); }
/** * <p> * Remove from the LDAP tree an already stored user. * </p> * * @throws Exception */ @Test public void testRemove() throws Exception { IdentityManager identityManager = getIdentityManager(); User someUser = getIdentityType(true); User anotherUser = loadOrCreateUser("someAnotherUser", true); assertNotNull(someUser); assertNotNull(anotherUser); identityManager.remove(someUser); User removedUserInstance = getIdentityManager().getUser(someUser.getId()); assertNull(removedUserInstance); anotherUser = identityManager.getUser(anotherUser.getId()); assertNotNull(anotherUser); }
@Test public void appUnregister() throws Exception{ IdentityManager identityManager = getIdentityManager(); Agent oauthApp = loadOrCreateAgent(appName, true); oauthApp = identityManager.getAgent(appName); assertNotNull(oauthApp); identityManager.remove(oauthApp); oauthApp = identityManager.getAgent(appName); assertNull(oauthApp); } }
/** * <p> * Remove from the LDAP tree an already stored role. * </p> * * @throws Exception */ @Test public void testRemove() throws Exception { Role storedRoleInstance = getIdentityType(true); assertNotNull(storedRoleInstance); IdentityManager identityManager = getIdentityManager(); identityManager.remove(storedRoleInstance); Role removedRoleInstance = identityManager.getRole(storedRoleInstance.getName()); assertNull(removedRoleInstance); }