Search in sources :

Example 11 with TextOutputCallback

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

the class AMLoginModule method cloneCallbacks.

/**
     * Clone Callback[], and save it in the internal/external
     * callbacks list. External callback contains all user defined
     * Callbacks in the xml module configuration (property file),
     * internal callback contains the external callbacks plus the
     * PagePropertiesCallback. Note here, although
     * Callback[] in internal/external are different, the Callback
     * instance they pointed are actually same instance
     * @param index indicates state of callback
     * @param original original array of callback to be cloned
     * @return Callback[] returns cloned callback
     * @exception AuthLoginException if callback can not be cloned
     */
private Callback[] cloneCallbacks(int index, Callback[] original) throws AuthLoginException {
    // check if there is any callbacks in original
    if (original == null || original.length == 0) {
        // this is the error case where there is no Callbacks
        // defined for a state
        debug.error("cloneCallbacks, no callbacks in state " + (index + 1));
        throw new AuthLoginException(bundleName, "noCallbackState", new Object[] { new Integer(index + 1) });
    }
    int len = original.length;
    // Callback array which hold the cloned Callbacks
    Callback[] copy = new Callback[len];
    // List which contains the external callbacks only
    List extCallbacks = new ArrayList();
    // if it is an external Callback, add to the extCallback list
    for (int i = 0; i < len; i++) {
        if (original[i] instanceof HiddenValueCallback) {
            final HiddenValueCallback hiddenValueCallback = (HiddenValueCallback) original[i];
            String defaultValue = hiddenValueCallback.getDefaultValue();
            if (defaultValue != null && defaultValue.length() != 0) {
                copy[i] = new HiddenValueCallback(hiddenValueCallback.getId(), defaultValue);
            } else {
                copy[i] = new HiddenValueCallback(hiddenValueCallback.getId());
            }
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is HiddenValueCallback");
            }
        } else if (original[i] instanceof NameCallback) {
            String dftName = ((NameCallback) original[i]).getDefaultName();
            if (dftName != null && dftName.length() != 0) {
                copy[i] = new NameCallback(((NameCallback) original[i]).getPrompt(), dftName);
            } else {
                copy[i] = new NameCallback(((NameCallback) original[i]).getPrompt());
            }
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is NameCallback");
            }
        } else if (original[i] instanceof PasswordCallback) {
            copy[i] = new PasswordCallback(((PasswordCallback) original[i]).getPrompt(), ((PasswordCallback) original[i]).isEchoOn());
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is PasswordCallback");
            }
        } else if (original[i] instanceof ScriptTextOutputCallback) {
            copy[i] = new ScriptTextOutputCallback(((TextOutputCallback) original[i]).getMessage());
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is ScriptTextOutputCallback");
            }
        } else if (original[i] instanceof TextOutputCallback) {
            copy[i] = new TextOutputCallback(((TextOutputCallback) original[i]).getMessageType(), ((TextOutputCallback) original[i]).getMessage());
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is TextOutputCallback");
            }
        } else if (original[i] instanceof PagePropertiesCallback) {
            // PagePropertiesCallback, no need to add to external callbacks
            copy[i] = new PagePropertiesCallback(((PagePropertiesCallback) original[i]).getModuleName(), ((PagePropertiesCallback) original[i]).getHeader(), ((PagePropertiesCallback) original[i]).getImage(), ((PagePropertiesCallback) original[i]).getTimeOutValue(), ((PagePropertiesCallback) original[i]).getTemplateName(), ((PagePropertiesCallback) original[i]).getErrorState(), ((PagePropertiesCallback) original[i]).getPageState());
            ((PagePropertiesCallback) copy[i]).setRequire(((PagePropertiesCallback) original[i]).getRequire());
            ((PagePropertiesCallback) copy[i]).setAttribute(((PagePropertiesCallback) original[i]).getAttribute());
            ((PagePropertiesCallback) copy[i]).setInfoText(((PagePropertiesCallback) original[i]).getInfoText());
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is PagePropertiesCallback");
            }
        } else if (original[i] instanceof ChoiceCallback) {
            ChoiceCallback originalChoiceCallback = (ChoiceCallback) original[i];
            ChoiceCallback clone = new ChoiceCallback(originalChoiceCallback.getPrompt(), originalChoiceCallback.getChoices(), originalChoiceCallback.getDefaultChoice(), originalChoiceCallback.allowMultipleSelections());
            if (originalChoiceCallback.getSelectedIndexes() != null && originalChoiceCallback.getSelectedIndexes().length > 0) {
                if (originalChoiceCallback.allowMultipleSelections()) {
                    clone.setSelectedIndexes(originalChoiceCallback.getSelectedIndexes());
                } else {
                    clone.setSelectedIndex(originalChoiceCallback.getSelectedIndexes()[0]);
                }
            }
            copy[i] = clone;
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is ChoiceCallback");
            }
        } else if (original[i] instanceof ConfirmationCallback) {
            ConfirmationCallback temp = (ConfirmationCallback) original[i];
            String prompt = temp.getPrompt();
            String[] options = temp.getOptions();
            if (prompt == null) {
                // no prompt
                if (options == null) {
                    // no options
                    copy[i] = new ConfirmationCallback(temp.getMessageType(), temp.getOptionType(), temp.getDefaultOption());
                } else {
                    copy[i] = new ConfirmationCallback(temp.getMessageType(), options, temp.getDefaultOption());
                }
            } else {
                // has prompt
                if (options == null) {
                    // no options
                    copy[i] = new ConfirmationCallback(prompt, temp.getMessageType(), temp.getOptionType(), temp.getDefaultOption());
                } else {
                    copy[i] = new ConfirmationCallback(prompt, temp.getMessageType(), options, temp.getDefaultOption());
                }
            }
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is ConfirmationCallback");
            }
        } else if (original[i] instanceof TextInputCallback) {
            copy[i] = new TextInputCallback(((TextInputCallback) original[i]).getPrompt());
            extCallbacks.add(copy[i]);
            if (debug.messageEnabled()) {
                debug.message("clone #" + i + " is TextInputCallback");
            }
        } else if (original[i] instanceof HttpCallback) {
            HttpCallback hc = (HttpCallback) original[i];
            copy[i] = new HttpCallback(hc.getAuthorizationHeader(), hc.getNegotiationHeaderName(), hc.getNegotiationHeaderValue(), hc.getNegotiationCode());
            extCallbacks.add(copy[i]);
        } else if (original[i] instanceof RedirectCallback) {
            RedirectCallback rc = (RedirectCallback) original[i];
            copy[i] = new RedirectCallback(rc.getRedirectUrl(), rc.getRedirectData(), rc.getMethod(), rc.getStatusParameter(), rc.getRedirectBackUrlCookieName());
            extCallbacks.add(copy[i]);
        } else {
            debug.error("unknown callback " + original[i]);
        }
    // more callbacks need to be handled here if ...
    }
    // construct external Callback[]
    Callback[] ext = new Callback[extCallbacks.size()];
    if (!extCallbacks.isEmpty()) {
        Iterator it = extCallbacks.iterator();
        int i = 0;
        while (it.hasNext()) {
            ext[i++] = (Callback) it.next();
        }
    }
    // set external/internal callbacks
    internal.set(index, copy);
    external.set(index, ext);
    return ext;
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ArrayList(java.util.ArrayList) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) SessionConstraint(com.iplanet.dpro.session.service.SessionConstraint) TextInputCallback(javax.security.auth.callback.TextInputCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) TextInputCallback(javax.security.auth.callback.TextInputCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) LoginStateCallback(com.sun.identity.authentication.service.LoginStateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) NameCallback(javax.security.auth.callback.NameCallback) Iterator(java.util.Iterator) PasswordCallback(javax.security.auth.callback.PasswordCallback) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with TextOutputCallback

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

