use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.
the class UsernamePasswordRealm method supports.
/**
* Determine if the supplied token is supported by this realm.
*/
@Override
public boolean supports(AuthenticationToken token) {
if (!(token instanceof BaseAuthenticationToken)) {
LOGGER.debug("The supplied authentication token is not an instance of BaseAuthenticationToken. Sending back not supported.");
return false;
}
BaseAuthenticationToken authToken = (BaseAuthenticationToken) token;
Object credentials = authToken.getCredentials();
if (credentials == null || authToken.getType() != AuthenticationTokenType.USERNAME) {
LOGGER.debug("The supplied authentication token has null/empty credentials. Sending back not supported.");
return false;
}
if (credentials instanceof String) {
LOGGER.debug("Token {} is supported by {}.", token.getClass(), UsernamePasswordRealm.class.getName());
return true;
}
return false;
}
use of org.codice.ddf.security.handler.BaseAuthenticationToken in project ddf by codice.
the class AssertionConsumerService method login.
private boolean login(org.opensaml.saml.saml2.core.Response samlResponse) {
if (!request.isSecure()) {
return false;
}
Map<String, Cookie> cookieMap = HttpUtils.getCookieMap(request);
if (cookieMap.containsKey("JSESSIONID") && sessionFactory != null) {
sessionFactory.getOrCreateSession(request).invalidate();
}
HandlerResult handlerResult = new HandlerResultImpl();
SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection();
simplePrincipalCollection.add(new SecurityAssertionSaml(samlResponse.getAssertions().get(0).getDOM()), "default");
SAMLAuthenticationToken samlToken = new SAMLAuthenticationToken(null, simplePrincipalCollection, request.getRemoteAddr());
handlerResult.setToken(samlToken);
handlerResult.setStatus(HandlerResult.Status.COMPLETED);
if (handlerResult.getStatus() != HandlerResult.Status.COMPLETED) {
LOGGER.debug("Failed to handle SAML assertion.");
return false;
}
if (handlerResult.getToken() instanceof BaseAuthenticationToken) {
((BaseAuthenticationToken) handlerResult.getToken()).setAllowGuest(contextPolicyManager.getGuestAccess());
}
request.setAttribute(AUTHENTICATION_TOKEN_KEY, handlerResult);
request.removeAttribute(ContextPolicy.NO_AUTH_POLICY);
try {
LOGGER.trace("Trying to login with provided SAML assertion.");
loginFilter.doFilter(request, null, (servletRequest, servletResponse) -> {
});
} catch (IOException | AuthenticationException e) {
LOGGER.debug("Failed to apply login filter to SAML assertion", e);
return false;
}
return true;
}
Aggregations