Search in sources :

Example 31 with ChoiceCallback

use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.

the class LoginProcessTest method shouldRestartLoginProcessWhenLevelUsedToChooseAuthModuleWithAuthTypeModule.

@Test
public void shouldRestartLoginProcessWhenLevelUsedToChooseAuthModuleWithAuthTypeModule() throws AuthLoginException {
    //Given
    Callback callbackOne = mock(Callback.class);
    ChoiceCallback callbackTwo = mock(ChoiceCallback.class);
    Callback callbackThree = mock(Callback.class);
    Callback[] callbacks = new Callback[] { callbackOne, callbackTwo, callbackThree };
    given(authContext.getIndexType()).willReturn(AuthIndexType.LEVEL);
    given(callbackTwo.getSelectedIndexes()).willReturn(new int[] { 0 });
    given(callbackTwo.getChoices()).willReturn(new String[] { "CHOICE_ONE" });
    given(coreServicesWrapper.getDataFromRealmQualifiedData("CHOICE_ONE")).willReturn("INDEX_VALUE");
    given(coreServicesWrapper.getRealmFromRealmQualifiedData("CHOICE_ONE")).willReturn("QUALIFIED_REALM");
    given(coreServicesWrapper.orgNameToDN("QUALIFIED_REALM")).willReturn("ORG_DN");
    given(coreServicesWrapper.getCompositeAdviceType(authContext)).willReturn(AuthUtils.MODULE);
    //When
    LoginProcess loginP = loginProcess.next(callbacks);
    //Then
    verify(authContext, never()).submitRequirements(callbacks);
    verify(authContext).setOrgDN("ORG_DN");
    verify(loginConfiguration).indexType(AuthIndexType.MODULE);
    verify(loginConfiguration).indexValue("INDEX_VALUE");
    verify(loginAuthenticator).startLoginProcess(loginProcess);
    assertNotEquals(loginP, loginProcess);
}
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) Test(org.testng.annotations.Test)

Example 32 with ChoiceCallback

use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.

the class OpenAMAuthHandler method getNextCallbackReplyMsg.

/**
     * Generates reply message for the current callback to be embedded in a challenge response to gather an answer for
     * that callback. If an unknown/unexpected callback type is incurred the process is terminated with a reject
     * response.
     *
     * @param respHandler
     * @param holder
     * @return
     */
private ReplyMessageAttribute getNextCallbackReplyMsg(RadiusResponse response, ContextHolder holder) {
    LOG.message("Entering getNextCallbackReplyMsg()");
    ReplyMessageAttribute msg = null;
    final Callback[] callbacks = holder.getCallbacks();
    if (callbacks == null) {
        return null;
    }
    final Callback cb = callbacks[holder.getIdxOfCurrentCallback()];
    String header = "";
    final PagePropertiesCallback pagePropCallback = holder.getCallbackSetProps();
    if (pagePropCallback != null && !"".equals(pagePropCallback.getHeader())) {
        header = pagePropCallback.getHeader() + " ";
    }
    if (cb instanceof NameCallback) {
        LOG.message("getNextCallbackReplyMsg(); - processing NameCallback.");
        msg = new ReplyMessageAttribute(header + ((NameCallback) cb).getPrompt());
    } else if (cb instanceof PasswordCallback) {
        LOG.message("getNextCallbackReplyMsg(); - processing PasswordCallback.");
        msg = new ReplyMessageAttribute(header + ((PasswordCallback) cb).getPrompt());
    } else if (cb instanceof ChoiceCallback) {
        LOG.message("getNextCallbackReplyMsg(); - processing ChoiceCallback.");
        final ChoiceCallback cc = (ChoiceCallback) cb;
        final StringBuilder sb = new StringBuilder();
        sb.append(header);
        sb.append(cc.getPrompt());
        if (cc.allowMultipleSelections()) {
            // ugh. we'll have to figure out how to translate this suitably in view of sentence structure for
            // a given locale.
            // TODO: LOCALIZE
            sb.append(" (Separate Selected Numbers by Spaces");
            if (cc.getDefaultChoice() >= 0) {
                sb.append(". Default is " + cc.getDefaultChoice());
            }
            sb.append(".)");
        }
        sb.append('\n');
        final String[] choices = cc.getChoices();
        for (int j = 0; j < choices.length; j++) {
            final String choice = choices[j];
            if (j != 0) {
                sb.append(",\n");
            }
            sb.append(j);
            sb.append(" = ");
            sb.append(choice);
        }
        msg = new ReplyMessageAttribute(sb.toString());
    } else if (cb instanceof ConfirmationCallback) {
        LOG.message("getNextCallbackReplyMsg(); - processing ConformationCallback.");
        final ConfirmationCallback cc = (ConfirmationCallback) cb;
        final StringBuilder sb = new StringBuilder();
        sb.append(header);
        sb.append(cc.getPrompt());
        if (cc.getDefaultOption() >= 0) {
            // ugh. ditto on above translation concern
            sb.append(" (Default is ");
            sb.append(cc.getDefaultOption());
            sb.append(".)");
        }
        sb.append('\n');
        final String[] options = cc.getOptions();
        for (int j = 0; j < options.length; j++) {
            final String option = options[j];
            if (j != 0) {
                sb.append(",\n");
            }
            sb.append(j);
            sb.append(" = ");
            sb.append(option);
        }
        msg = new ReplyMessageAttribute(sb.toString());
    } else {
        // unknown and unexpected type
        LOG.error("Radius can not support " + cb.getClass().getSimpleName() + " used by module " + holder.getChainModuleIndex() + " with name " + holder.getModuleName() + " in chain '" + this.authChain + "'. Denying Access.");
        rejectAccessAndTerminateProcess(response, holder);
    }
    LOG.message("Entering getNextCallbackReplyMsg() returning '" + msg + "'");
    return msg;
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) ReplyMessageAttribute(org.forgerock.openam.radius.common.ReplyMessageAttribute) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) RedirectCallback(com.sun.identity.authentication.spi.RedirectCallback) 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) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Aggregations

ChoiceCallback (javax.security.auth.callback.ChoiceCallback)32 Callback (javax.security.auth.callback.Callback)19 Test (org.testng.annotations.Test)17 NameCallback (javax.security.auth.callback.NameCallback)15 PasswordCallback (javax.security.auth.callback.PasswordCallback)13 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)12 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)9 JsonValue (org.forgerock.json.JsonValue)8 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)5 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)5 TextInputCallback (javax.security.auth.callback.TextInputCallback)5 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)5 SSOException (com.iplanet.sso.SSOException)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)4 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)4 ArrayList (java.util.ArrayList)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LanguageCallback (javax.security.auth.callback.LanguageCallback)3