use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldNotSaveProfileIfRequiredAttributesNotSet.
@Test
public void shouldNotSaveProfileIfRequiredAttributesNotSet() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[2];
PasswordCallback smsOTPCallback = mock(PasswordCallback.class);
ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
int state = 2;
String otpCode = "OTPCODE";
callbacks[0] = smsOTPCallback;
callbacks[1] = confirmationCallback;
given(smsOTPCallback.getPassword()).willReturn(otpCode.toCharArray());
given(confirmationCallback.getSelectedIndex()).willReturn(0);
given(hotpService.isValidHOTP("OTPCODE")).willReturn(true);
given(devicePrintService.hasRequiredAttributes(Matchers.<DevicePrint>anyObject())).willReturn(false);
given(devicePrintAuthenticationConfig.getBoolean(DevicePrintAuthenticationConfig.AUTO_STORE_PROFILES)).willReturn(true);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
verify(devicePrintService, never()).createNewProfile(Matchers.<DevicePrint>anyObject());
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldThrowExceptionStateIsNotKnown.
@Test
public void shouldThrowExceptionStateIsNotKnown() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[0];
int state = 4;
//When
boolean exceptionCaught = false;
try {
devicePrintAuthenticationService.process(callbacks, state);
fail();
} catch (AuthLoginException e) {
exceptionCaught = true;
}
//Then
assertTrue(exceptionCaught);
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldSendOTPWhenDevicePrintInfoNotSufficient.
/*
1) first call ISAuthConstants.LOGIN_START - device print attr populated, device print info not sufficient - should return ISAuthConstants.LOGIN_SUCCEED
2) first call ISAuthConstants.LOGIN_START - device print attr populated, with invalid stored profiles using OTP - should return 2
3) first call ISAuthConstants.LOGIN_START - device print attr populated, with a valid stored profile - should return ISAuthConstants.LOGIN_SUCCEED
4) second call, using OPT, 2 - request OPT to be sent - should return 2
5) third call, using OPT, 2 - OPT code submitted, with correct code - should return 3
6) third call, using OPT, 2 - OPT code submitted, with incorrect code - should throw exception
7) fourth call, 3 - don't save profile - should return ISAuthConstants.LOGIN_SUCCEED, with no profile saved
8) fourth call, 3 - save profile, having no valid previous profiles - should create new profile, return ISAuthConstants.LOGIN_SUCCEED
9) fourth call, 3 - save profile, having a valid previous profile - should update previous profile, return ISAuthConstants.LOGIN_SUCCEED
*/
/**
* 1) first call ISAuthConstants.LOGIN_START - device print attr populated, device print info not sufficient - should return 2 (SEND_OPT)
*/
@Test
public void shouldSendOTPWhenDevicePrintInfoNotSufficient() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[1];
NameCallback devicePrintCallback = mock(NameCallback.class);
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
callbacks[0] = devicePrintCallback;
given(devicePrintCallback.getName()).willReturn("DEVICE_PRINT_INFO");
given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(false);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
assertEquals(nextState, 2);
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManager method handleResponseCallbacks.
/**
* Handles the processing of the JSON given in the request and updates the Callback objects from it.
*
* This is for special circumstances where the JSON from the request does not contain a "callback" attribute,
* where the <code>handleJsonCallbacks()</code> method should be used.
*
* @param request The HttpServletRequest from the request.
* @param response The HttpServletResponse from the request.
* @param originalCallbacks The Callbacks to set values from the JSONArray onto.
* @param jsonRequestObject The JSON object that was sent in the POST of the request.
* @return The updated originalCallbacks.
*/
public Callback[] handleResponseCallbacks(HttpServletRequest request, HttpServletResponse response, Callback[] originalCallbacks, JsonValue jsonRequestObject) throws RestAuthException {
for (Callback originalCallback : originalCallbacks) {
RestAuthCallbackHandler restAuthCallbackHandler = restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(originalCallback.getClass());
restAuthCallbackHandler.handle(request, response, jsonRequestObject, originalCallback);
}
return originalCallbacks;
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class LoginProcess method next.
/**
* Moves the login process to the next step, which means either submitting the callbacks or if the AuthIndexType
* is LEVEL or COMPOSITE then instead of submitting the callbacks, the callbacks are assumed to be the
* authentication module choice login step and the resulting choice will be used to continue the login process.
*
* @param callbacks The array of Callbacks to process.
* @return The LoginProcess to use to continue the login process.
* @throws com.sun.identity.authentication.spi.AuthLoginException If there is a problem processing the login.
*/
public LoginProcess next(Callback[] callbacks) throws AuthLoginException {
AuthIndexType indexType = authContext.getIndexType();
if (indexType == null) {
indexType = loginConfiguration.getIndexType();
}
if (AuthIndexType.LEVEL.equals(indexType) || AuthIndexType.COMPOSITE.equals(indexType)) {
String choice = null;
for (Callback responseCallback : callbacks) {
if (responseCallback instanceof ChoiceCallback) {
int selectedIndex = ((ChoiceCallback) responseCallback).getSelectedIndexes()[0];
choice = ((ChoiceCallback) responseCallback).getChoices()[selectedIndex];
break;
}
}
String indexValue = coreServicesWrapper.getDataFromRealmQualifiedData(choice);
String qualifiedRealm = coreServicesWrapper.getRealmFromRealmQualifiedData(choice);
if ((qualifiedRealm != null) && (qualifiedRealm.length() != 0)) {
String orgDN = coreServicesWrapper.orgNameToDN(qualifiedRealm);
authContext.setOrgDN(orgDN);
}
int type = coreServicesWrapper.getCompositeAdviceType(authContext);
if (type == AuthUtils.MODULE) {
indexType = AuthIndexType.MODULE;
} else if (type == AuthUtils.SERVICE) {
indexType = AuthIndexType.SERVICE;
} else if (type == AuthUtils.REALM) {
indexType = AuthIndexType.SERVICE;
String orgDN = coreServicesWrapper.orgNameToDN(choice);
indexValue = coreServicesWrapper.getOrgConfiguredAuthenticationChain(orgDN);
authContext.setOrgDN(orgDN);
} else {
indexType = AuthIndexType.MODULE;
}
loginConfiguration.indexType(indexType);
loginConfiguration.indexValue(indexValue);
return loginAuthenticator.startLoginProcess(this);
} else {
authContext.submitRequirements(callbacks);
return this;
}
}
Aggregations