the class AMModuleProperties method walk.

//walk the DOM tree and create the callback array
private void walk(Node node) {
    int type = node.getNodeType();
    String nodeName = node.getNodeName();
    debug.message("Callback type: " + nodeName);
    String tmp;
    Node sub;
    switch(type) {
        case Node.ELEMENT_NODE:
            {
                if (nodeName.equals("ModuleProperties")) {
                    moduleName = getAttribute(node, "moduleName");
                } else if (nodeName.equals("Callbacks")) {
                    p = 0;
                    String timeout = getAttribute(node, "timeout");
                    String template = getAttribute(node, "template");
                    if (template == null) {
                        template = "";
                    }
                    String image = getAttribute(node, "image");
                    if (image == null) {
                        image = "";
                    }
                    String header = getAttribute(node, "header");
                    boolean error = Boolean.valueOf(getAttribute(node, "error")).booleanValue();
                    int size = Integer.parseInt(getAttribute(node, "length")) + 1;
                    int t = 0;
                    if (timeout != null) {
                        t = Integer.parseInt(timeout);
                    }
                    order = getAttribute(node, "order");
                    callbacks = new Callback[size];
                    callbacks[p] = new PagePropertiesCallback(moduleName, header, image, t, template, error, order);
                    p++;
                    attribute = new ArrayList();
                    require = new ArrayList();
                    infoText = new ArrayList<String>();
                } else if (nodeName.equals("NameCallback")) {
                    sub = node.getFirstChild();
                    sub = sub.getNextSibling();
                    String prompt = sub.getFirstChild().getNodeValue();
                    String dftName = null;
                    sub = sub.getNextSibling().getNextSibling();
                    if (sub != null) {
                        sub = sub.getFirstChild();
                        dftName = sub.getNodeValue();
                        callbacks[p] = new NameCallback(prompt, dftName);
                    } else {
                        callbacks[p] = new NameCallback(prompt);
                    }
                    tmp = getAttribute(node, "isRequired");
                    if (tmp != null) {
                        if (tmp.equals("true")) {
                            require.add("true");
                        } else {
                            require.add("");
                        }
                    } else {
                        require.add("");
                    }
                    tmp = getAttribute(node, "attribute");
                    if (tmp != null) {
                        attribute.add(tmp);
                    } else {
                        attribute.add("");
                    }
                    tmp = getAttribute(node, "infoText");
                    if (tmp != null) {
                        infoText.add(tmp);
                    } else {
                        infoText.add("");
                    }
                    p++;
                } else if (nodeName.equals("HiddenValueCallback")) {
                    sub = node.getFirstChild();
                    sub = sub.getNextSibling();
                    String id = sub.getFirstChild().getNodeValue();
                    String dftName = null;
                    sub = sub.getNextSibling().getNextSibling();
                    if (sub != null) {
                        sub = sub.getFirstChild();
                        dftName = sub.getNodeValue();
                        callbacks[p] = new HiddenValueCallback(id, dftName);
                    } else {
                        callbacks[p] = new HiddenValueCallback(id);
                    }
                    tmp = getAttribute(node, "isRequired");
                    if (Boolean.parseBoolean(tmp)) {
                        require.add("true");
                    } else {
                        require.add("");
                    }
                    tmp = getAttribute(node, "attribute");
                    if (tmp != null) {
                        attribute.add(tmp);
                    } else {
                        attribute.add("");
                    }
                    tmp = getAttribute(node, "infoText");
                    if (tmp != null) {
                        infoText.add(tmp);
                    } else {
                        infoText.add("");
                    }
                    p++;
                } else if (nodeName.equals("PasswordCallback")) {
                    String echo = getAttribute(node, "echoPassword");
                    sub = node.getFirstChild();
                    sub = sub.getNextSibling().getFirstChild();
                    String prompt = sub.getNodeValue();
                    boolean b = Boolean.valueOf(echo).booleanValue();
                    callbacks[p] = new PasswordCallback(prompt, b);
                    tmp = getAttribute(node, "isRequired");
                    if (tmp != null) {
                        if (tmp.equals("true")) {
                            require.add("true");
                        } else {
                            require.add("");
                        }
                    } else {
                        require.add("");
                    }
                    tmp = getAttribute(node, "attribute");
                    if (tmp != null) {
                        attribute.add(tmp);
                    } else {
                        attribute.add("");
                    }
                    tmp = getAttribute(node, "infoText");
                    if (tmp != null) {
                        infoText.add(tmp);
                    } else {
                        infoText.add("");
                    }
                    p++;
                } else if (nodeName.equals("ChoiceCallback")) {
                    String multiple = getAttribute(node, "multipleSelectionsAllowed");
                    String prompt = null;
                    String[] choices = null;
                    int defaultChoice = 0;
                    boolean mch = Boolean.valueOf(multiple).booleanValue();
                    for (sub = node.getFirstChild(); sub != null; sub = sub.getNextSibling()) {
                        if (sub.getNodeName().equals("Prompt")) {
                            prompt = sub.getFirstChild().getNodeValue();
                        } else if (sub.getNodeName().equals("ChoiceValues")) {
                            int len = 0;
                            Node ss = sub.getFirstChild().getNextSibling();
                            for (Node count = ss; count != null; count = count.getNextSibling().getNextSibling()) {
                                len++;
                            }
                            choices = new String[len];
                            for (int i = 0; i < len; i++) {
                                choices[i] = ss.getFirstChild().getNextSibling().getFirstChild().getNodeValue();
                                if (Boolean.valueOf(getAttribute(ss, "isDefault")).booleanValue()) {
                                    defaultChoice = i;
                                }
                                ss = ss.getNextSibling().getNextSibling();
                            }
                            break;
                        }
                    }
                    callbacks[p] = new ChoiceCallback(prompt, choices, defaultChoice, mch);
                    tmp = getAttribute(node, "isRequired");
                    if (tmp != null) {
                        if (tmp.equals("true")) {
                            require.add("true");
                        } else {
                            require.add("");
                        }
                    } else {
                        require.add("");
                    }
                    tmp = getAttribute(node, "attribute");
                    if (tmp != null) {
                        attribute.add(tmp);
                    } else {
                        attribute.add("");
                    }
                    tmp = getAttribute(node, "infoText");
                    if (tmp != null) {
                        infoText.add(tmp);
                    } else {
                        infoText.add("");
                    }
                    p++;
                } else if (nodeName.equals("ConfirmationCallback")) {
                    int messageType = ConfirmationCallback.INFORMATION;
                    int defaultOption = 0;
                    String[] options = null;
                    for (sub = node.getFirstChild(); sub != null; sub = sub.getNextSibling()) {
                        if (sub.getNodeName().equals("OptionValues")) {
                            int len = 0;
                            Node ss = sub.getFirstChild().getNextSibling();
                            for (Node count = ss; count != null; count = count.getNextSibling().getNextSibling()) {
                                len++;
                            }
                            options = new String[len];
                            for (int i = 0; i < len; i++) {
                                options[i] = ss.getFirstChild().getNextSibling().getFirstChild().getNodeValue();
                                ss = ss.getNextSibling().getNextSibling();
                            }
                            break;
                        }
                    }
                    callbacks[p] = new ConfirmationCallback(messageType, options, defaultOption);
                    p++;
                } else if (nodeName.equals("TextInputCallback")) {
                    sub = node.getFirstChild();
                    sub = sub.getNextSibling().getFirstChild();
                    String prompt = sub.getNodeValue();
                    callbacks[p] = new TextInputCallback(prompt);
                    p++;
                } else if (nodeName.equals("TextOutputCallback")) {
                    int messageType = TextOutputCallback.ERROR;
                    String s = getAttribute(node, "messageType");
                    String value = node.getFirstChild().getNodeValue();
                    if (s.equals("script")) {
                        callbacks[p] = new ScriptTextOutputCallback(value);
                    } else {
                        if (s.equals("error")) {
                            messageType = TextOutputCallback.ERROR;
                        } else if (s.equals("warning")) {
                            messageType = TextOutputCallback.WARNING;
                        } else {
                            //default to information
                            messageType = TextOutputCallback.INFORMATION;
                        }
                        callbacks[p] = new TextOutputCallback(messageType, value);
                    }
                    p++;
                } else if (nodeName.equals("LanguageCallback")) {
                    for (sub = node.getFirstChild(); sub != null; sub = sub.getNextSibling()) {
                        if (sub.getNodeName().equals("ChoiceValue")) {
                            String isdefault = getAttribute(sub, "isDefault");
                        }
                    }
                    callbacks[p] = new LanguageCallback();
                    p++;
                } else if (nodeName.equals(AuthXMLTags.HTTP_CALLBACK)) {
                    String header = null;
                    String negotiation = null;
                    String code = null;
                    sub = node.getFirstChild();
                    for (; sub != null; sub = sub.getNextSibling()) {
                        String tmpStr = sub.getNodeName();
                        if (tmpStr.equals(AuthXMLTags.HTTP_HEADER)) {
                            header = sub.getFirstChild().getNodeValue();
                        } else if (tmpStr.equals(AuthXMLTags.HTTP_NEGO)) {
                            negotiation = sub.getFirstChild().getNodeValue();
                        } else if (tmpStr.equals(AuthXMLTags.HTTP_CODE)) {
                            code = sub.getFirstChild().getNodeValue();
                        }
                    }
                    callbacks[p] = new HttpCallback(header, negotiation, code);
                    p++;
                } else if (nodeName.equals(AuthXMLTags.REDIRECT_CALLBACK)) {
                    String redirectUrl = null;
                    String statusParameter = null;
                    String redirectBackUrlCookie = null;
                    Map redirectData = new HashMap();
                    String method = getAttribute(node, AuthXMLTags.REDIRECT_METHOD);
                    sub = node.getFirstChild();
                    for (; sub != null; sub = sub.getNextSibling()) {
                        String tmpStr = sub.getNodeName();
                        if (tmpStr.equals(AuthXMLTags.REDIRECT_URL)) {
                            redirectUrl = sub.getFirstChild().getNodeValue();
                        } else if (tmpStr.equals(AuthXMLTags.REDIRECT_STATUS_PARAM)) {
                            statusParameter = sub.getFirstChild().getNodeValue();
                        } else if (tmpStr.equals(AuthXMLTags.REDIRECT_BACK_URL_COOKIE)) {
                            redirectBackUrlCookie = sub.getFirstChild().getNodeValue();
                        } else if (tmpStr.equals(AuthXMLTags.REDIRECT_DATA)) {
                            String name = null;
                            String value = null;
                            Node ss = sub.getFirstChild().getNextSibling();
                            String tmpStrName = ss.getNodeName();
                            if (tmpStrName.equals("Name")) {
                                name = ss.getFirstChild().getNodeValue();
                            }
                            ss = ss.getNextSibling().getNextSibling();
                            String tmpStrValue = ss.getNodeName();
                            if (tmpStrValue.equals("Value")) {
                                value = ss.getFirstChild().getNodeValue();
                            }
                            redirectData.put(name, value);
                        }
                    }
                    if (debug.messageEnabled()) {
                        debug.message("redirectUrl : " + redirectUrl);
                        debug.message("statusParameter : " + statusParameter);
                        debug.message("redirectBackUrlCookie : " + redirectBackUrlCookie);
                        debug.message("redirectData : " + redirectData);
                        debug.message("method : " + method);
                    }
                    callbacks[p] = new RedirectCallback(redirectUrl, redirectData, method);
                    p++;
                }
                break;
            }
        //end of element
        default:
            break;
    }
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        walk(child);
    }
    //without this the ending tags will miss
    if (type == Node.ELEMENT_NODE) {
        if (nodeName.equals("Callbacks")) {
            ((PagePropertiesCallback) callbacks[0]).setAttribute(attribute);
            ((PagePropertiesCallback) callbacks[0]).setRequire(require);
            ((PagePropertiesCallback) callbacks[0]).setInfoText(infoText);
            rtable.put(order, callbacks);
        //attrtable.put(order, subAttr);
        //requiretable.put(order, subRequire);
        }
    }
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) HashMap(java.util.HashMap) HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) 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) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 13 with TextOutputCallback

