Search in sources :

Example 1 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.

the class DeleteOnQueryResultHandlerTest method getHits.

private Collection<PartialToken> getHits(int count) throws Exception {
    List<PartialToken> tokens = new ArrayList<PartialToken>(count);
    for (int i = 0; i < count; i++) {
        PartialToken token = mock(PartialToken.class);
        given(token.getValue(CoreTokenField.TOKEN_ID)).willReturn(String.valueOf(i));
        tokens.add(token);
    }
    return tokens;
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList)

Example 2 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.

the class DeleteOnQueryResultHandlerTest method shouldInvokeDeleteForEachHit.

@Test
public void shouldInvokeDeleteForEachHit() throws Exception {
    Collection<PartialToken> hits = getHits(5);
    handler.processResults(hits);
    for (PartialToken hit : hits) {
        verify(mockTaskDispatcher).delete(eq(hit.<String>getValue(CoreTokenField.TOKEN_ID)), any(ResultHandler.class));
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ResultHandler(org.forgerock.openam.sm.datalayer.api.ResultHandler) Test(org.testng.annotations.Test)

Example 3 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken 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 4 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken 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)

Example 5 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken 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)

Aggregations

PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)13 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)5 TokenFilterBuilder (org.forgerock.openam.cts.api.filter.TokenFilterBuilder)5 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)5 CoreTokenField (org.forgerock.openam.tokens.CoreTokenField)4 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)2 SessionException (com.iplanet.dpro.session.SessionException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CTSPersistentStore (org.forgerock.openam.cts.CTSPersistentStore)1 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)1 TokenStrategyFailedException (org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)1 QueryBuilder (org.forgerock.openam.sm.datalayer.api.query.QueryBuilder)1 CTSTokenPersistenceException (org.forgerock.openam.sts.CTSTokenPersistenceException)1 STSIssuedTokenState (org.forgerock.openam.sts.user.invocation.STSIssuedTokenState)1 Connection (org.forgerock.opendj.ldap.Connection)1