Search in sources :

Example 26 with ChoiceCallback

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

the class AuthXMLUtils method createChoiceCallback.

static ChoiceCallback createChoiceCallback(Node childNode, Callback callback) {
    ChoiceCallback choiceCallback = null;
    if (callback != null) {
        if (callback instanceof ChoiceCallback) {
            choiceCallback = (ChoiceCallback) callback;
        }
    }
    if (choiceCallback == null) {
        String prompt = getPrompt(childNode);
        boolean multiSelect = false;
        String multiSelectAttr = XMLUtils.getNodeAttributeValue(childNode, AuthXMLTags.MULTI_SELECT_ALLOWED);
        if ((multiSelectAttr != null) && multiSelectAttr.equals("true")) {
            multiSelect = true;
        }
        String[] choices = null;
        int defaultChoice = 0;
        Node choicesNode = XMLUtils.getChildNode(childNode, AuthXMLTags.CHOICE_VALUES);
        NodeList choicesChildNodes = choicesNode.getChildNodes();
        choices = new String[choicesChildNodes.getLength()];
        for (int j = 0; j < choicesChildNodes.getLength(); j++) {
            Node choiceValueNode = choicesChildNodes.item(j);
            String isDefaultAttr = XMLUtils.getNodeAttributeValue(choiceValueNode, AuthXMLTags.IS_DEFAULT);
            if ((isDefaultAttr != null) && isDefaultAttr.equals("yes")) {
                defaultChoice = j;
            }
            String choiceValue = getValue(choiceValueNode);
            choices[j] = choiceValue;
        }
        choiceCallback = new ChoiceCallback(prompt, choices, defaultChoice, multiSelect);
    }
    int[] selectedIndexes;
    Node selectedNode = XMLUtils.getChildNode(childNode, AuthXMLTags.SELECTED_VALUES);
    if (selectedNode != null) {
        NodeList selectChildNodes = selectedNode.getChildNodes();
        selectedIndexes = new int[selectChildNodes.getLength()];
        for (int j = 0; j < selectChildNodes.getLength(); j++) {
            Node selectValueNode = selectChildNodes.item(j);
            selectedIndexes[j] = Integer.parseInt(XMLUtils.getValueOfValueNode(selectValueNode));
        }
        if (choiceCallback.allowMultipleSelections()) {
            choiceCallback.setSelectedIndexes(selectedIndexes);
        } else {
            choiceCallback.setSelectedIndex(selectedIndexes[0]);
        }
    }
    return choiceCallback;
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Example 27 with ChoiceCallback

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

the class AuthXMLUtils method getXMLForCallbacks.

/**
     * TODO-JAVADOC
     */
public static String getXMLForCallbacks(Callback[] callbacks) {
    if (callbacks == null) {
        return ("");
    }
    // Construct the xml string
    StringBuilder xmlString = new StringBuilder();
    xmlString.append(AuthXMLTags.CALLBACKS_BEGIN).append(AuthXMLTags.SPACE).append(AuthXMLTags.LENGTH).append(AuthXMLTags.EQUAL).append(AuthXMLTags.QUOTE).append(callbacks.length).append(AuthXMLTags.QUOTE).append(AuthXMLTags.ELEMENT_END);
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof HiddenValueCallback) {
            HiddenValueCallback hiddenValueCallback = (HiddenValueCallback) callbacks[i];
            xmlString.append(getHiddenValueCallbackXML(hiddenValueCallback));
        } else if (callbacks[i] instanceof NameCallback) {
            NameCallback nameCallback = (NameCallback) callbacks[i];
            xmlString.append(getNameCallbackXML(nameCallback));
        } else if (callbacks[i] instanceof PasswordCallback) {
            PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
            xmlString.append(getPasswordCallbackXML(passwordCallback));
        } else if (callbacks[i] instanceof ChoiceCallback) {
            ChoiceCallback choiceCallback = (ChoiceCallback) callbacks[i];
            xmlString.append(getChoiceCallbackXML(choiceCallback));
        } else if (callbacks[i] instanceof ConfirmationCallback) {
            ConfirmationCallback conCallback = (ConfirmationCallback) callbacks[i];
            xmlString.append(getConfirmationCallbackXML(conCallback));
        } else if (callbacks[i] instanceof TextInputCallback) {
            TextInputCallback textInputCallback = (TextInputCallback) callbacks[i];
            xmlString.append(getTextInputCallbackXML(textInputCallback));
        } else if (callbacks[i] instanceof TextOutputCallback) {
            TextOutputCallback textOutputCallback = (TextOutputCallback) callbacks[i];
            xmlString.append(getTextOutputCallbackXML(textOutputCallback));
        } else if (callbacks[i] instanceof PagePropertiesCallback) {
            PagePropertiesCallback pagePCallback = (PagePropertiesCallback) callbacks[i];
            xmlString.append(getPagePropertiesCallbackXML(pagePCallback));
        } else if (callbacks[i] instanceof LanguageCallback) {
            LanguageCallback lc = (LanguageCallback) callbacks[i];
            xmlString.append(getLanguageCallbackXML(lc));
        } else if (callbacks[i] instanceof X509CertificateCallback) {
            X509CertificateCallback xc = (X509CertificateCallback) callbacks[i];
            xmlString.append(getX509CertificateCallbackXML(xc));
        } else if (callbacks[i] instanceof HttpCallback) {
            HttpCallback hc = (HttpCallback) callbacks[i];
            xmlString.append(getHttpCallbackXML(hc));
        } else if (callbacks[i] instanceof DSAMECallbackInterface) {
            DSAMECallbackInterface dsameCallback = (DSAMECallbackInterface) callbacks[i];
            xmlString.append(getCustomCallbackXML(dsameCallback));
        } else if (callbacks[i] instanceof RedirectCallback) {
            RedirectCallback redirectCallback = (RedirectCallback) callbacks[i];
            xmlString.append(getRedirectCallbackXML(redirectCallback));
        } else {
            AuthenticationCallbackXMLHelper callbackXMLHelper = AuthenticationCallbackXMLHelperFactory.getCallbackXMLHelper();
            if (callbackXMLHelper != null) {
                xmlString.append(callbackXMLHelper.getAuthenticationCallbackXML(callbacks[i]));
            }
        }
    }
    xmlString.append(AuthXMLTags.CALLBACKS_END);
    return (xmlString.toString());
}
Also used : RedirectCallback(com.sun.identity.authentication.spi.RedirectCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) TextInputCallback(javax.security.auth.callback.TextInputCallback) DSAMECallbackInterface(com.sun.identity.authentication.spi.DSAMECallbackInterface) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback)

