Search in sources :

Example 1 with MessageInfo

use of javax.security.auth.message.MessageInfo in project tomcat by apache.

the class AuthenticatorBase method logout.

@Override
public void logout(Request request) {
    AuthConfigProvider provider = getJaspicProvider();
    if (provider != null) {
        MessageInfo messageInfo = new MessageInfoImpl(request, request.getResponse(), true);
        Subject client = (Subject) request.getNote(Constants.REQ_JASPIC_SUBJECT_NOTE);
        if (client == null) {
            return;
        }
        ServerAuthContext serverAuthContext;
        try {
            ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet", jaspicAppContextID, CallbackHandlerImpl.getInstance());
            String authContextID = serverAuthConfig.getAuthContextID(messageInfo);
            serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null);
            serverAuthContext.cleanSubject(messageInfo, client);
        } catch (AuthException e) {
            log.debug(sm.getString("authenticator.jaspicCleanSubjectFail"), e);
        }
    }
    Principal p = request.getPrincipal();
    if (p instanceof TomcatPrincipal) {
        try {
            ((TomcatPrincipal) p).logout();
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            log.debug(sm.getString("authenticator.tomcatPrincipalLogoutFail"), t);
        }
    }
    register(request, request.getResponse(), null, null, null, null);
}
Also used : AuthConfigProvider(javax.security.auth.message.config.AuthConfigProvider) MessageInfoImpl(org.apache.catalina.authenticator.jaspic.MessageInfoImpl) AuthException(javax.security.auth.message.AuthException) Subject(javax.security.auth.Subject) ServerAuthConfig(javax.security.auth.message.config.ServerAuthConfig) Principal(java.security.Principal) TomcatPrincipal(org.apache.catalina.TomcatPrincipal) GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) MessageInfo(javax.security.auth.message.MessageInfo) ServerAuthContext(javax.security.auth.message.config.ServerAuthContext) TomcatPrincipal(org.apache.catalina.TomcatPrincipal)

Example 2 with MessageInfo

use of javax.security.auth.message.MessageInfo in project tomcat by apache.

the class TestSimpleServerAuthConfig method validateServerAuthContext.

private void validateServerAuthContext(ServerAuthContext serverAuthContext) throws Exception {
    MessageInfo msgInfo = new TesterMessageInfo();
    serverAuthContext.cleanSubject(msgInfo, null);
    Assert.assertEquals("init()-cleanSubject()-", msgInfo.getMap().get("trace"));
}
Also used : MessageInfo(javax.security.auth.message.MessageInfo)

Example 3 with MessageInfo

use of javax.security.auth.message.MessageInfo in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapper method onLoginSuccess.

/**
     * Post processing of successful authentication, which initialises the underlying JASPI ServerAuthModule, as a new
     * instance of this class is created for the Post Authentication Process, and then calls the subtypes
     * onLoginSuccess method, and then finally calls the JASPI ServerAuthModule's secureResponse method.
     *
     * @param requestParamsMap {@inheritDoc}
     * @param request {@inheritDoc}
     * @param response {@inheritDoc}
     * @param ssoToken {@inheritDoc}
     * @throws AuthenticationException {@inheritDoc}
     */
public void onLoginSuccess(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
    try {
        Map<String, Object> config = initialize(requestParamsMap, request, response, ssoToken);
        serverAuthModule.initialize(createRequestMessagePolicy(), null, null, config);
        MessageInfo messageInfo = prepareMessageInfo(request, response);
        onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
        AuthStatus authStatus = serverAuthModule.secureResponse(messageInfo, null);
        if (AuthStatus.SEND_SUCCESS.equals(authStatus)) {
            // nothing to do here just carry on
            debug.message("Successfully secured response.");
        } else if (AuthStatus.SEND_FAILURE.equals(authStatus)) {
            // Send HttpServletResponse to client and exit.
            debug.message("Failed to secured response, included response message");
            throw new AuthenticationException(resourceBundleName, "authFailed", null);
        } else if (AuthStatus.SEND_CONTINUE.equals(authStatus)) {
            // Send HttpServletResponse to client and exit.
            debug.message("Has not finished securing response. Requires more information from client.");
            throw new AuthenticationException(resourceBundleName, "authFailed", null);
        } else {
            debug.error("Invalid AuthStatus, " + authStatus.toString());
            throw new AuthenticationException(resourceBundleName, "authFailed", null);
        }
    } catch (AuthException e) {
        debug.error("Authentication Failed", e);
        throw new AuthenticationException(resourceBundleName, "authFailed", null);
    }
}
Also used : AuthStatus(javax.security.auth.message.AuthStatus) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) AuthException(javax.security.auth.message.AuthException) MessageInfo(javax.security.auth.message.MessageInfo)

