use of org.jasig.cas.client.validation.Assertion in project ddf by codice.
the class CasHandlerTest method createServletRequest.
private HttpServletRequest createServletRequest(boolean shouldAddCas) {
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);
when(session.getId()).thenReturn(SESSION_ID);
when(servletRequest.getSession()).thenReturn(session);
when(servletRequest.getSession(any(Boolean.class))).thenReturn(session);
if (shouldAddCas) {
// Mock CAS items
Assertion assertion = mock(Assertion.class);
when(session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION)).thenReturn(assertion);
AttributePrincipal principal = mock(AttributePrincipal.class);
when(principal.getProxyTicketFor(STS_ADDRESS)).thenReturn(MOCK_TICKET);
when(principal.getProxyTicketFor(not(eq(STS_ADDRESS)))).thenThrow(new RuntimeException("Tried to create ticket for incorrect service."));
when(assertion.getPrincipal()).thenReturn(principal);
}
return servletRequest;
}
use of org.jasig.cas.client.validation.Assertion in project ddf by codice.
the class CasHandler method getNormalizedToken.
@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, FilterChain chain, boolean resolve) throws ServletException {
// Default to NO_ACTION and set the source as this handler
HandlerResult handlerResult = new HandlerResult(HandlerResult.Status.NO_ACTION, null);
handlerResult.setSource(realm + "-" + SOURCE);
HttpServletRequest httpRequest = (HttpServletRequest) request;
String path = httpRequest.getServletPath();
LOGGER.debug("Doing CAS authentication and authorization for path {}", path);
// if the request contains the principal, return it
Assertion assertion = getAssertion(httpRequest);
try {
if (resolve && assertion == null) {
proxyFilter.doFilter(request, response, new ProxyFilterChain(null));
}
} catch (IOException e) {
throw new ServletException(e);
}
if (assertion != null) {
LOGGER.debug("Found previous CAS attribute, using that same session.");
CASAuthenticationToken token = getAuthenticationToken(assertion);
if (token != null) {
handlerResult.setToken(token);
handlerResult.setStatus(HandlerResult.Status.COMPLETED);
//update cache with new information
LOGGER.debug("Adding new CAS assertion for session {}", httpRequest.getSession(false).getId());
httpRequest.getSession(false).setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, assertion);
LOGGER.debug("Successfully set authentication token, returning result with token.");
} else {
LOGGER.debug("Could not create authentication token, returning NO_ACTION result.");
}
} else {
if (resolve) {
LOGGER.debug("Calling cas authentication and validation filters to perform redirects.");
handlerResult.setStatus(HandlerResult.Status.REDIRECTED);
} else {
LOGGER.debug("No cas authentication information found and resolve is not enabled, returning NO_ACTION.");
}
}
return handlerResult;
}
Aggregations