Search in sources :

Example 1 with DSAMECallbackInterface

use of com.sun.identity.authentication.spi.DSAMECallbackInterface in project OpenAM by OpenRock.

the class AuthXMLUtils method createCustomCallback.

static DSAMECallbackInterface createCustomCallback(Node childNode, Callback customCallback) {
    debug.message("in create custom callback");
    String className = XMLUtils.getNodeAttributeValue(childNode, AuthXMLTags.ATTRIBUTE_CLASS_NAME);
    try {
        DSAMECallbackInterface callback = null;
        if (customCallback != null) {
            if (customCallback instanceof DSAMECallbackInterface) {
                callback = (DSAMECallbackInterface) customCallback;
                if (callback != null) {
                    String clName = callback.getClass().getName();
                    if (debug.messageEnabled()) {
                        debug.message("Class Name is : " + clName);
                    }
                    if ((clName == null) || (!clName.equals(className))) {
                        callback = null;
                    }
                }
            }
        }
        if (callback == null) {
            if ((className != null) && (className.length() != 0)) {
                Class xmlClass = Class.forName(className);
                callback = (DSAMECallbackInterface) xmlClass.newInstance();
            }
        }
        HashMap map = new HashMap();
        String value = null;
        String attributeName = null;
        HashSet valueSet = null;
        // get the values
        NodeList childNodesList = childNode.getChildNodes();
        for (int i = 0; i < childNodesList.getLength(); i++) {
            Node cNode = childNodesList.item(i);
            NodeList childNodeIList = cNode.getChildNodes();
            for (int j = 0; j < childNodeIList.getLength(); j++) {
                Node childNodeI = childNodeIList.item(j);
                String localName = childNodeI.getLocalName();
                if (debug.messageEnabled()) {
                    debug.message("child node local name : " + localName);
                }
                if (localName.equals(AuthXMLTags.ATTRIBUTE)) {
                    attributeName = XMLUtils.getNodeAttributeValue(childNodeI, AuthXMLTags.ATTRIBUTE_NAME);
                }
                if (childNodeI.getLocalName().equals(AuthXMLTags.VALUE)) {
                    valueSet = new HashSet();
                    value = XMLUtils.getValueOfValueNode(childNodeI);
                    valueSet.add(value);
                }
            }
            map.put(attributeName, valueSet);
        }
        if (debug.messageEnabled()) {
            debug.message("MAP is : " + map);
        }
        callback.setConfig(map);
        return callback;
    } catch (Exception e) {
        debug.message("Error creating callback ", e);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException) DSAMECallbackInterface(com.sun.identity.authentication.spi.DSAMECallbackInterface) HashSet(java.util.HashSet)

Example 2 with DSAMECallbackInterface

use of com.sun.identity.authentication.spi.DSAMECallbackInterface 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)

Aggregations

DSAMECallbackInterface (com.sun.identity.authentication.spi.DSAMECallbackInterface)2 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)1 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)1 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)1 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)1 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)1 X509CertificateCallback (com.sun.identity.authentication.spi.X509CertificateCallback)1 IOException (java.io.IOException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 CertificateException (java.security.cert.CertificateException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)1 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)1 LanguageCallback (javax.security.auth.callback.LanguageCallback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 TextInputCallback (javax.security.auth.callback.TextInputCallback)1 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)1 Node (org.w3c.dom.Node)1