Search in sources :

Example 26 with Attribute

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;
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ArrayList(java.util.ArrayList) NoSuchElementException(java.util.NoSuchElementException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchElementException(java.util.NoSuchElementException) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 27 with Attribute

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);
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) Attr(com.iplanet.services.ldap.Attr)

Example 28 with Attribute

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.");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ByteString(org.forgerock.opendj.ldap.ByteString) HashSet(java.util.HashSet) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException)

Example 29 with Attribute

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());
}
Also used : LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) Attribute(org.forgerock.opendj.ldap.Attribute) Test(org.testng.annotations.Test)

Example 30 with Attribute

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);
}
Also used : LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) Attribute(org.forgerock.opendj.ldap.Attribute) Token(org.forgerock.openam.cts.api.tokens.Token) Test(org.testng.annotations.Test)

Aggregations

Attribute (org.forgerock.opendj.ldap.Attribute)48 ByteString (org.forgerock.opendj.ldap.ByteString)35 LdapException (org.forgerock.opendj.ldap.LdapException)30 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)28 Connection (org.forgerock.opendj.ldap.Connection)25 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)16 HashSet (java.util.HashSet)14 IOException (java.io.IOException)13 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)11 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)10 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)9 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)8 FileNotFoundException (java.io.FileNotFoundException)6 ArrayList (java.util.ArrayList)6 LinkedHashSet (java.util.LinkedHashSet)6 Set (java.util.Set)6 Modification (org.forgerock.opendj.ldap.Modification)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)5