Search in sources :

Example 21 with ConfirmationCallback

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

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

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

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

the class AuthXMLUtils method createConfirmationCallback.

static ConfirmationCallback createConfirmationCallback(Node childNode, Callback callback) {
    ConfirmationCallback conCallback = null;
    if (callback != null) {
        if (callback instanceof ConfirmationCallback) {
            conCallback = (ConfirmationCallback) callback;
        }
    }
    if (conCallback == null) {
        String prompt = getPrompt(childNode);
        int messageType = 0;
        String msgType = XMLUtils.getNodeAttributeValue(childNode, AuthXMLTags.MESSAGE_TYPE);
        if (msgType.equals("information")) {
            messageType = ConfirmationCallback.INFORMATION;
        } else if (msgType.equals("error")) {
            messageType = ConfirmationCallback.ERROR;
        } else if (msgType.equals("warning")) {
            messageType = ConfirmationCallback.WARNING;
        }
        boolean bOptions = false;
        int optionType = 0;
        String optType = XMLUtils.getNodeAttributeValue(childNode, AuthXMLTags.OPTION_TYPE);
        if (optType != null) {
            if (optType.equals("yes_no")) {
                optionType = ConfirmationCallback.YES_NO_OPTION;
            } else if (optType.equals("yes_no_cancel")) {
                optionType = ConfirmationCallback.YES_NO_CANCEL_OPTION;
            } else if (optType.equals("ok_cancel")) {
                optionType = ConfirmationCallback.OK_CANCEL_OPTION;
            } else if (optType.equals("unspecified")) {
                optionType = ConfirmationCallback.UNSPECIFIED_OPTION;
                bOptions = true;
            }
        }
        String[] options = null;
        Node optionsNode = XMLUtils.getChildNode(childNode, AuthXMLTags.OPTION_VALUES);
        if (optionsNode != null) {
            NodeList optionsChildNodes = optionsNode.getChildNodes();
            options = new String[optionsChildNodes.getLength()];
            for (int j = 0; j < optionsChildNodes.getLength(); j++) {
                Node optionValueNode = optionsChildNodes.item(j);
                String optionValue = getValue(optionValueNode);
                options[j] = optionValue;
            }
        }
        Node defaultNode = XMLUtils.getChildNode(childNode, AuthXMLTags.DEFAULT_OPTION_VALUE);
        String defaultValue = getValue(defaultNode);
        int defaultOption = Integer.parseInt(defaultValue);
        if (prompt != null) {
            if (bOptions) {
                conCallback = new ConfirmationCallback(prompt, messageType, options, defaultOption);
            } else {
                conCallback = new ConfirmationCallback(prompt, messageType, optionType, defaultOption);
            }
        } else {
            if (bOptions) {
                conCallback = new ConfirmationCallback(messageType, options, defaultOption);
            } else {
                conCallback = new ConfirmationCallback(messageType, optionType, defaultOption);
            }
        }
    }
    Node selectedNode = XMLUtils.getChildNode(childNode, AuthXMLTags.SELECTED_VALUE);
    if (selectedNode != null) {
        String selectedValue = getValue(selectedNode);
        int selectedOption = Integer.parseInt(selectedValue);
        conCallback.setSelectedIndex(selectedOption);
    }
    return conCallback;
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Example 25 with ConfirmationCallback

use of javax.security.auth.callback.ConfirmationCallback 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

ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)29 NameCallback (javax.security.auth.callback.NameCallback)18 PasswordCallback (javax.security.auth.callback.PasswordCallback)18 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)14 Callback (javax.security.auth.callback.Callback)13 Test (org.testng.annotations.Test)13 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)7 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)6 JsonValue (org.forgerock.json.JsonValue)6 DevicePrint (org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)6 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)5 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)5 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 TextInputCallback (javax.security.auth.callback.TextInputCallback)4 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)3 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)3 LanguageCallback (javax.security.auth.callback.LanguageCallback)3