Search in sources :

Example 6 with X509CertificateCallback

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

the class AuthXMLUtils method createX509CertificateCallback.

static X509CertificateCallback createX509CertificateCallback(Node childNode, Callback callback) {
    X509CertificateCallback certCallback = null;
    if (callback != null) {
        if (callback instanceof X509CertificateCallback) {
            certCallback = (X509CertificateCallback) callback;
        }
    }
    if (certCallback == null) {
        certCallback = new X509CertificateCallback(getPrompt(childNode));
    }
    boolean signReq = true;
    String strSignReq = XMLUtils.getNodeAttributeValue(childNode, AuthXMLTags.SIGN_REQUIRED);
    if (strSignReq.equals("false")) {
        signReq = false;
    }
    certCallback.setReqSignature(signReq);
    Node pNode = XMLUtils.getChildNode(childNode, AuthXMLTags.X509CERTIFICATE);
    if (pNode != null) {
        String certificate = XMLUtils.getValueOfValueNode(pNode);
        if (certificate != null) {
            /*
                 * use the base64 decoder from MimeUtility instead of
                 * writing our own
                 */
            byte[] certbytes = Base64.decode(certificate);
            ByteArrayInputStream carray = new ByteArrayInputStream(certbytes);
            try {
                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                X509Certificate userCert = (X509Certificate) cf.generateCertificate(carray);
                certCallback.setCertificate(userCert);
            } catch (CertificateException e) {
                debug.error("createX509CertificateCallback : ", e);
            }
        }
    }
    return certCallback;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback)

Example 7 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 8 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)

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