Example 4 with MessageInfo

use of javax.security.auth.message.MessageInfo in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapperTest method setUp.

@BeforeMethod
public void setUp() {
    amLoginModuleBinder = mock(AMLoginModuleBinder.class);
    serverAuthModule = mock(ServerAuthModule.class);
    jaspiAuthModuleWrapper = new JaspiAuthModuleWrapper<ServerAuthModule>(serverAuthModule, "amAuthPersistentCookie") {

        @Override
        protected Map<String, Object> initialize(Subject subject, Map sharedState, Map options) {
            return config;
        }

        @Override
        protected boolean process(MessageInfo messageInfo, Subject clientSubject, Callback[] callbacks) throws LoginException {
            processMethodCalled = true;
            return true;
        }

        @Override
        protected Map<String, Object> initialize(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
            return config;
        }

        @Override
        protected void onLoginSuccess(MessageInfo messageInfo, Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
            onLoginSuccessMethodCalled = true;
        }

        @Override
        public Principal getPrincipal() {
            return null;
        }
    };
    jaspiAuthModuleWrapper.setAMLoginModule(amLoginModuleBinder);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
    given(amLoginModuleBinder.getHttpServletResponse()).willReturn(response);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) ServerAuthModule(javax.security.auth.message.module.ServerAuthModule) HttpServletResponse(javax.servlet.http.HttpServletResponse) Subject(javax.security.auth.Subject) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) Callback(javax.security.auth.callback.Callback) LoginException(javax.security.auth.login.LoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with MessageInfo

use of javax.security.auth.message.MessageInfo in project OpenAM by OpenRock.

the class PersistentCookieAuthModuleTest method shouldStoreClientIPOnLoginSuccess.

@Test
public void shouldStoreClientIPOnLoginSuccess() throws AuthenticationException, SSOException {
    //Given
    MessageInfo messageInfo = mock(MessageInfo.class);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    Map<String, Object> messageInfoMap = new HashMap<String, Object>();
    Map<String, Object> contextMap = new HashMap<String, Object>();
    Principal principal = mock(Principal.class);
    SSOTokenID ssoTokenID = mock(SSOTokenID.class);
    given(messageInfo.getMap()).willReturn(messageInfoMap);
    messageInfoMap.put(AuthenticationFramework.ATTRIBUTE_AUTH_CONTEXT, contextMap);
    given(ssoToken.getPrincipal()).willReturn(principal);
    given(ssoToken.getTokenID()).willReturn(ssoTokenID);
    given(request.getRemoteAddr()).willReturn("CLIENT_IP");
    //When
    persistentCookieAuthModule.onLoginSuccess(messageInfo, Collections.emptyMap(), request, response, ssoToken);
    //Then
    assertEquals(contextMap.get("openam.clientip"), "CLIENT_IP");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) Principal(java.security.Principal) MessageInfo(javax.security.auth.message.MessageInfo) Test(org.testng.annotations.Test)

Aggregations

MessageInfo (javax.security.auth.message.MessageInfo)12 HashMap (java.util.HashMap)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 Map (java.util.Map)7 Subject (javax.security.auth.Subject)7 Test (org.testng.annotations.Test)7 Principal (java.security.Principal)5 Callback (javax.security.auth.callback.Callback)5 SSOToken (com.iplanet.sso.SSOToken)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Jwt (org.forgerock.json.jose.jwt.Jwt)4 JwtClaimsSet (org.forgerock.json.jose.jwt.JwtClaimsSet)4 SSOTokenID (com.iplanet.sso.SSOTokenID)3 SSOException (com.iplanet.sso.SSOException)2 AuthenticationException (com.sun.identity.authentication.spi.AuthenticationException)2 SMSException (com.sun.identity.sm.SMSException)2 AuthException (javax.security.auth.message.AuthException)2 ServletJwtSessionModule (org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 LoginException (javax.security.auth.login.LoginException)1