Search in sources :

Example 11 with Modification

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

the class COSManager method toModifications.

private Collection<Modification> toModifications(ModificationType type, AttrSet attrSet) {
    Collection<Modification> modifications = new HashSet<>();
    Enumeration<Attr> attributes = attrSet.getAttributes();
    while (attributes.hasMoreElements()) {
        modifications.add(new Modification(type, attributes.nextElement().toLDAPAttribute()));
    }
    return modifications;
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Attr(com.iplanet.services.ldap.Attr) HashSet(java.util.HashSet)

Example 12 with Modification

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

the class EmbeddedOpenDS method delOpenDSServer.

/**
     * Removes host:port from OpenDJ replication
     */
public static void delOpenDSServer(Connection lc, String delServer) {
    String replServerDN = "cn=" + delServer + ",cn=Servers,cn=admin data";
    final String[] attrs = { "ds-cfg-key-id" };
    Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
    if (lc == null) {
        debug.error("EmbeddedOpenDS:syncOpenDSServer():" + "Could not connect to local OpenDJ instance." + replServerDN);
        return;
    }
    String trustKey = null;
    try {
        SearchResultEntry le = lc.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(replServerDN, attrs));
        if (le != null) {
            Attribute la = le.getAttribute(attrs[0]);
            if (la != null) {
                trustKey = la.firstValueAsString();
            }
            String keyDN = "ds-cfg-key-id=" + trustKey + ",cn=instance keys,cn=admin data";
            lc.delete(LDAPRequests.newDeleteRequest(keyDN));
        } else {
            debug.error("EmbeddedOpenDS:syncOpenDSServer():" + "Could not find trustkey for:" + replServerDN);
        }
    } catch (Exception ex) {
        debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting replication key:", ex);
    }
    try {
        lc.delete(LDAPRequests.newDeleteRequest(replServerDN));
    } catch (Exception ex) {
        debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting deleting server entry:" + replServerDN, ex);
    }
    try {
        ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(replDN).addModification(new Modification(ModificationType.DELETE, Attributes.singletonAttribute("uniqueMember", "cn=" + delServer)));
        lc.modify(modifyRequest);
    } catch (Exception ex) {
        debug.error("EmbeddedOpenDS.syncOpenDSServer()." + " Error getting removing :" + replDN, ex);
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) Debug(com.sun.identity.shared.debug.Debug) 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 13 with Modification

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

the class LdifUtils method createSchemaFromLDIF.

/**
     * Creates LDAP schema from LDIF file.
     *
     * @param ldif LDIF object.
     * @param ld LDAP Connection.
     * @throws IOException If an error occurs when reading the LDIF file.
     */
public static void createSchemaFromLDIF(LDIFChangeRecordReader ldif, final Connection ld) throws IOException {
    while (ldif.hasNext()) {
        final ChangeRecord changeRecord = ldif.readChangeRecord();
        changeRecord.accept(new ChangeRecordVisitor<Void, Void>() {

            @Override
            public Void visitChangeRecord(Void aVoid, AddRequest change) {
                try {
                    change.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
                    ld.add(change);
                } catch (LdapException e) {
                    if (ResultCode.ENTRY_ALREADY_EXISTS.equals(e.getResult().getResultCode())) {
                        for (Attribute attr : change.getAllAttributes()) {
                            ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(change.getName());
                            modifyRequest.addModification(new Modification(ModificationType.ADD, attr));
                            try {
                                ld.modify(modifyRequest);
                            } catch (LdapException ex) {
                                DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}", modifyRequest, ex);
                            }
                        }
                    } else {
                        DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not add to schema: {}", change, e);
                    }
                }
                return null;
            }

            @Override
            public Void visitChangeRecord(Void aVoid, ModifyRequest change) {
                try {
                    change.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
                    ld.modify(change);
                } catch (LdapException e) {
                    DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}", change, e);
                }
                return null;
            }

            @Override
            public Void visitChangeRecord(Void aVoid, ModifyDNRequest change) {
                return null;
            }

            @Override
            public Void visitChangeRecord(Void aVoid, DeleteRequest change) {
                DEBUG.message("Delete request ignored: {}", changeRecord);
                return null;
            }
        }, null);
    }
}
Also used : AddRequest(org.forgerock.opendj.ldap.requests.AddRequest) ModifyDNRequest(org.forgerock.opendj.ldap.requests.ModifyDNRequest) Modification(org.forgerock.opendj.ldap.Modification) Attribute(org.forgerock.opendj.ldap.Attribute) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) ChangeRecord(org.forgerock.opendj.ldif.ChangeRecord) LdapException(org.forgerock.opendj.ldap.LdapException) DeleteRequest(org.forgerock.opendj.ldap.requests.DeleteRequest)

Aggregations

Modification (org.forgerock.opendj.ldap.Modification)13 LdapException (org.forgerock.opendj.ldap.LdapException)7 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)7 Attribute (org.forgerock.opendj.ldap.Attribute)6 ByteString (org.forgerock.opendj.ldap.ByteString)6 Connection (org.forgerock.opendj.ldap.Connection)5 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)4 Attr (com.iplanet.services.ldap.Attr)2 HashSet (java.util.HashSet)2 ResultCode (org.forgerock.opendj.ldap.ResultCode)2 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 Debug (com.sun.identity.shared.debug.Debug)1 SMSException (com.sun.identity.sm.SMSException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1