use of org.forgerock.opendj.ldap.AttributeDescription in project OpenAM by OpenRock.
the class LdapTokenAttributeConversionTest method shouldStripObjectClass.
@Test
public void shouldStripObjectClass() {
// Given
Entry entry = mock(Entry.class);
Attribute attribute = mock(Attribute.class);
given(entry.getAttribute(anyString())).willReturn(attribute);
AttributeDescription description = AttributeDescription.valueOf("badger");
given(attribute.getAttributeDescription()).willReturn(description);
// When
LdapTokenAttributeConversion.stripObjectClass(entry);
// Then
verify(entry).removeAttribute(description);
}
use of org.forgerock.opendj.ldap.AttributeDescription in project OpenAM by OpenRock.
the class LdapTokenAttributeConversion method stripObjectClass.
/**
* Only strips out the ObjectClass if it is present.
*
* @param entry Non null Entry to process.
*
* @return The Entry reference passed in.
*/
public static Entry stripObjectClass(Entry entry) {
Attribute attribute = entry.getAttribute(CoreTokenConstants.OBJECT_CLASS);
if (attribute != null) {
AttributeDescription description = attribute.getAttributeDescription();
entry.removeAttribute(description);
}
return entry;
}
use of org.forgerock.opendj.ldap.AttributeDescription in project OpenAM by OpenRock.
the class LdapTokenAttributeConversion method mapFromEntry.
/**
* Convert an Entry into a more convenient Mapping of CoreTokenField to Object.
*
* This function is important because no every operation with LDAP needs to return a
* fully initialised Token. Instead users may be interested in only certain
* attributes of the Token, and choose to query just those as a performance enhancement.
*
* @param entry Non null entry to convert.
*
* @return A mapping of zero or more CoreTokenFields to Objects.
*/
public Map<CoreTokenField, Object> mapFromEntry(Entry entry) {
stripObjectClass(entry);
Map<CoreTokenField, Object> r = new LinkedHashMap<>();
for (Attribute a : entry.getAllAttributes()) {
AttributeDescription description = a.getAttributeDescription();
CoreTokenField field = CoreTokenField.fromLDAPAttribute(description.toString());
// Special case for Token Type
if (CoreTokenField.TOKEN_TYPE.equals(field)) {
String value = entry.parseAttribute(description).asString();
r.put(field, TokenType.valueOf(value));
continue;
}
if (CoreTokenFieldTypes.isCalendar(field)) {
String dateString = entry.parseAttribute(description).asString();
Calendar calendar = conversion.fromLDAPDate(dateString);
r.put(field, calendar);
} else if (CoreTokenFieldTypes.isString(field)) {
String value = entry.parseAttribute(description).asString();
if (EMPTY.equals(value)) {
value = "";
}
r.put(field, value);
} else if (CoreTokenFieldTypes.isInteger(field)) {
Integer value = entry.parseAttribute(description).asInteger();
r.put(field, value);
} else if (CoreTokenFieldTypes.isByteArray(field)) {
byte[] data = entry.parseAttribute(description).asByteString().toByteArray();
r.put(field, data);
} else {
throw new IllegalStateException();
}
}
return r;
}
Aggregations