Search in sources :

Example 36 with LdapException

use of org.forgerock.opendj.ldap.LdapException 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)

Example 37 with LdapException

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

the class SearchResultIterator method hasNext.

public boolean hasNext() {
    try {
        if (results.hasNext()) {
            if (current == null) {
                if (results.isReference()) {
                    debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
                    return hasNext();
                }
                SearchResultEntry entry = results.readEntry();
                String dn = entry.getName().toString();
                if (hasExcludeDNs && excludeDNs.contains(dn)) {
                    return hasNext();
                }
                current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
            }
            return true;
        }
    } catch (LdapException e) {
        ResultCode errorCode = e.getResult().getResultCode();
        if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
            debug.message("SearchResultIterator: size limit exceeded");
        } else {
            debug.error("SearchResultIterator.hasNext", e);
        }
    } catch (SearchResultReferenceIOException e) {
        debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
        return hasNext();
    }
    conn.close();
    return false;
}
Also used : SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 38 with LdapException

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

the class COSManager method removeDirectCOSAssignment.

/**
     * Removes a Direct COS assignment from a target persistent object. The COS
     * target persistent object could be a user, group, organization,
     * organizationalunit, etc. The COS target object must be persistent before
     * this method can be used.
     * 
     * @param pObject
     *            The COS target persistent object.
     * @param cosDef
     *            A COS definition.
     * @param sMgr
     *            A SchemaManager object, which is used to determine object
     *            classes for attributes.
     * 
     * @throws UMSException
     *             The exception thrown if any of the following occur: o an
     *             exception occurs determining the object class for the COS
     *             specifier. o an exception occurs determining the object class
     *             for the COS attributes. o there is an exception thrown rom
     *             the data layer.
     */
