Search in sources :

Example 16 with CoreTokenField

use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.

the class QueryBuilder method returnTheseAttributes.

/**
     * Limit the search to return only the named attributes.
     *
     * @param returnFields Collection of CoreTokenField that are required in the search results.
     * @return The QueryBuilder instance.
     * @throws IllegalArgumentException If the requested fields were null or empty.
     */
public QueryBuilder<C, F> returnTheseAttributes(Collection<CoreTokenField> returnFields) {
    Reject.ifTrue(returnFields == null || returnFields.isEmpty());
    Set<String> fields = new HashSet<String>();
    for (CoreTokenField field : returnFields) {
        fields.add(field.toString());
    }
    return setReturnAttributes(fields);
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) HashSet(java.util.HashSet)

Example 17 with CoreTokenField

use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.

the class TokenTest method shouldStoreInteger.

@Test
public void shouldStoreInteger() {
    // Given
    Integer value = new Integer(12345);
    CoreTokenField key = CoreTokenField.INTEGER_EIGHT;
    Token token = new Token("", TokenType.SESSION);
    // When
    token.setAttribute(key, value);
    // Then
    assertEquals(value, token.getValue(key));
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Test(org.testng.annotations.Test)

Example 18 with CoreTokenField

use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.

the class TokenTest method shouldStoreString.

@Test
public void shouldStoreString() {
    // Given
    CoreTokenField key = CoreTokenField.STRING_ONE;
    String value = "Badger";
    Token token = new Token("", TokenType.SESSION);
    // When
    token.setAttribute(key, value);
    // Then
    assertEquals(value, token.getValue(key));
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Test(org.testng.annotations.Test)

Example 19 with CoreTokenField

use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.

the class TokenTest method shouldReturnNotReturnAttributesForUnsetAttributes.

@Test
public void shouldReturnNotReturnAttributesForUnsetAttributes() {
    // Given
    Token token = new Token("ID", TokenType.SESSION);
    CoreTokenField field = CoreTokenField.STRING_ONE;
    // Set and clear an attribute
    token.setAttribute(field, "badger");
    token.clearAttribute(field);
    // When
    Collection<CoreTokenField> fields = token.getAttributeNames();
    // Then
    assertEquals(fields.size(), 2);
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Test(org.testng.annotations.Test)

Example 20 with CoreTokenField

use of org.forgerock.openam.tokens.CoreTokenField in project OpenAM by OpenRock.

the class TokenTest method shouldRespectReadOnlyField.

@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldRespectReadOnlyField() {
    // Given
    CoreTokenField key = CoreTokenField.TOKEN_ID;
    assertEquals(true, Token.isFieldReadOnly(key));
    Token token = new Token("", TokenType.SESSION);
    // When/Then
    token.setAttribute(key, "");
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Test(org.testng.annotations.Test)

Aggregations

CoreTokenField (org.forgerock.openam.tokens.CoreTokenField)33 Test (org.testng.annotations.Test)17 Calendar (java.util.Calendar)5 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 TokenFilterBuilder (org.forgerock.openam.cts.api.filter.TokenFilterBuilder)4 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)4 QueryFilter (org.forgerock.util.query.QueryFilter)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 JsonValue (org.forgerock.json.JsonValue)3 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)3 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)3 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)3 Token (org.forgerock.openam.cts.api.tokens.Token)3 BadRequestException (org.forgerock.json.resource.BadRequestException)2 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)2 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)2 QueryBuilder (org.forgerock.openam.sm.datalayer.api.query.QueryBuilder)2