Search in sources :

Example 6 with CoreTokenField

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

the class CoreTokenFieldTest method shouldConvertFromStringToCoreTokenField.

@Test
public void shouldConvertFromStringToCoreTokenField() {
    // Given
    CoreTokenField field = CoreTokenField.EXPIRY_DATE;
    String key = field.toString();
    // When
    CoreTokenField result = CoreTokenField.fromLDAPAttribute(key);
    // Then
    assertEquals(result, field);
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Test(org.testng.annotations.Test)

Example 7 with CoreTokenField

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

the class CTSPersistentStoreImpl method delete.

@Override
public int delete(Map<CoreTokenField, Object> query) throws DeleteFailedException {
    TokenFilterBuilder.FilterAttributeBuilder builder = new TokenFilterBuilder().returnAttribute(CoreTokenField.TOKEN_ID).and();
    for (Map.Entry<CoreTokenField, Object> entry : query.entrySet()) {
        CoreTokenField key = entry.getKey();
        Object value = entry.getValue();
        builder = builder.withAttribute(key, value);
    }
    TokenFilter filter = builder.build();
    Collection<String> failures = new ArrayList<String>();
    try {
        Collection<PartialToken> partialTokens = attributeQuery(filter);
        debug("Found {0} partial Tokens for deletion", Integer.toString(partialTokens.size()));
        for (PartialToken token : partialTokens) {
            String tokenId = token.getValue(CoreTokenField.TOKEN_ID);
            try {
                delete(tokenId);
            } catch (CoreTokenException e) {
                failures.add(tokenId);
            }
        }
        if (!failures.isEmpty()) {
            error("Failed to delete {0} tokens.\n{1}", Integer.toString(failures.size()), StringUtils.join(failures, ","));
        }
        return partialTokens.size() - failures.size();
    } catch (CoreTokenException e) {
        throw new DeleteFailedException("Failed to delete Tokens", e);
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) DeleteFailedException(org.forgerock.openam.cts.exceptions.DeleteFailedException) TokenFilterBuilder(org.forgerock.openam.cts.api.filter.TokenFilterBuilder) Map(java.util.Map) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter)

Example 8 with CoreTokenField

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

the class Token method getAttributeNames.

/**
     * The Token supports being accessed in a generic way allowing a caller to iterate
     * over all fields that are assigned in this token.
     *
     * @return A non null, non modifiable list of the CoreTokenField fields currently assigned.
     */
public Collection<CoreTokenField> getAttributeNames() {
    Set<CoreTokenField> fields = new HashSet<CoreTokenField>();
    for (Map.Entry<String, Object> entry : attributes.entrySet()) {
        CoreTokenField field = CoreTokenField.fromLDAPAttribute(entry.getKey());
        if (entry.getValue() == null) {
            continue;
        }
        fields.add(field);
    }
    return Collections.unmodifiableSet(fields);
}
Also used : CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with CoreTokenField

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

the class PartialTokenTest method shouldContainNewFieldInCopyConstructor.

@Test
public void shouldContainNewFieldInCopyConstructor() {
    // Given
    String id = "badger";
    CoreTokenField field = CoreTokenField.TOKEN_ID;
    PartialToken first = new PartialToken(Collections.<CoreTokenField, Object>emptyMap());
    // When
    PartialToken clone = new PartialToken(first, field, id);
    // Then
    assertThat(clone.<String>getValue(field)).isEqualTo(id);
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) Test(org.testng.annotations.Test)

Example 10 with CoreTokenField

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

the class PartialTokenTest method shouldSupportEmptyCollectionOfFields.

@Test
public void shouldSupportEmptyCollectionOfFields() {
    Map<CoreTokenField, Object> empty = Collections.emptyMap();
    assertThat(new PartialToken(empty).getFields()).isEmpty();
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) 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