private void removeDirectCOSAssignment(PersistentObject pObject, DirectCOSDefinition cosDef, COSTemplate cosTemplate, SchemaManager sMgr) throws UMSException {
    ArrayList aList;
    AttrSet attrSet = new AttrSet();
    try {
        //
        if (pObject.getAttribute(cosDef.getCOSSpecifier()) != null)
            attrSet.add(new Attr(cosDef.getCOSSpecifier(), cosTemplate.getName()));
        // Get cosSpecifier object class - should only be one.
        // Include the cosSpecifier object class in the attribute
        // set for removal (only if itt exists).
        //
        aList = (ArrayList) sMgr.getObjectClasses(cosDef.getCOSSpecifier());
        String cosSpecObjectClass = (String) aList.get(0);
        if (objectClassExists(cosSpecObjectClass, pObject)) {
            attrSet.add(new Attr("objectclass", cosSpecObjectClass));
        }
        // Get the cos attributes from the definition (ex. mailquota).
        // For each of the attributes, get the objectclass. Include the
        // object classes in the attribute set for removal (if they exist).
        //
        String[] cosAttributes = cosDef.getCOSAttributes();
        String cosAttribute = null;
        for (int i = 0; i < cosAttributes.length; i++) {
            // Only get the attribute - not the qualifier
            //
            StringTokenizer st = new StringTokenizer(cosAttributes[i]);
            cosAttribute = st.nextToken();
            aList = (ArrayList) sMgr.getObjectClasses(cosAttribute);
            String cosAttributeObjectClass = (String) aList.get(0);
            if (objectClassExists(cosAttributeObjectClass, pObject)) {
                attrSet.add(new Attr("objectclass", cosAttributeObjectClass));
            }
        }
        if (attrSet.size() > 0) {
            pObject.modify(toModifications(ModificationType.DELETE, attrSet));
            pObject.save();
        }
    } catch (UMSException e) {
        LdapException le = (LdapException) e.getRootCause();
        // Ignore anything that is not a COS generated attribute's object class
        if (!ResultCode.OBJECTCLASS_VIOLATION.equals(le.getResult().getResultCode())) {
            throw e;
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) UMSException(com.iplanet.ums.UMSException) ArrayList(java.util.ArrayList) LdapException(org.forgerock.opendj.ldap.LdapException) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 39 with LdapException

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

the class ImportServiceConfiguration method getLDAPConnection.

private Connection getLDAPConnection() throws CLIException {
    IOutput outputWriter = getOutputWriter();
    if (isVerbose()) {
        outputWriter.printlnMessage(getResourceString("import-service-configuration-connecting-to-ds"));
    }
    try {
        Connection conn;
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        ServerGroup sg = dsCfg.getServerGroup("sms");
        if (sg != null) {
            conn = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN).getConnection();
        } else {
            throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
        }
        if (isVerbose()) {
            outputWriter.printlnMessage(getResourceString("import-service-configuration-connected-to-ds"));
        }
        return conn;
    } catch (LDAPServiceException | LdapException e) {
        throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
    }
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) IOutput(com.sun.identity.cli.IOutput) Connection(org.forgerock.opendj.ldap.Connection) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) CLIException(com.sun.identity.cli.CLIException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 40 with LdapException

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

the class ImportServiceConfiguration method handleRequest.

/**
     * Services a Commandline Request.
     *
     * @param rc Request Context.
     * @throws CLIException if the request cannot serviced.
     */
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String xmlFile = getStringOptionValue(IArgument.XML_FILE);
    String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
    try {
        encryptSecret = CLIUtil.getFileContent(getCommandManager(), encryptSecret).trim();
    } catch (CLIException clie) {
    //There is no encryptSecret file
    }
    validateEncryptSecret(xmlFile, encryptSecret);
    // disable notification
    SystemProperties.initializeProperties(Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
    SystemProperties.initializeProperties("com.sun.am.event.connection.disable.list", "sm,aci,um");
    // disable error debug messsage
    SystemProperties.initializeProperties(Constants.SYS_PROPERTY_INSTALL_TIME, "true");
    IOutput outputWriter = getOutputWriter();
    try (Connection ldConnection = getLDAPConnection()) {
        InitializeSystem initSys = CommandManager.initSys;
        SSOToken ssoToken = initSys.getSSOToken(getAdminPassword());
        DirectoryServerVendor.Vendor vendor = DirectoryServerVendor.getInstance().query(ldConnection);
        if (!vendor.name.equals(DirectoryServerVendor.OPENDJ) && !vendor.name.equals(DirectoryServerVendor.OPENDS) && !vendor.name.equals(DirectoryServerVendor.ODSEE)) {
            throw new CLIException(getResourceString("import-service-configuration-unknown-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        loadLDIF(vendor, ldConnection);
        String ouServices = "ou=services," + initSys.getRootSuffix();
        if (this.isOuServicesExists(ssoToken, ouServices)) {
            System.out.print(getResourceString("import-service-configuration-prompt-delete") + " ");
            String value = (new BufferedReader(new InputStreamReader(System.in))).readLine();
            value = value.trim();
            if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
                outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
                deleteOuServicesDescendents(ssoToken, ouServices);
                importData(xmlFile, encryptSecret, ssoToken);
            }
        } else {
            outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
            importData(xmlFile, encryptSecret, ssoToken);
        }
    } catch (SMSException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (LdapException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (LoginException e) {
        throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
    } catch (InvalidAuthContextException e) {
        throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) InputStreamReader(java.io.InputStreamReader) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) InitializeSystem(com.sun.identity.cli.InitializeSystem) IOutput(com.sun.identity.cli.IOutput) BufferedReader(java.io.BufferedReader) CLIException(com.sun.identity.cli.CLIException) DirectoryServerVendor(com.sun.identity.sm.DirectoryServerVendor) LoginException(javax.security.auth.login.LoginException) LdapException(org.forgerock.opendj.ldap.LdapException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException)

Aggregations

LdapException (org.forgerock.opendj.ldap.LdapException)90 Connection (org.forgerock.opendj.ldap.Connection)64 ByteString (org.forgerock.opendj.ldap.ByteString)45 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)38 ResultCode (org.forgerock.opendj.ldap.ResultCode)37 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)37 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)24 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)24 HashSet (java.util.HashSet)22 Attribute (org.forgerock.opendj.ldap.Attribute)19 PolicyException (com.sun.identity.policy.PolicyException)13 SMSException (com.sun.identity.sm.SMSException)12 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)12 SSOException (com.iplanet.sso.SSOException)11 LinkedHashSet (java.util.LinkedHashSet)11 DN (org.forgerock.opendj.ldap.DN)11 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)10 IOException (java.io.IOException)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)9