Search in sources :

Example 6 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 7 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 8 with TextOutputCallback

use of javax.security.auth.callback.TextOutputCallback in project apex-core by apache.

the class DefaultCallbackHandler method processCallback.

protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException {
    if (callback instanceof NameCallback) {
        NameCallback namecb = (NameCallback) callback;
        namecb.setName(context.getValue(SecurityContext.USER_NAME));
    } else if (callback instanceof PasswordCallback) {
        PasswordCallback passcb = (PasswordCallback) callback;
        passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
    } else if (callback instanceof RealmCallback) {
        RealmCallback realmcb = (RealmCallback) callback;
        realmcb.setText(context.getValue(SecurityContext.REALM));
    } else if (callback instanceof TextOutputCallback) {
        TextOutputCallback textcb = (TextOutputCallback) callback;
        if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
            logger.info(textcb.getMessage());
        } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
            logger.warn(textcb.getMessage());
        } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
            logger.error(textcb.getMessage());
        } else {
            logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
        }
    } else {
        throw new UnsupportedCallbackException(callback);
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RealmCallback(javax.security.sasl.RealmCallback)

Example 9 with TextOutputCallback

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

the class LDAPCallbacks method messageCallback.

private void messageCallback(int msgType, String msg) throws LoginException {
    if (callbackHandler == null) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    }
    try {
        Callback[] callbacks = new Callback[1];
        callbacks[0] = new TextOutputCallback(msgType, msg);
        callbackHandler.handle(callbacks);
    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    } catch (IllegalArgumentException ill) {
        debug.message("message type missing");
        throw new LoginException(bundle.getString("IllegalArgs"));
    }
}
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) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 10 with TextOutputCallback

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

the class LDAPCallbacks method loginCallbacks.

private void loginCallbacks() throws LoginException {
    if (callbackHandler == null) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    }
    Callback[] callbacks = new Callback[3];
    callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, "LDAP Authentication");
    callbacks[1] = new NameCallback("Enter Username :");
    callbacks[2] = new PasswordCallback("Enter Password :", false);
    try {
        callbackHandler.handle(callbacks);
        username = ((NameCallback) callbacks[1]).getName();
        passwd = charToString(((PasswordCallback) callbacks[2]).getPassword(), callbacks[2]);
    } catch (java.io.IOException ioe) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException();
    }
}
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) NameCallback(javax.security.auth.callback.NameCallback) 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)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