Search in sources :

Example 6 with HandlerResultImpl

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());
}
Also used : HandlerResultImpl(org.codice.ddf.security.handler.HandlerResultImpl) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 7 with HandlerResultImpl

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());
}
Also used : HandlerResultImpl(org.codice.ddf.security.handler.HandlerResultImpl) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) PrincipalHolder(ddf.security.common.PrincipalHolder) Test(org.junit.Test)

Example 8 with HandlerResultImpl

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());
}
Also used : HandlerResultImpl(org.codice.ddf.security.handler.HandlerResultImpl) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 9 with HandlerResultImpl

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());
}
Also used : HandlerResultImpl(org.codice.ddf.security.handler.HandlerResultImpl) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult) Test(org.junit.Test)

Example 10 with HandlerResultImpl

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) HandlerResultImpl(org.codice.ddf.security.handler.HandlerResultImpl) HandlerResult(org.codice.ddf.security.handler.api.HandlerResult)

Aggregations

HandlerResultImpl (org.codice.ddf.security.handler.HandlerResultImpl)18 HandlerResult (org.codice.ddf.security.handler.api.HandlerResult)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 IOException (java.io.IOException)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 AuthenticationFailureException (org.codice.ddf.platform.filter.AuthenticationFailureException)4 Test (org.junit.Test)4 SecurityAssertionSaml (ddf.security.assertion.saml.impl.SecurityAssertionSaml)2 PrincipalHolder (ddf.security.common.PrincipalHolder)2 Cookie (javax.servlet.http.Cookie)2 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)2 SessionException (org.apache.shiro.session.SessionException)2 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)2 AuthenticationChallengeException (org.codice.ddf.platform.filter.AuthenticationChallengeException)2 AuthenticationException (org.codice.ddf.platform.filter.AuthenticationException)2 BaseAuthenticationToken (org.codice.ddf.security.handler.BaseAuthenticationToken)2 OidcAuthenticationToken (org.codice.ddf.security.handler.OidcAuthenticationToken)2 SAMLAuthenticationToken (org.codice.ddf.security.handler.SAMLAuthenticationToken)2 JEEContext (org.pac4j.core.context.JEEContext)2 JEESessionStore (org.pac4j.core.context.session.JEESessionStore)2