Search in sources :

Example 1 with X509CertificateCallback

use of com.sun.identity.authentication.spi.X509CertificateCallback in project OpenAM by OpenRock.

the class RestAuthX509CallbackHandlerTest method shouldUpdateCallbackFromRequest.

@Test
public void shouldUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    X509CertificateCallback x509CertificateCallback = mock(X509CertificateCallback.class);
    X509Certificate x509Certificate = mock(X509Certificate.class);
    X509Certificate[] x509Certificates = new X509Certificate[] { x509Certificate };
    given(request.getAttribute("javax.servlet.request.X509Certificate")).willReturn(x509Certificates);
    //When
    boolean updated = restAuthX509CallbackHandler.updateCallbackFromRequest(request, response, x509CertificateCallback);
    //Then
    verify(x509CertificateCallback).setCertificate(x509Certificate);
    assertTrue(updated);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) X509Certificate(java.security.cert.X509Certificate) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) Test(org.testng.annotations.Test)

Example 2 with X509CertificateCallback

use of com.sun.identity.authentication.spi.X509CertificateCallback in project OpenAM by OpenRock.

the class RestAuthX509CallbackHandlerTest method shouldUpdateCallbackFromRequestWithMultipleX509Certificates.

@Test
public void shouldUpdateCallbackFromRequestWithMultipleX509Certificates() throws RestAuthResponseException, RestAuthException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    X509CertificateCallback x509CertificateCallback = mock(X509CertificateCallback.class);
    X509Certificate x509Certificate = mock(X509Certificate.class);
    X509Certificate x509Certificate2 = mock(X509Certificate.class);
    X509Certificate[] x509Certificates = new X509Certificate[] { x509Certificate, x509Certificate2 };
    given(request.getAttribute("javax.servlet.request.X509Certificate")).willReturn(x509Certificates);
    //When
    boolean updated = restAuthX509CallbackHandler.updateCallbackFromRequest(request, response, x509CertificateCallback);
    //Then
    verify(x509CertificateCallback).setCertificate(x509Certificate);
    assertTrue(updated);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) X509Certificate(java.security.cert.X509Certificate) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) Test(org.testng.annotations.Test)

Example 3 with X509CertificateCallback

use of com.sun.identity.authentication.spi.X509CertificateCallback in project OpenAM by OpenRock.

the class RestAuthX509CallbackHandlerTest method shouldNotUpdateCallbackFromRequestWithNoX509Certificate.

@Test
public void shouldNotUpdateCallbackFromRequestWithNoX509Certificate() throws RestAuthResponseException, RestAuthException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    X509CertificateCallback x509CertificateCallback = mock(X509CertificateCallback.class);
    X509Certificate[] x509Certificates = new X509Certificate[] {};
    given(request.getAttribute("javax.servlet.request.X509Certificate")).willReturn(x509Certificates);
    //When
    boolean updated = restAuthX509CallbackHandler.updateCallbackFromRequest(request, response, x509CertificateCallback);
    //Then
    verify(x509CertificateCallback, never()).setCertificate(Matchers.<X509Certificate>anyObject());
    assertTrue(updated);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) X509Certificate(java.security.cert.X509Certificate) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) Test(org.testng.annotations.Test)

Example 4 with X509CertificateCallback

use of com.sun.identity.authentication.spi.X509CertificateCallback in project OpenAM by OpenRock.

the class RestAuthX509CallbackHandlerTest method shouldHandleCallback.

@Test
public void shouldHandleCallback() {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    JsonValue jsonPostBody = mock(JsonValue.class);
    X509CertificateCallback originalX509CertificateCallback = mock(X509CertificateCallback.class);
    //When
    X509CertificateCallback x509CertificateCallback = restAuthX509CallbackHandler.handle(request, response, jsonPostBody, originalX509CertificateCallback);
    //Then
    Assert.assertEquals(originalX509CertificateCallback, x509CertificateCallback);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) Test(org.testng.annotations.Test)

Example 5 with X509CertificateCallback

