use of org.codice.ddf.security.handler.HandlerResultImpl in project ddf by codice.
the class LoginFilterTest method testGoodToken.
@Test
public void testGoodToken() throws Exception {
HandlerResult result = new HandlerResultImpl(HandlerResult.Status.COMPLETED, goodAuthenticationTokenMock);
when(requestMock.getAttribute(AUTHENTICATION_TOKEN_KEY)).thenReturn(result);
loginFilter.doFilter(requestMock, responseMock, filterChainMock);
verify(filterChainMock, times(1)).doFilter(any(), any());
}
use of org.codice.ddf.security.handler.HandlerResultImpl in project ddf by codice.
the class LoginFilterTest method testValidReference.
@Test
public void testValidReference() throws Exception {
HandlerResult result = new HandlerResultImpl(HandlerResult.Status.COMPLETED, referenceTokenMock);
when(requestMock.getAttribute(AUTHENTICATION_TOKEN_KEY)).thenReturn(result);
PrincipalHolder principalHolder = new PrincipalHolder();
principalHolder.setPrincipals(principalCollectionMock);
when(sessionMock.getAttribute(SECURITY_TOKEN_KEY)).thenReturn(principalHolder);
when(securityManagerMock.getSubject(referenceTokenMock)).thenReturn(subject);
loginFilter.doFilter(requestMock, responseMock, filterChainMock);
verify(filterChainMock, times(1)).doFilter(any(), any());
}
use of org.codice.ddf.security.handler.HandlerResultImpl in project ddf by codice.
the class LoginFilterTest method testInvalidReference.
@Test
public void testInvalidReference() throws Exception {
HandlerResult result = new HandlerResultImpl(HandlerResult.Status.COMPLETED, referenceTokenMock);
when(requestMock.getAttribute(AUTHENTICATION_TOKEN_KEY)).thenReturn(result);
when(sessionMock.getAttribute(SECURITY_TOKEN_KEY)).thenReturn(badPrincipalHolderMock);
loginFilter.doFilter(requestMock, responseMock, FAIL_FILTER_CHAIN);
verify(requestMock, times(0)).setAttribute(any(), any());
}
use of org.codice.ddf.security.handler.HandlerResultImpl in project ddf by codice.
the class LoginFilterTest method testBadToken.
@Test
public void testBadToken() throws Exception {
HandlerResult result = new HandlerResultImpl(HandlerResult.Status.COMPLETED, badAuthenticationTokenMock);
when(requestMock.getAttribute(AUTHENTICATION_TOKEN_KEY)).thenReturn(result);
loginFilter.doFilter(requestMock, responseMock, FAIL_FILTER_CHAIN);
verify(requestMock, times(0)).setAttribute(any(), any());
}
use of org.codice.ddf.security.handler.HandlerResultImpl in project ddf by codice.
the class BasicAuthenticationHandler method getNormalizedToken.
/**
* Processes the incoming request to retrieve the username/password tokens. Handles responding to
* the client that authentication is needed if they are not present in the request. Returns the
* {@link org.codice.ddf.security.handler.api.HandlerResult} for the HTTP Request.
*
* @param request http request to obtain attributes from and to pass into any local filter chains
* required
* @param response http response to return http responses or redirects
* @param chain original filter chain (should not be called from your handler)
* @param resolve flag with true implying that credentials should be obtained, false implying
* return if no credentials are found.
* @return
*/
@Override
public HandlerResult getNormalizedToken(ServletRequest request, ServletResponse response, SecurityFilterChain chain, boolean resolve) {
HandlerResult handlerResult = new HandlerResultImpl(HandlerResult.Status.NO_ACTION, null);
handlerResult.setSource(SOURCE);
HttpServletRequest httpRequest = (HttpServletRequest) request;
String path = httpRequest.getServletPath();
LOGGER.debug("Handling request for path {}", path);
LOGGER.debug("Doing authentication and authorization for path {}", path);
AuthenticationToken token = extractAuthenticationInfo(httpRequest);
// we found credentials, attach to result and return with completed status
if (token != null) {
handlerResult.setToken(token);
handlerResult.setStatus(HandlerResult.Status.COMPLETED);
return handlerResult;
}
// prompt for credentials since we didn't find any
doAuthPrompt((HttpServletResponse) response);
handlerResult.setStatus(HandlerResult.Status.REDIRECTED);
return handlerResult;
}
Aggregations