Search in sources :

Example 96 with JsonValue

use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.

the class RestAuthNameCallbackHandlerTest method shouldConvertToJson.

@Test
public void shouldConvertToJson() throws RestAuthException {
    //Given
    NameCallback nameCallback = new NameCallback("Enter username:");
    //When
    JsonValue jsonObject = restAuthNameCallbackHandler.convertToJson(nameCallback, 1);
    //Then
    assertEquals("NameCallback", jsonObject.get("type").asString());
    assertNotNull(jsonObject.get("output"));
    Assert.assertEquals(1, jsonObject.get("output").size());
    Assert.assertEquals("Enter username:", jsonObject.get("output").get(0).get("value").asString());
    assertNotNull(jsonObject.get("input"));
    Assert.assertEquals(1, jsonObject.get("input").size());
    Assert.assertEquals("", jsonObject.get("input").get(0).get("value").asString());
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 97 with JsonValue

use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.

the class RestAuthNameCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() throws RestAuthException {
    //Given
    NameCallback nameCallback = new NameCallback("Enter username:");
    JsonValue jsonNameCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", "USERNAME").build()).array("output").addLast(JsonValueBuilder.jsonValue().put("value", "Enter username:").build()).put("type", "NameCallback").build();
    //When
    NameCallback convertedNameCallback = restAuthNameCallbackHandler.convertFromJson(nameCallback, jsonNameCallback);
    //Then
    Assert.assertEquals(nameCallback, convertedNameCallback);
    Assert.assertEquals("Enter username:", convertedNameCallback.getPrompt());
    Assert.assertEquals("USERNAME", convertedNameCallback.getName());
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 98 with JsonValue

use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.

the class RestAuthChoiceCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() throws RestAuthException {
    //Given
    ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "1", "34", "66", "93" }, 0, true);
    JsonValue jsonNameCallback = json(object(field("input", array(object(field("value", 1)))), field("output", array(object(field("value", "Select choice:")), object(field("value", array("1", "34", "66", "93"))), object(field("value", "0")))), field("type", "ChoiceCallback")));
    //When
    ChoiceCallback convertedChoiceCallback = restAuthChoiceCallbackHandler.convertFromJson(choiceCallback, jsonNameCallback);
    //Then
    assertEquals(choiceCallback, convertedChoiceCallback);
    assertEquals("Select choice:", convertedChoiceCallback.getPrompt());
    assertEquals(new String[] { "1", "34", "66", "93" }, convertedChoiceCallback.getChoices());
    assertEquals(0, convertedChoiceCallback.getDefaultChoice());
    assertEquals(new int[] { 1 }, convertedChoiceCallback.getSelectedIndexes());
}
Also used : ChoiceCallback(javax.security.auth.callback.ChoiceCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 99 with JsonValue

use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldConvertFromJson.

@Test
public void shouldConvertFromJson() throws RestAuthException {
    //Given
    ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
    JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "ConfirmationCallback").build();
    //When
    ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
    //Then
    assertEquals(confirmationCallback, convertedConfirmationCallback);
    assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt());
    assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType());
    assertEquals("OK", convertedConfirmationCallback.getOptions()[0]);
    assertEquals("NO", convertedConfirmationCallback.getOptions()[1]);
    assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]);
    assertEquals(-1, convertedConfirmationCallback.getOptionType());
    assertEquals(0, convertedConfirmationCallback.getDefaultOption());
    assertEquals(2, convertedConfirmationCallback.getSelectedIndex());
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 100 with JsonValue

use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandlerTest method shouldConvertToJson.

@Test
public void shouldConvertToJson() throws RestAuthException {
    //Given
    ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
    //When
    JsonValue jsonObject = restAuthConfirmationCallbackHandler.convertToJson(confirmationCallback, 1);
    //Then
    assertEquals("ConfirmationCallback", jsonObject.get("type").asString());
    assertNotNull(jsonObject.get("output"));
    assertEquals(5, jsonObject.get("output").size());
    assertEquals("Select confirmation:", jsonObject.get("output").get(0).get("value").asString());
    assertEquals(ConfirmationCallback.INFORMATION, (int) jsonObject.get("output").get(1).get("value").asInteger());
    assertEquals("OK", jsonObject.get("output").get(2).get("value").get(0).asString());
    assertEquals("NO", jsonObject.get("output").get(2).get("value").get(1).asString());
    assertEquals("CANCEL", jsonObject.get("output").get(2).get("value").get(2).asString());
    assertEquals(-1, (int) jsonObject.get("output").get(3).get("value").asInteger());
    assertEquals(0, (int) jsonObject.get("output").get(4).get("value").asInteger());
    assertNotNull(jsonObject.get("input"));
    assertEquals(1, jsonObject.get("input").size());
    assertEquals(0, (int) jsonObject.get("input").get(0).get("value").asInteger());
}
Also used : ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Aggregations

JsonValue (org.forgerock.json.JsonValue)575 Test (org.testng.annotations.Test)333 ResourceException (org.forgerock.json.resource.ResourceException)144 ResourceResponse (org.forgerock.json.resource.ResourceResponse)123 RealmContext (org.forgerock.openam.rest.RealmContext)70 Context (org.forgerock.services.context.Context)63 HashSet (java.util.HashSet)56 SSOException (com.iplanet.sso.SSOException)54 ArrayList (java.util.ArrayList)51 BadRequestException (org.forgerock.json.resource.BadRequestException)47 Privilege (com.sun.identity.entitlement.Privilege)46 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)46 SSOToken (com.iplanet.sso.SSOToken)43 SMSException (com.sun.identity.sm.SMSException)42 HashMap (java.util.HashMap)42 NotFoundException (org.forgerock.json.resource.NotFoundException)41 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)41 CreateRequest (org.forgerock.json.resource.CreateRequest)40 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 Subject (javax.security.auth.Subject)32