Search in sources :

Example 1 with SMSFlatFileObject

use of com.sun.identity.sm.flatfile.SMSFlatFileObject in project OpenAM by OpenRock.

the class SMSRepositoryMig method migrate.

private static void migrate(ConnectionFactory factory, String host, int port, String binddn, String pw, String basedn, String flatfiledir) throws Exception {
    // check args
    if (port < 0 || binddn == null || binddn.length() == 0 || pw == null || pw.length() == 0 || basedn == null || basedn.length() == 0 || flatfiledir == null || flatfiledir.length() == 0) {
        throw new IllegalArgumentException("SMSRepositoryMig: One or more invalid " + "arguments in constructor");
    }
    // Create the SMSFlatFileObject
    SMSFlatFileObject smsFlatFileObject = new SMSFlatFileObject();
    try (Connection conn = factory.getConnection()) {
        // Loop through LDAP attributes, create SMS object for each.
        ConnectionEntryReader res = conn.search(LDAPRequests.newSearchRequest("ou=services," + basedn, SearchScope.BASE_OBJECT, "(objectclass=*)", "*"));
        while (res.hasNext()) {
            if (res.isReference()) {
                //ignore
                res.readReference();
                System.out.println("ERROR: LDAP Referral not supported.");
                System.out.println("LDAPReferralException received");
            } else {
                SearchResultEntry entry;
                try {
                    entry = res.readEntry();
                    createSMSEntry(smsFlatFileObject, entry.getName().toString(), entry.getAllAttributes());
                } catch (LdapException e) {
                    System.out.println("ERROR: LDAP Exception encountered: " + e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException) SMSFlatFileObject(com.sun.identity.sm.flatfile.SMSFlatFileObject) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Aggregations

SMSFlatFileObject (com.sun.identity.sm.flatfile.SMSFlatFileObject)1 Connection (org.forgerock.opendj.ldap.Connection)1 LdapException (org.forgerock.opendj.ldap.LdapException)1 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)1 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)1