Search in sources :

Example 16 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class SAMLAdapterTest method shouldNotStoreSecondaryKeyIfNull.

@Test
public void shouldNotStoreSecondaryKeyIfNull() {
    // Given
    SAMLToken samlToken = new SAMLToken("primary", null, 12345, "");
    given(tokenIdFactory.toSAMLPrimaryTokenId(anyString())).willReturn("id");
    given(serialisation.serialise(anyObject())).willReturn("");
    // When
    Token token = adapter.toToken(samlToken);
    // Then
    assertThat(token.<String>getValue(SAMLTokenField.SECONDARY_KEY.getField())).isNull();
}
Also used : SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) Token(org.forgerock.openam.cts.api.tokens.Token) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) Test(org.testng.annotations.Test)

Example 17 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class SessionAdapterTest method shouldFilterLatestAccessTime.

@Test
public void shouldFilterLatestAccessTime() throws CoreTokenException {
    // Given
    Token token = new Token("badger", TokenType.SESSION);
    String latestAccessTime = "\"latestAccessTime\":1376308558,";
    String someJSONLikeText = "{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true," + latestAccessTime + "\"maxCachingTime\":3}";
    token.setBlob(someJSONLikeText.getBytes());
    TokenBlobUtils utils = new TokenBlobUtils();
    // When
    adapter.filterLatestAccessTime(token);
    // Then
    String contents = utils.getBlobAsString(token);
    // Present in the original json text.
    assertTrue(someJSONLikeText.contains(latestAccessTime));
    // Removed in the treated json text.
    assertFalse(contents.contains(latestAccessTime));
}
Also used : Token(org.forgerock.openam.cts.api.tokens.Token) TokenBlobUtils(org.forgerock.openam.cts.utils.blob.TokenBlobUtils) Test(org.testng.annotations.Test)

Example 18 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class JavaBeanAdapterTest method wrongTokenTypeFails.

@Test(expectedExceptions = IllegalArgumentException.class)
public void wrongTokenTypeFails() throws Exception {
    // Given
    Token token = new Token("abc123", TokenType.REST);
    // When
    adapter.fromToken(token);
// Then exception
}
Also used : Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Example 19 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class OAuthAdapterTest method shouldDeserialiseSerialisedToken.

@Test
public void shouldDeserialiseSerialisedToken() {
    // Given
    String[] id = { "badger" };
    List<String> list = new ArrayList<String>(Arrays.asList(id));
    OAuthTokenField field = OAuthTokenField.ID;
    JSONSerialisation serialisation = new JSONSerialisation(new ObjectMapper());
    OAuthAdapter adapter = generateOAuthAdapter();
    // Populate a map for serialisation.
    Map<String, Object> values = new HashMap<String, Object>();
    values.put(field.getOAuthField(), list);
    //Map<String, Object> map = new HashMap<String, Object>();
    //map.put(OAuthAdapter.VALUE, values);
    String serialisedObject = serialisation.serialise(values);
    Token token = new Token(id[0], TokenType.OAUTH);
    // Set the serialised binary data
    token.setBlob(serialisedObject.getBytes());
    // When
    JsonValue result = adapter.fromToken(token);
    // Then
    assertNotNull(result);
    assert (result.asMap().get(field.getOAuthField()).toString().contains(id[0]));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) Token(org.forgerock.openam.cts.api.tokens.Token) OAuthTokenField(org.forgerock.openam.cts.api.fields.OAuthTokenField) JSONSerialisation(org.forgerock.openam.cts.utils.JSONSerialisation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 20 with Token

use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.

the class OAuthAdapterTest method shouldSerialiseSimpleString.

@Test
public void shouldSerialiseSimpleString() {
    // Given
    OAuthAdapter adapter = generateOAuthAdapter();
    Set<String> text = new HashSet<String>();
    text.add("badger");
    OAuthTokenField field = OAuthTokenField.PARENT;
    Map<String, Object> values = new HashMap<String, Object>();
    values.put(field.getOAuthField(), text);
    JsonValue jsonValue = makeDefaultJsonValue(values);
    // When
    Token result = adapter.toToken(jsonValue);
    // Then
    assert (result.getValue(field.getField()).toString().contains("badger"));
}
Also used : OAuthTokenField(org.forgerock.openam.cts.api.fields.OAuthTokenField) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) Token(org.forgerock.openam.cts.api.tokens.Token) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Token (org.forgerock.openam.cts.api.tokens.Token)86 Test (org.testng.annotations.Test)58 Task (org.forgerock.openam.sm.datalayer.api.Task)17 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)16 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)16 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)13 InternalSession (com.iplanet.dpro.session.service.InternalSession)8 DataLayerException (org.forgerock.openam.sm.datalayer.api.DataLayerException)8 Calendar (java.util.Calendar)7 JsonValue (org.forgerock.json.JsonValue)7 SessionID (com.iplanet.dpro.session.SessionID)6 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)6 Collection (java.util.Collection)5 HashMap (java.util.HashMap)5 Entry (org.forgerock.opendj.ldap.Entry)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 SAMLToken (org.forgerock.openam.cts.api.tokens.SAMLToken)4 Connection (org.forgerock.opendj.ldap.Connection)4 LinkedHashMapEntry (org.forgerock.opendj.ldap.LinkedHashMapEntry)4