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