Wednesday, August 21, 2024

Create group in OpenLdap

import sailpoint.connector.Connector;
import sailpoint.connector.LDAPConnector;
import sailpoint.object.Application;
import sailpoint.object.Attributes;
import sailpoint.object.Link;
import sailpoint.object.Identity;
import sailpoint.api.SailPointContext;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;
import java.util.HashMap;
import java.util.Map;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.BasicAttribute;

Application ldapApp = context.getObjectByName(Application.class, "Mighty Application Name"); // Replace with your LDAP application name

// Initialize the LDAP connector
Connector connector = ldapApp.getConnector();
LDAPConnector ldapConnector = (LDAPConnector) connector;


String groupName = "mygroup";  
String groupBaseDN = "ou=groups,dc=example,dc=com";  
String gidNumber = "1234";  

// Prepare attributes for the new group
Attributes<String, Object> groupAttrs = new Attributes<>();
groupAttrs.put("cn", groupName);
groupAttrs.put("objectClass", Util.list("top", "posixGroup"));
groupAttrs.put("gidNumber", gidNumber);

try {
    ldapConnector.createObject(context, "group", groupAttrs, groupBaseDN + ",cn=" + groupName);

    
} catch (GeneralException e) {
    System.out.println("GeneralException: " + e.getMessage());
}

No comments:

Post a Comment

Fetch Members from Workgroup

  import java.util.ArrayList;   import java.util.Iterator;   import java.util.List;   import sailpoint.api.ObjectUtil;   import sailpoint.ob...