use of org.apache.jackrabbit.core.security.authentication.Authentication in project pentaho-platform by pentaho.
the class SpringSecurityLoginModule method getAuthentication.
/**
* {@inheritDoc}
*
* Creates a {@code UsernamePasswordAuthenticationToken} from the given {@code principal} and {@code credentials}
* and passes to Spring Security {@code AuthenticationManager}.
*/
@Override
protected Authentication getAuthentication(final Principal principal, final Credentials credentials) throws RepositoryException {
// only handles SimpleCredential instances; DefaultLoginModule behaves the same way (albeit indirectly)
if (!(credentials instanceof SimpleCredentials)) {
// $NON-NLS-1$
logger.debug("credentials not instance of SimpleCredentials; returning null");
return null;
}
SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(simpleCredentials.getUserID(), String.valueOf(simpleCredentials.getPassword()));
boolean authenticated = false;
try {
org.springframework.security.core.Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getName().equals(simpleCredentials.getUserID())) {
// see if there's already an active Authentication for this user.
authenticated = true;
} else {
// delegate to Spring Security
getAuthenticationManager().authenticate(token);
authenticated = true;
}
} catch (AuthenticationException e) {
// $NON-NLS-1$
logger.debug("authentication exception", e);
}
final boolean authenticateResult = authenticated;
return new Authentication() {
public boolean canHandle(Credentials credentials) {
// this is decided earlier in getAuthentication
return true;
}
public boolean authenticate(Credentials credentials) throws RepositoryException {
return authenticateResult;
}
};
}
Aggregations