Search in sources :

Example 36 with Callback

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());
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 37 with Callback

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);
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 38 with Callback

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);
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) Test(org.testng.annotations.Test)

Example 39 with Callback

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;
}
Also used : Callback(javax.security.auth.callback.Callback) RestAuthCallbackHandler(org.forgerock.openam.core.rest.authn.callbackhandlers.RestAuthCallbackHandler)

Example 40 with Callback

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;
    }
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) Callback(javax.security.auth.callback.Callback)

Aggregations

Callback (javax.security.auth.callback.Callback)390 NameCallback (javax.security.auth.callback.NameCallback)250 PasswordCallback (javax.security.auth.callback.PasswordCallback)245 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)210 IOException (java.io.IOException)141 LoginException (javax.security.auth.login.LoginException)89 CallbackHandler (javax.security.auth.callback.CallbackHandler)76 Subject (javax.security.auth.Subject)52 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)52 Test (org.testng.annotations.Test)42 FailedLoginException (javax.security.auth.login.FailedLoginException)41 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)38 Principal (java.security.Principal)37 HashMap (java.util.HashMap)37 LoginContext (javax.security.auth.login.LoginContext)37 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)31 Test (org.junit.Test)31 RealmCallback (javax.security.sasl.RealmCallback)30 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)28