Search in sources :

Example 6 with Attribute

use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.

the class UpgradeUtils method getExistingValues.

/**
     * Returns a set of valid attributes values for an attribute.
     *
     * @param subConfig the <code>ServiceConfig</code> object.
     * @param attrName the attribute name.
     * @param defaultVal set of attribute values to validate with the
     *    the existing attribute values.
     */
static Set getExistingValues(ServiceConfig subConfig, String attrName, Set defaultVal) {
    Set<String> valSet = new HashSet<>();
    String classMethod = "UpgradeUtils:getExistingValues : ";
    try (Connection conn = getLDAPConnection()) {
        if (conn != null) {
            String dn = subConfig.getDN();
            SearchResultEntry result = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn));
            if (result != null) {
                for (Attribute attribute : result.getAllAttributes()) {
                    String attributeName = attribute.getAttributeDescriptionAsString();
                    if (attributeName != null && ATTR_SUN_KEY_VALUE.equalsIgnoreCase(attributeName)) {
                        for (ByteString value : attribute) {
                            String valueString = value.toString();
                            int index = valueString.indexOf("=");
                            if (index != -1) {
                                String key = valueString.substring(0, index);
                                if (attributeName.equalsIgnoreCase(key)) {
                                    String v = valueString.substring(index + 1, valueString.length());
                                    if (defaultVal.contains(v)) {
                                        valSet.add(v);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        debug.error(classMethod + "Error retreving attribute values ", e);
    }
    if (debug.messageEnabled()) {
        debug.message(classMethod + "Default Values are :" + valSet);
    }
    return valSet;
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) HashSet(java.util.HashSet) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 7 with Attribute

use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.

the class OpenDJUpgrader method findBaseDNs.

private List<DN> findBaseDNs() throws IOException {
    final List<DN> baseDNs = new LinkedList<DN>();
    final SearchRequest request = LDAPRequests.newSearchRequest("cn=backends,cn=config", SearchScope.WHOLE_SUBTREE, "(objectclass=ds-cfg-backend)", "ds-cfg-base-dn");
    try (LDIFEntryReader reader = new LDIFEntryReader(new FileInputStream(installRoot + "/config/config.ldif"))) {
        final EntryReader filteredReader = LDIF.search(reader, request);
        while (filteredReader.hasNext()) {
            final Entry entry = filteredReader.readEntry();
            final Attribute values = entry.getAttribute("ds-cfg-base-dn");
            if (values != null) {
                for (final ByteString value : values) {
                    baseDNs.add(DN.valueOf(value.toString()));
                }
            }
        }
    }
    return baseDNs;
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) EntryReader(org.forgerock.opendj.ldif.EntryReader) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) ZipEntry(java.util.zip.ZipEntry) Entry(org.forgerock.opendj.ldap.Entry) LDIFEntryReader(org.forgerock.opendj.ldif.LDIFEntryReader) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) DN(org.forgerock.opendj.ldap.DN) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream)

Example 8 with Attribute

use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.

the class UserIdRepo method getADAMInstanceGUID.

private String getADAMInstanceGUID(Map userRepo) throws Exception {
    try (Connection ld = getLDAPConnection(userRepo)) {
        String attrName = "schemaNamingContext";
        ConnectionEntryReader res = ld.search(LDAPRequests.newSearchRequest("", SearchScope.BASE_OBJECT, "(objectclass=*)"));
        if (res.hasNext()) {
            SearchResultEntry entry = res.readEntry();
            Attribute ldapAttr = entry.getAttribute(attrName);
            if (ldapAttr != null) {
                String value = ldapAttr.firstValueAsString();
                int index = value.lastIndexOf("=");
                if (index != -1) {
                    return value.substring(index + 1).trim();
                }
            }
        }
    }
    return null;
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) Attribute(org.forgerock.opendj.ldap.Attribute) Connection(org.forgerock.opendj.ldap.Connection) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 9 with Attribute

use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.

the class EmbeddedOpenDS method getAdminPort.

/**
     * Get admin port of the OpenDJ server
     *
     * @param username The username of the directory admin
     * @param password The password of the directory admin
     * @param hostname The hostname of the directory server
     * @param port     The port of the directory server
     * @return The admin port
     */
public static String getAdminPort(String username, String password, String hostname, String port) {
    final String adminConnectorDN = "cn=Administration Connector,cn=config";
    final String[] attrs = { "ds-cfg-listen-port" };
    String adminPort = null;
    Connection ld = null;
    try (Connection conn = getLDAPConnection(hostname, port, username, password)) {
        if (conn != null) {
            SearchResultEntry le = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(adminConnectorDN, attrs));
            if (le != null) {
                Attribute la = le.getAttribute(attrs[0]);
                if (la != null) {
                    adminPort = la.firstValueAsString();
                }
            }
        }
    } catch (Exception ex) {
        Debug.getInstance(SetupConstants.DEBUG_NAME).error("EmbeddedOpenDS.getAdminPort(). Error getting admin port:", ex);
    }
    return adminPort;
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 10 with Attribute

use of org.forgerock.opendj.ldap.Attribute in project OpenAM by OpenRock.

the class EmbeddedOpenDS method getReplicationPort.

/**
     * Get replication port
     *
     * @param username
     * @param password
     * @param hostname
     * @param port
     * @return port number if replication is setup, null if not or on error.
     */
public static String getReplicationPort(String username, String password, String hostname, String port) {
    final String replDN = "cn=replication server,cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config";
    final String[] attrs = { "ds-cfg-replication-port" };
    String replPort = null;
    Connection ld = null;
    username = "cn=Directory Manager";
    try (Connection conn = getLDAPConnection(hostname, port, username, password)) {
        // We'll use Directory Manager
        if (conn != null) {
            SearchResultEntry le = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(replDN, attrs));
            if (le != null) {
                Attribute la = le.getAttribute(attrs[0]);
                if (la != null) {
                    replPort = la.firstValueAsString();
                }
            }
        }
    } catch (Exception ex) {
        Debug.getInstance(SetupConstants.DEBUG_NAME).error("EmbeddedOpenDS.getReplicationPort(). Error getting replication port:", ex);
    }
    return replPort;
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

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