use of org.codice.ddf.security.handler.cas.filter.ProxyFilterChain in project ddf by codice.
the class CasHandlerTest method testNoPrincipalNoResolve.
/**
* Tests that the handler properly returns a NO_ACTION result if no assertion is available in
* the request and resolve is false.
*
* @throws ServletException
*/
@Test
public void testNoPrincipalNoResolve() throws ServletException {
CasHandler handler = createHandler();
HandlerResult result = handler.getNormalizedToken(createServletRequest(false), mock(HttpServletResponse.class), new ProxyFilterChain(null), false);
// NO_ACTION due to resolve being false
assertEquals(HandlerResult.Status.NO_ACTION, result.getStatus());
}
use of org.codice.ddf.security.handler.cas.filter.ProxyFilterChain 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;
}
use of org.codice.ddf.security.handler.cas.filter.ProxyFilterChain in project ddf by codice.
the class CasHandlerTest method testPrincipalResolve.
/**
* Tests that the handler properly returns a COMPLETED result if the assertion is in the
* session and resolve is true.
*
* @throws ServletException
* @throws IOException
*/
@Test
public void testPrincipalResolve() throws ServletException, IOException {
CasHandler handler = createHandler();
HandlerResult result = handler.getNormalizedToken(createServletRequest(true), mock(HttpServletResponse.class), new ProxyFilterChain(null), true);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
use of org.codice.ddf.security.handler.cas.filter.ProxyFilterChain in project ddf by codice.
the class CasHandlerTest method testCachedPrincipalResolve.
/**
* Tests that the handler properly returns a COMPLETED result from having a cached session that
* contains the CAS assertion.
*
* @throws ServletException
* @throws IOException
*/
@Test
public void testCachedPrincipalResolve() throws ServletException, IOException {
CasHandler handler = createHandler();
HttpServletRequest servletRequest = createServletRequest(true);
HttpSession session = servletRequest.getSession();
HandlerResult result = handler.getNormalizedToken(servletRequest, mock(HttpServletResponse.class), new ProxyFilterChain(null), true);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
// now check for caching sessions
servletRequest = createServletRequest(false);
when(servletRequest.getSession()).thenReturn(session);
when(servletRequest.getSession(any(Boolean.class))).thenReturn(session);
result = handler.getNormalizedToken(servletRequest, mock(HttpServletResponse.class), new ProxyFilterChain(null), true);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
use of org.codice.ddf.security.handler.cas.filter.ProxyFilterChain in project ddf by codice.
the class CasHandlerTest method testPrincipalNoResolve.
/**
* Tests that the handler properly returns a COMPLETED result if the assertion is in the session.
*
* @throws ServletException
*/
@Test
public void testPrincipalNoResolve() throws ServletException {
CasHandler handler = createHandler();
HandlerResult result = handler.getNormalizedToken(createServletRequest(true), mock(HttpServletResponse.class), new ProxyFilterChain(null), false);
assertEquals(HandlerResult.Status.COMPLETED, result.getStatus());
}
Aggregations