Example 28 with ChoiceCallback

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

the class LoginProcessTest method shouldRestartLoginProcessWhenCompositeUsedToChooseAuthModuleWithAuthTypeRealm.

@Test
public void shouldRestartLoginProcessWhenCompositeUsedToChooseAuthModuleWithAuthTypeRealm() 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.COMPOSITE);
    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(null);
    given(coreServicesWrapper.orgNameToDN("CHOICE_ONE")).willReturn("ORG_DN");
    given(coreServicesWrapper.getCompositeAdviceType(authContext)).willReturn(AuthUtils.REALM);
    given(coreServicesWrapper.getOrgConfiguredAuthenticationChain("ORG_DN")).willReturn("SERVICE_INDEX_VALUE");
    //When
    LoginProcess loginP = loginProcess.next(callbacks);
    //Then
    verify(authContext, never()).submitRequirements(callbacks);
    verify(authContext).setOrgDN("ORG_DN");
    verify(loginConfiguration).indexType(AuthIndexType.SERVICE);
    verify(loginConfiguration).indexValue("SERVICE_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 29 with ChoiceCallback

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

the class LoginProcessTest method shouldRestartLoginProcessWhenCompositeUsedToChooseAuthModule.

@Test
public void shouldRestartLoginProcessWhenCompositeUsedToChooseAuthModule() 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.COMPOSITE);
    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(null);
    given(coreServicesWrapper.getCompositeAdviceType(authContext)).willReturn(-1);
    //When
    LoginProcess loginP = loginProcess.next(callbacks);
    //Then
    verify(authContext, never()).submitRequirements(callbacks);
    verify(authContext, never()).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 30 with ChoiceCallback

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

the class LoginProcessTest method shouldRestartLoginProcessWhenLevelUsedToChooseAuthModuleWithAuthTypeService.

@Test
public void shouldRestartLoginProcessWhenLevelUsedToChooseAuthModuleWithAuthTypeService() 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(null);
    given(coreServicesWrapper.getCompositeAdviceType(authContext)).willReturn(AuthUtils.SERVICE);
    //When
    LoginProcess loginP = loginProcess.next(callbacks);
    //Then
    verify(authContext, never()).submitRequirements(callbacks);
    verify(authContext, never()).setOrgDN(anyString());
    verify(loginConfiguration).indexType(AuthIndexType.SERVICE);
    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)

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