use of javax.security.auth.callback.TextOutputCallback 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 14 with TextOutputCallback

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

the class RestAuthTextOutputCallbackHandlerTest method shouldFailToConvertFromJsonWithInvalidType.

@Test(expectedExceptions = RestAuthException.class)
public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException {
    //Given
    TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE");
    JsonValue jsonTextOutputCallback = JsonValueBuilder.jsonValue().array("output").add(JsonValueBuilder.jsonValue().put("value", "MESSAGE").build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "PasswordCallback").build();
    //When
    testOutputRestAuthCallbackHandler.convertFromJson(textOutputCallback, jsonTextOutputCallback);
    //Then
    fail();
}
Also used : JsonValue(org.forgerock.json.JsonValue) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Test(org.testng.annotations.Test)

Example 15 with TextOutputCallback

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

the class RestAuthTextOutputCallbackHandlerTest method shouldHandleCallback.

@Test
public void shouldHandleCallback() {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    JsonValue jsonPostBody = mock(JsonValue.class);
    TextOutputCallback originalTextOutputCallback = mock(TextOutputCallback.class);
    //When
    TextOutputCallback textOutputCallback = testOutputRestAuthCallbackHandler.handle(request, response, jsonPostBody, originalTextOutputCallback);
    //Then
    assertEquals(originalTextOutputCallback, textOutputCallback);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Test(org.testng.annotations.Test)

Aggregations

TextOutputCallback (javax.security.auth.callback.TextOutputCallback)18 NameCallback (javax.security.auth.callback.NameCallback)10 PasswordCallback (javax.security.auth.callback.PasswordCallback)10 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)7 Test (org.testng.annotations.Test)7 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)6 JsonValue (org.forgerock.json.JsonValue)6 Callback (javax.security.auth.callback.Callback)5 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)4 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)4 TextInputCallback (javax.security.auth.callback.TextInputCallback)4 LoginException (javax.security.auth.login.LoginException)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)3 ArrayList (java.util.ArrayList)3 LanguageCallback (javax.security.auth.callback.LanguageCallback)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 SessionConstraint (com.iplanet.dpro.session.service.SessionConstraint)1 LoginStateCallback (com.sun.identity.authentication.service.LoginStateCallback)1 DSAMECallbackInterface (com.sun.identity.authentication.spi.DSAMECallbackInterface)1