@Test public void testSuccessfulValidation() throws Exception { IdentityManager identityManager = getIdentityManager(); String accountName = "someUser"; Account user = createAccount(accountName); Digest digestPassword = new Digest(); digestPassword.setRealm("pl-idm"); digestPassword.setUsername(accountName); digestPassword.setPassword("somePassword"); identityManager.updateCredential(user, digestPassword); digestPassword.setDigest( DigestUtil.calculateA1( accountName, digestPassword.getRealm(), digestPassword.getPassword().toCharArray())); DigestCredentials credential = new DigestCredentials(digestPassword); identityManager.validateCredentials(credential); assertEquals(Credentials.Status.VALID, credential.getStatus()); assertNotNull(credential.getValidatedAccount()); assertEquals(user.getId(), credential.getValidatedAccount().getId()); }
@Test public void testUserDisabled() throws Exception { IdentityManager identityManager = getIdentityManager(); String accountName = "someUser"; Account user = createAccount(accountName); Digest digestPassword = new Digest(); digestPassword.setRealm("pl-idm"); digestPassword.setUsername(accountName); digestPassword.setPassword("somePassword"); identityManager.updateCredential(user, digestPassword); digestPassword.setDigest( DigestUtil.calculateA1( accountName, digestPassword.getRealm(), digestPassword.getPassword().toCharArray())); DigestCredentials credential = new DigestCredentials(digestPassword); identityManager.validateCredentials(credential); assertEquals(Credentials.Status.VALID, credential.getStatus()); user.setEnabled(false); identityManager.update(user); identityManager.validateCredentials(credential); assertEquals(Credentials.Status.ACCOUNT_DISABLED, credential.getStatus()); }
@Test(expected = LockedAccountException.class) public void failLockedAccount() { Account account = getAccount(); account.setEnabled(false); getIdentityManager().update(account); DefaultLoginCredentials credentials = getCredentials(); credentials.setPassword(USER_PASSWORD); credentials.setUserId(USER_NAME); // should throw the exception. user is disabled/locked. Identity identity = getIdentity(); identity.login(); }