use of com.sun.identity.authentication.spi.X509CertificateCallback in project OpenAM by OpenRock.

the class AuthXMLHandler method processRequirements.

/*
     * process callbacks
     */
private void processRequirements(String xml, AuthContextLocal authContext, AuthXMLResponse authResponse, String params, HttpServletRequest servletRequest) {
    String[] paramArray = null;
    StringTokenizer paramsSet = null;
    if (params != null) {
        paramsSet = new StringTokenizer(params, ISAuthConstants.PIPE_SEPARATOR);
    }
    boolean allCallbacksAreSet = true;
    String param;
    while (authContext.hasMoreRequirements()) {
        Callback[] reqdCallbacks = authContext.getRequirements();
        for (int i = 0; i < reqdCallbacks.length; i++) {
            if (reqdCallbacks[i] instanceof X509CertificateCallback) {
                X509CertificateCallback certCallback = (X509CertificateCallback) reqdCallbacks[i];
                LoginState loginState = AuthUtils.getLoginState(authContext);
                if (loginState != null) {
                    X509Certificate cert = loginState.getX509Certificate(servletRequest);
                    if (cert != null) {
                        certCallback.setCertificate(cert);
                        certCallback.setReqSignature(false);
                    } else {
                        allCallbacksAreSet = false;
                    }
                }
            } else {
                param = null;
                if (reqdCallbacks[i] instanceof NameCallback) {
                    param = getNextParam(paramsSet);
                    if (param != null) {
                        NameCallback nc = (NameCallback) reqdCallbacks[i];
                        nc.setName(param);
                        if (messageEnabled) {
                            debug.message("Name callback set to " + param);
                        }
                    } else {
                        allCallbacksAreSet = false;
                        break;
                    }
                } else if (reqdCallbacks[i] instanceof PasswordCallback) {
                    param = getNextParam(paramsSet);
                    if (param != null) {
                        PasswordCallback pc = (PasswordCallback) reqdCallbacks[i];
                        pc.setPassword(param.toCharArray());
                        if (messageEnabled) {
                            debug.message("Password callback is set");
                        }
                    } else {
                        allCallbacksAreSet = false;
                        break;
                    }
                } else {
                    if (params == null) {
                        allCallbacksAreSet = false;
                    }
                }
            // add more callbacks if required
            }
        }
        if (getNextParam(paramsSet) != null) {
            allCallbacksAreSet = false;
        }
        if (allCallbacksAreSet) {
            if (messageEnabled) {
                debug.message("submit callbacks with passed in params");
            }
            authContext.submitRequirements(reqdCallbacks);
        } else {
            authResponse.setReqdCallbacks(reqdCallbacks);
            break;
        }
    }
    if (!authContext.hasMoreRequirements()) {
        AuthContext.Status loginStatus = authContext.getStatus();
        if (messageEnabled) {
            debug.message(" Status: " + loginStatus);
        }
        authResponse.setLoginStatus(loginStatus);
    }
}
Also used : AuthContext(com.sun.identity.authentication.AuthContext) X509Certificate(java.security.cert.X509Certificate) StringTokenizer(java.util.StringTokenizer) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) NameCallback(javax.security.auth.callback.NameCallback) LoginState(com.sun.identity.authentication.service.LoginState) PasswordCallback(javax.security.auth.callback.PasswordCallback) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback)

Aggregations

X509CertificateCallback (com.sun.identity.authentication.spi.X509CertificateCallback)8 X509Certificate (java.security.cert.X509Certificate)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Test (org.testng.annotations.Test)4 Callback (javax.security.auth.callback.Callback)2 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)2 NameCallback (javax.security.auth.callback.NameCallback)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 AuthContext (com.sun.identity.authentication.AuthContext)1 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)1 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)1 LoginState (com.sun.identity.authentication.service.LoginState)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 DSAMECallbackInterface (com.sun.identity.authentication.spi.DSAMECallbackInterface)1 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)1 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)1 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CertificateException (java.security.cert.CertificateException)1