Search in sources :

Example 1 with TextOutputCallback

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

the class RestAuthTextOutputCallbackHandlerTest method shouldNotUpdateCallbackFromRequest.

@Test
public void shouldNotUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    TextOutputCallback textOutputCallback = mock(TextOutputCallback.class);
    //When
    boolean updated = testOutputRestAuthCallbackHandler.updateCallbackFromRequest(request, response, textOutputCallback);
    //Then
    assertTrue(!updated);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Test(org.testng.annotations.Test)

Example 2 with TextOutputCallback

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

the class RestAuthTextOutputCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() 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", "TextOutputCallback").build();
    //When
    TextOutputCallback convertedTextOutputCallback = testOutputRestAuthCallbackHandler.convertFromJson(textOutputCallback, jsonTextOutputCallback);
    //Then
    assertEquals(textOutputCallback, convertedTextOutputCallback);
    assertEquals("MESSAGE", convertedTextOutputCallback.getMessage());
    assertEquals(TextOutputCallback.INFORMATION, convertedTextOutputCallback.getMessageType());
}
Also used : JsonValue(org.forgerock.json.JsonValue) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Test(org.testng.annotations.Test)

Example 3 with TextOutputCallback

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

the class RestAuthTextOutputCallbackHandlerTest method shouldFailToConvertFromJsonWithTypeLowerCase.

@Test
public void shouldFailToConvertFromJsonWithTypeLowerCase() 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", "tExtoUtputcallback").build();
    //When
    TextOutputCallback convertedTextOutputCallback = testOutputRestAuthCallbackHandler.convertFromJson(textOutputCallback, jsonTextOutputCallback);
    //Then
    assertEquals(textOutputCallback, convertedTextOutputCallback);
    assertEquals("MESSAGE", convertedTextOutputCallback.getMessage());
    assertEquals(TextOutputCallback.INFORMATION, convertedTextOutputCallback.getMessageType());
}
Also used : JsonValue(org.forgerock.json.JsonValue) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Test(org.testng.annotations.Test)

Example 4 with TextOutputCallback

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

the class RestAuthTextOutputCallbackHandlerTest method shouldConvertToJsonAndEscapeCharacters.

@Test
public void shouldConvertToJsonAndEscapeCharacters() throws RestAuthException, JSONException {
    //Given
    final String script = "for (var i = 0; i < 10; i++) { alert(\"alert\"); }";
    TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, script);
    //When
    JsonValue jsonObject = testOutputRestAuthCallbackHandler.convertToJson(textOutputCallback, 1);
    //Then
    assertEquals("TextOutputCallback", jsonObject.get("type").asString());
    assertNotNull(jsonObject.get("output"));
    assertEquals(2, jsonObject.get("output").size());
    assertEquals(script, jsonObject.get("output").get(0).get("value").asString());
    assertEquals(TextOutputCallback.INFORMATION, Integer.parseInt(jsonObject.get("output").get(1).get("value").asString()));
    assertEquals(2, jsonObject.size());
    // Round-trip via toString/parsing with JSONObject to verify correct escaping
    JSONObject parsed = new JSONObject(jsonObject.toString());
    assertEquals(script, parsed.getJSONArray("output").getJSONObject(0).getString("value"));
}
Also used : JSONObject(org.json.JSONObject) JsonValue(org.forgerock.json.JsonValue) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Test(org.testng.annotations.Test)

Example 5 with TextOutputCallback

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

the class LDAPCallbacks method chgPwdCallback.

private void chgPwdCallback() throws LoginException {
    char[] pwd = null;
    if (callbackHandler == null) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    }
    Callback[] callbacks = new Callback[4];
    callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, "Change Password");
    callbacks[1] = new PasswordCallback("EnterOld Password", false);
    callbacks[2] = new PasswordCallback("Enter New Password", false);
    callbacks[3] = new PasswordCallback("Confirm Password", false);
    try {
        callbackHandler.handle(callbacks);
        oldPassword = charToString(((PasswordCallback) callbacks[1]).getPassword(), callbacks[1]);
        newPassword = charToString(((PasswordCallback) callbacks[2]).getPassword(), callbacks[2]);
        confirmPassword = charToString(((PasswordCallback) callbacks[3]).getPassword(), callbacks[3]);
    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Callback(javax.security.auth.callback.Callback) LoginException(javax.security.auth.login.LoginException) PasswordCallback(javax.security.auth.callback.PasswordCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Aggregations

TextOutputCallback (javax.security.auth.callback.TextOutputCallback)21 NameCallback (javax.security.auth.callback.NameCallback)13 PasswordCallback (javax.security.auth.callback.PasswordCallback)13 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Callback (javax.security.auth.callback.Callback)7 Test (org.testng.annotations.Test)7 JsonValue (org.forgerock.json.JsonValue)6 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)5 TextInputCallback (javax.security.auth.callback.TextInputCallback)5 LoginException (javax.security.auth.login.LoginException)5 ScriptTextOutputCallback (com.sun.identity.authentication.callbacks.ScriptTextOutputCallback)4 LanguageCallback (javax.security.auth.callback.LanguageCallback)4 HiddenValueCallback (com.sun.identity.authentication.callbacks.HiddenValueCallback)3 ArrayList (java.util.ArrayList)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