use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.
the class SearchResults method next.
/**
* Returns the next entry in the search results.
*
* @throws UMSException
* No more entries in the search results.
* @supported.api
*/
public PersistentObject next() throws UMSException {
// TODO: define detailed exception list (eg. referral, ...)
//
SearchResultEntry ldapEntry;
if (m_attrVals != null) {
if (m_attrIndex < m_attrVals.length) {
String dn = m_attrVals[m_attrIndex++];
PersistentObject pO = new PersistentObject();
pO.setGuid(new Guid(dn));
pO.setPrincipal(m_principal);
return pO;
} else {
throw new NoSuchElementException();
}
}
if ((ldapEntry = currentEntry) != null) {
String id = ldapEntry.getName().toString();
Collection<Attribute> attributes = new ArrayList<>();
for (Attribute attribute : ldapEntry.getAllAttributes()) {
attributes.add(attribute);
}
AttrSet attrSet = new AttrSet(attributes);
Class javaClass = TemplateManager.getTemplateManager().getJavaClassForEntry(id, attrSet);
PersistentObject pO = null;
try {
pO = (PersistentObject) javaClass.newInstance();
} catch (Exception e) {
String[] args = new String[1];
args[0] = e.toString();
String msg = i18n.getString(IUMSConstants.NEW_INSTANCE_FAILED, args);
throw new UMSException(msg);
}
// Make it a live object
pO.setAttrSet(attrSet);
pO.setGuid(new Guid(ldapEntry.getName().toString()));
pO.setPrincipal(m_principal);
return pO;
}
return null;
}
use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.
the class StaticGroup method getMembers.
/**
* Get members of the group.
*
* @param level
* Nesting level
* @return SearchResults for members of the group
* @exception Not
* thrown by this class
* @supported.api
*
*/
public SearchResults getMembers(int level) throws UMSException {
Attr attr = getAttribute(MEMBER_ATTR_NAME);
if (attr == null) {
return null;
}
if (level == LEVEL_ALL) {
level = getMaxNestingLevel();
}
if (level == LEVEL_DIRECT) {
return new SearchResults(getAttribute(MEMBER_ATTR_NAME));
}
Attr nestedMembers = new Attr(MEMBER_ATTR_NAME);
Attribute la = attr.toLDAPAttribute();
Iterator<ByteString> iterator = la.iterator();
while (iterator.hasNext()) {
String memberdn = iterator.next().toString();
PersistentObject entry = null;
try {
// entry = getUMSSession().getObject(new Guid(memberdn));
entry = UMSObject.getObject(getPrincipal(), new Guid(memberdn));
} catch (UMSException ignore) {
}
if (entry != null && entry instanceof StaticGroup) {
SearchResults r = ((StaticGroup) entry).getMembers(level - 1);
while (r.hasMoreElements()) {
PersistentObject member = null;
try {
member = r.next();
nestedMembers.addValue(member.getDN());
} catch (UMSException ignore) {
}
}
} else {
nestedMembers.addValue(memberdn);
}
entry = null;
}
return new SearchResults(nestedMembers);
}
use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.
the class SMSRepositoryMig method createSMSEntry.
private static void createSMSEntry(SMSFlatFileObject smsFlatFileObject, String dn, Iterable<Attribute> attrs) throws Exception {
// Convert attrs from LDAPAttributeSet to a Map needed by SMSObject.
Map<String, Set<String>> attrsMap = new HashMap<>();
for (Attribute attribute : attrs) {
String attrName = attribute.getAttributeDescriptionAsString();
Set<String> attrVals = new HashSet<>();
for (ByteString value : attribute) {
attrVals.add(value.toString());
}
attrsMap.put(attrName, attrVals);
}
try {
smsFlatFileObject.create(null, dn, attrsMap);
} catch (ServiceAlreadyExistsException e) {
System.out.println("Warning: '" + dn + "' already exists.");
}
}
use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.
the class LdapTokenAttributeConversionTest method shouldNotAddObjectClassIfPresent.
@Test
public void shouldNotAddObjectClassIfPresent() {
// Given
Entry entry = mock(Entry.class);
Attribute attribute = mock(Attribute.class);
given(entry.getAttribute(anyString())).willReturn(attribute);
// When
LdapTokenAttributeConversion.addObjectClass(entry);
// Then
verify(entry, times(0)).addAttribute(anyString(), any());
}
use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.
the class LdapTokenAttributeConversionTest method shouldHandleEmptyStrings.
@Test
public void shouldHandleEmptyStrings() {
// Given
Token token = new Token("id", TokenType.OAUTH);
token.setAttribute(CoreTokenField.STRING_ONE, "");
LdapTokenAttributeConversion conversion = generateTokenAttributeConversion();
// When
Entry result = conversion.getEntry(token);
// Then
Attribute attribute = result.getAttribute(CoreTokenField.STRING_ONE.toString());
assertNull(attribute);
}
Aggregations