Search in sources :

Example 6 with LanguageCallback

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

the class RestAuthLanguageCallbackHandlerTest method shouldHandleCallback.

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

Example 7 with LanguageCallback

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

the class RestAuthLanguageCallbackHandlerTest method shouldConvertToJson.

@Test
public void shouldConvertToJson() throws RestAuthException {
    //Given
    LanguageCallback languageCallback = new LanguageCallback();
    languageCallback.setLocale(new Locale("LANGUAGE", "COUNTRY"));
    //When
    JsonValue jsonObject = restAuthLanguageCallbackHandler.convertToJson(languageCallback, 1);
    //Then
    assertEquals(2, jsonObject.size());
    assertEquals("LanguageCallback", jsonObject.get("type").asString());
    assertNotNull(jsonObject.get("input"));
    assertEquals(2, jsonObject.get("input").size());
    assertEquals("language", jsonObject.get("input").get(0).get("value").asString());
    assertEquals("COUNTRY", jsonObject.get("input").get(1).get("value").asString());
}
Also used : Locale(java.util.Locale) JsonValue(org.forgerock.json.JsonValue) LanguageCallback(javax.security.auth.callback.LanguageCallback) Test(org.testng.annotations.Test)

Example 8 with LanguageCallback

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

the class RestAuthLanguageCallbackHandlerTest method shouldNotFailToConvertFromJsonWithTypeLowerCase.

@Test
public void shouldNotFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException {
    //Given
    LanguageCallback languageCallback = new LanguageCallback();
    JsonValue jsonLanguageCallback = JsonValueBuilder.jsonValue().array("input").add(JsonValueBuilder.jsonValue().put("value", "lAngUage").build()).addLast(JsonValueBuilder.jsonValue().put("value", "COuntRY").build()).put("type", "lanGuagecalLback").build();
    //When
    LanguageCallback convertedLanguageCallback = restAuthLanguageCallbackHandler.convertFromJson(languageCallback, jsonLanguageCallback);
    //Then
    assertEquals(languageCallback, convertedLanguageCallback);
    Assert.assertNotNull(convertedLanguageCallback.getLocale());
    assertEquals("language", convertedLanguageCallback.getLocale().getLanguage());
    assertEquals("COUNTRY", convertedLanguageCallback.getLocale().getCountry());
}
Also used : JsonValue(org.forgerock.json.JsonValue) LanguageCallback(javax.security.auth.callback.LanguageCallback) Test(org.testng.annotations.Test)

Example 9 with LanguageCallback

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

the class RestAuthLanguageCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() throws RestAuthException {
    //Given
    LanguageCallback languageCallback = new LanguageCallback();
    JsonValue jsonLanguageCallback = JsonValueBuilder.jsonValue().array("input").add(JsonValueBuilder.jsonValue().put("value", "language").build()).addLast(JsonValueBuilder.jsonValue().put("value", "COUNTRY").build()).put("type", "LanguageCallback").build();
    //When
    LanguageCallback convertedLanguageCallback = restAuthLanguageCallbackHandler.convertFromJson(languageCallback, jsonLanguageCallback);
    //Then
    assertEquals(languageCallback, convertedLanguageCallback);
    Assert.assertNotNull(convertedLanguageCallback.getLocale());
    assertEquals("language", convertedLanguageCallback.getLocale().getLanguage());
    assertEquals("COUNTRY", convertedLanguageCallback.getLocale().getCountry());
}
Also used : JsonValue(org.forgerock.json.JsonValue) LanguageCallback(javax.security.auth.callback.LanguageCallback) Test(org.testng.annotations.Test)

Example 10 with LanguageCallback

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

Aggregations

LanguageCallback (javax.security.auth.callback.LanguageCallback)11 Test (org.testng.annotations.Test)7 JsonValue (org.forgerock.json.JsonValue)6 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)3 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)3 NameCallback (javax.security.auth.callback.NameCallback)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 TextInputCallback (javax.security.auth.callback.TextInputCallback)3 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)3 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)2 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Node (org.w3c.dom.Node)2 DSAMECallbackInterface (com.sun.identity.authentication.spi.DSAMECallbackInterface)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