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;
}
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);
}
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);
}
Aggregations