@Test public void testAuthenticateSimpleCredentials() throws Exception { assertTrue(authentication.authenticate(new SimpleCredentials(userId, userId.toCharArray()))); }
@Override public boolean authenticate(@Nullable Credentials credentials) throws LoginException { if (credentials == null || loginId == null) { return false; } boolean success = false; try { User user = getValidUser(config.getUserManager(root, NamePathMapper.DEFAULT), loginId); if (user == null) { return false; } if (credentials instanceof SimpleCredentials) { SimpleCredentials creds = (SimpleCredentials) credentials; Credentials userCreds = user.getCredentials(); if (loginId.equals(creds.getUserID()) && userCreds instanceof CredentialsImpl) { success = PasswordUtil.isSame(((CredentialsImpl) userCreds).getPasswordHash(), creds.getPassword()); } checkSuccess(success, "UserId/Password mismatch."); if (isPasswordExpired(user) && !changePassword(user, creds)) { throw new CredentialExpiredException("User password has expired"); } } else if (credentials instanceof ImpersonationCredentials) { ImpersonationCredentials ipCreds = (ImpersonationCredentials) credentials; AuthInfo info = ipCreds.getImpersonatorInfo(); success = equalUserId(ipCreds, loginId) && impersonate(info, user); checkSuccess(success, "Impersonation not allowed."); } else { success = (credentials instanceof GuestCredentials) || credentials == PreAuthenticatedLogin.PRE_AUTHENTICATED; } userId = user.getID(); principal = user.getPrincipal(); } catch (RepositoryException e) { throw new LoginException(e.getMessage()); } finally { removeNewPwAttribute(credentials); } return success; }
UserAuthentication implements Authentication, UserConstants { @Override public boolean authenticate(@Nullable Credentials credentials) throws LoginException { if (credentials == null || loginId == null) { return false; } boolean success = false; try { User user = getValidUser(config.getUserManager(root, NamePathMapper.DEFAULT), loginId); if (user == null) { return false; } if (credentials instanceof SimpleCredentials) { SimpleCredentials creds = (SimpleCredentials) credentials; Credentials userCreds = user.getCredentials(); if (loginId.equals(creds.getUserID()) && userCreds instanceof CredentialsImpl) { success = PasswordUtil.isSame(((CredentialsImpl) userCreds).getPasswordHash(), creds.getPassword()); } checkSuccess(success, "UserId/Password mismatch."); if (isPasswordExpired(user) && !changePassword(user, creds)) { throw new CredentialExpiredException("User password has expired"); } } else if (credentials instanceof ImpersonationCredentials) { ImpersonationCredentials ipCreds = (ImpersonationCredentials) credentials; AuthInfo info = ipCreds.getImpersonatorInfo(); success = equalUserId(ipCreds, loginId) && impersonate(info, user); checkSuccess(success, "Impersonation not allowed."); } else { success = (credentials instanceof GuestCredentials) || credentials == PreAuthenticatedLogin.PRE_AUTHENTICATED; } userId = user.getID(); principal = user.getPrincipal(); } catch (RepositoryException e) { throw new LoginException(e.getMessage()); } finally { removeNewPwAttribute(credentials); } return success; } }
UserAuthentication implements Authentication, UserConstants { @Override public boolean authenticate(@Nullable Credentials credentials) throws LoginException { if (credentials == null || loginId == null) { return false; } boolean success = false; try { User user = getValidUser(config.getUserManager(root, NamePathMapper.DEFAULT), loginId); if (user == null) { return false; } if (credentials instanceof SimpleCredentials) { SimpleCredentials creds = (SimpleCredentials) credentials; Credentials userCreds = user.getCredentials(); if (loginId.equals(creds.getUserID()) && userCreds instanceof CredentialsImpl) { success = PasswordUtil.isSame(((CredentialsImpl) userCreds).getPasswordHash(), creds.getPassword()); } checkSuccess(success, "UserId/Password mismatch."); if (isPasswordExpired(user) && !changePassword(user, creds)) { throw new CredentialExpiredException("User password has expired"); } } else if (credentials instanceof ImpersonationCredentials) { ImpersonationCredentials ipCreds = (ImpersonationCredentials) credentials; AuthInfo info = ipCreds.getImpersonatorInfo(); success = equalUserId(ipCreds, loginId) && impersonate(info, user); checkSuccess(success, "Impersonation not allowed."); } else { success = (credentials instanceof GuestCredentials) || credentials == PreAuthenticatedLogin.PRE_AUTHENTICATED; } userId = user.getID(); principal = user.getPrincipal(); } catch (RepositoryException e) { throw new LoginException(e.getMessage()); } finally { removeNewPwAttribute(credentials); } return success; } UserAuthentication(@NotNull UserConfiguration config, @NotNull Root root, @Nullable String loginId); }
UserAuthentication implements Authentication, UserConstants { @Override public boolean authenticate(@Nullable Credentials credentials) throws LoginException { if (credentials == null || loginId == null) { return false; } boolean success = false; try { User user = getValidUser(config.getUserManager(root, NamePathMapper.DEFAULT), loginId); if (user == null) { return false; } if (credentials instanceof SimpleCredentials) { SimpleCredentials creds = (SimpleCredentials) credentials; Credentials userCreds = user.getCredentials(); if (loginId.equals(creds.getUserID()) && userCreds instanceof CredentialsImpl) { success = PasswordUtil.isSame(((CredentialsImpl) userCreds).getPasswordHash(), creds.getPassword()); } checkSuccess(success, "UserId/Password mismatch."); if (isPasswordExpired(user) && !changePassword(user, creds)) { throw new CredentialExpiredException("User password has expired"); } } else if (credentials instanceof ImpersonationCredentials) { ImpersonationCredentials ipCreds = (ImpersonationCredentials) credentials; AuthInfo info = ipCreds.getImpersonatorInfo(); success = equalUserId(ipCreds, loginId) && impersonate(info, user); checkSuccess(success, "Impersonation not allowed."); } else { success = (credentials instanceof GuestCredentials) || credentials == PreAuthenticatedLogin.PRE_AUTHENTICATED; } userId = user.getID(); principal = user.getPrincipal(); } catch (RepositoryException e) { throw new LoginException(e.getMessage()); } finally { removeNewPwAttribute(credentials); } return success; } UserAuthentication(@NotNull UserConfiguration config, @NotNull Root root, @Nullable String loginId); @Override boolean authenticate(@Nullable Credentials credentials); @Nullable @Override String getUserId(); @Nullable @Override Principal getUserPrincipal(); }
UserAuthentication implements Authentication, UserConstants { @Override public boolean authenticate(@Nullable Credentials credentials) throws LoginException { if (credentials == null || loginId == null) { return false; } boolean success = false; try { User user = getValidUser(config.getUserManager(root, NamePathMapper.DEFAULT), loginId); if (user == null) { return false; } if (credentials instanceof SimpleCredentials) { SimpleCredentials creds = (SimpleCredentials) credentials; Credentials userCreds = user.getCredentials(); if (loginId.equals(creds.getUserID()) && userCreds instanceof CredentialsImpl) { success = PasswordUtil.isSame(((CredentialsImpl) userCreds).getPasswordHash(), creds.getPassword()); } checkSuccess(success, "UserId/Password mismatch."); if (isPasswordExpired(user) && !changePassword(user, creds)) { throw new CredentialExpiredException("User password has expired"); } } else if (credentials instanceof ImpersonationCredentials) { ImpersonationCredentials ipCreds = (ImpersonationCredentials) credentials; AuthInfo info = ipCreds.getImpersonatorInfo(); success = equalUserId(ipCreds, loginId) && impersonate(info, user); checkSuccess(success, "Impersonation not allowed."); } else { success = (credentials instanceof GuestCredentials) || credentials == PreAuthenticatedLogin.PRE_AUTHENTICATED; } userId = user.getID(); principal = user.getPrincipal(); } catch (RepositoryException e) { throw new LoginException(e.getMessage()); } finally { removeNewPwAttribute(credentials); } return success; } UserAuthentication(@NotNull UserConfiguration config, @NotNull Root root, @Nullable String loginId); @Override boolean authenticate(@Nullable Credentials credentials); @Nullable @Override String getUserId(); @Nullable @Override Principal getUserPrincipal(); static final String PARAM_PASSWORD_EXPIRY_FOR_ADMIN; }