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);
}
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);
}
}
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);
}
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);
}
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();
}
Aggregations