use of org.codice.ddf.platform.filter.AuthenticationException 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;
}
use of org.codice.ddf.platform.filter.AuthenticationException in project ddf by codice.
the class GuestInterceptor method getSubject.
private synchronized Subject getSubject(String ipAddress) throws AuthenticationException {
Subject subject = guestSubjectCache.getIfPresent(ipAddress);
if (subject == null) {
if (securityManager == null) {
throw new AuthenticationException("Unable to create the guest subject, system is not ready.");
}
GuestAuthenticationToken token = new GuestAuthenticationToken(ipAddress, securityLogger);
LOGGER.debug("Getting new Guest user token for {}", ipAddress);
try {
subject = securityManager.getSubject(token);
// this should be a cache not a map so we can remove items, make this change
guestSubjectCache.put(ipAddress, subject);
} catch (SecurityServiceException sse) {
LOGGER.info("Unable to request subject for guest user.", sse);
}
} else {
LOGGER.debug("Using cached Guest user token for {}", ipAddress);
}
return subject;
}
use of org.codice.ddf.platform.filter.AuthenticationException in project ddf by codice.
the class GuestInterceptor method handleMessage.
@Override
public void handleMessage(SoapMessage message) throws Fault {
if (message != null) {
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
LOGGER.debug("Getting new Guest user token");
Principal principal = null;
Subject subject = null;
try {
subject = getSubject(request.getRemoteAddr());
} catch (AuthenticationException e) {
throw new Fault(e);
}
if (subject != null) {
PrincipalCollection principals = subject.getPrincipals();
SecurityAssertion securityAssertion = principals.oneByType(SecurityAssertion.class);
if (securityAssertion != null) {
principal = new SecurityAssertionPrincipalDefault(securityAssertion);
} else {
LOGGER.debug("Subject did not contain a security assertion");
}
message.put(SecurityContext.class, new DefaultSecurityContext(principal, null));
message.put(WSS4J_CHECK_STRING, Boolean.TRUE);
}
} else {
LOGGER.debug("Incoming SOAP message is null - guest interceptor makes no sense.");
}
}
Aggregations