Search in sources :

Example 1 with UsernameNotFoundException

use of net.sf.acegisecurity.providers.dao.UsernameNotFoundException in project alfresco-repository by Alfresco.

the class RepositoryAuthenticationDao method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String incomingUserName) throws UsernameNotFoundException, DataAccessException {
    CacheEntry userEntry = getUserEntryOrNull(incomingUserName);
    if (userEntry == null) {
        throw new UsernameNotFoundException("Could not find user by userName: " + AuthenticationUtil.maskUsername(incomingUserName));
    }
    UserDetails userDetails = userEntry.userDetails;
    if (userEntry.credentialExpiryDate == null || userEntry.credentialExpiryDate.getTime() >= System.currentTimeMillis()) {
        return userDetails;
    }
    if (userDetails instanceof RepositoryAuthenticatedUser) {
        RepositoryAuthenticatedUser repoUser = (RepositoryAuthenticatedUser) userDetails;
        return new RepositoryAuthenticatedUser(userDetails.getUsername(), userDetails.getPassword(), userDetails.isEnabled(), userDetails.isAccountNonExpired(), false, userDetails.isAccountNonLocked(), userDetails.getAuthorities(), repoUser.getHashIndicator(), repoUser.getSalt());
    }
    throw new AlfrescoRuntimeException("Unable to retrieve a compatible UserDetails object (requires RepositoryAuthenticatedUser)");
}
Also used : UsernameNotFoundException(net.sf.acegisecurity.providers.dao.UsernameNotFoundException) UserDetails(net.sf.acegisecurity.UserDetails) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

UserDetails (net.sf.acegisecurity.UserDetails)1 UsernameNotFoundException (net.sf.acegisecurity.providers.dao.UsernameNotFoundException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1