Wednesday, January 27, 2021

FileNet and Ldap connectivity - java code to get Active Directory Connection

 

//Connecting to LDAP using java code

String rootDN = "CN=xyz,CN=xyz,DC=xyz,DC=xyz";

        String rootPWD = "*****";

        Hashtable<String, String> environment = new Hashtable<String, String>();

        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

        environment.put(Context.PROVIDER_URL, "<ldapurl>");

        environment.put(Context.SECURITY_AUTHENTICATION, "authentications type");

        environment.put(Context.SECURITY_PRINCIPAL, rootDN);

        environment.put(Context.SECURITY_CREDENTIALS, rootPWD);

        DirContext dirContext = null;

        NamingEnumeration<?> results = null;

dirContext = new InitialDirContext(environment);

FileNet - Fetch the users and all attributes from Active Directory and AD Connection and setting all environment variables for AD


Connecting to Active Directory



ArrayList getListValues(){

// Connect to the Active Directory here or click here for Connection code

ArrayList list = new ArrayList();

        SearchControls searchctrl = new SearchControls();

        searchctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);

        searchctrl.setReturningAttributes(new String[]{"name or id"}); \\ attributes which we are retriving from AD

        results = dirContext.search("", "(objectclass=user)", searchctrl);

        while(results.hasMore()){

        SearchResult res = (SearchResult) results.next();

        Attributes attributes = res.getAttributes();

        Enumeration attribute = attributes.getAll();

        while(attribute.hasMoreElements()){

        Attribute attr = (Attribute) attribute.nextElement();

        if(!attr.toString().equals("") && !attr.toString().equals(null)){

        list.add(attr.toString());

        }

        }       

          }       

              return list;

}

ICN Plug-in Filter for Retrieving Users from LDAP and displaying in Property as a Choice List Object (IBM Content Navigator Plugins and Filters)


IBM Filenet Request and Response Filters


public class OpenContentClassFilter extends PluginResponseFilter {

public String[] getFilteredServices() {

return new String[] { "/p8/openContentClass" };

}

public void filter(String serverType, PluginServiceCallbacks callbacks,

HttpServletRequest request, JSONObject jsonResponse) throws Exception {

JSONArray jsonprops = (JSONArray) jsonResponse.get("criterias");

for(int i =0; i<jsonprops.size();i++){

JSONObject jobject = (JSONObject) jsonprops.get(i);

String str  = (String) jobject.get("name");

if(str.equals("CmAcmRuleType")){

JSONObject newchlist = new JSONObject();

newchlist.put("displayName", "listofadusers");

JSONArray jarry = new JSONArray();

ArrayList list = getListValues();

for(int j = 0; j<list.size();j++){

JSONObject item = new JSONObject();

item.put("value", list.get(j));

jarry.add(item);

}

newchlist.put("choices", jarry);

jobject.put("choiceList", newchlist);

}

}

}

ArrayList getListValues(){

String rootDN = "CN=xyz,CN=xyz,DC=xyz,DC=xyz";

        String rootPWD = "*****";

        Hashtable<String, String> environment = new Hashtable<String, String>();

        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

        environment.put(Context.PROVIDER_URL, "<ldapurl>");

        environment.put(Context.SECURITY_AUTHENTICATION, "authentications type");

        environment.put(Context.SECURITY_PRINCIPAL, rootDN);

        environment.put(Context.SECURITY_CREDENTIALS, rootPWD);

        DirContext dirContext = null;

        NamingEnumeration<?> results = null;

        ArrayList list = new ArrayList();

        try{

        dirContext = new InitialDirContext(environment);

        SearchControls searchctrl = new SearchControls();

        searchctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);

        searchctrl.setReturningAttributes(new String[]{"name or id"}); \\ attributes which we are retriving from AD

        results = dirContext.search("", "(objectclass=user)", searchctrl);

        while(results.hasMore()){

        SearchResult res = (SearchResult) results.next();

        Attributes attributes = res.getAttributes();

        Enumeration attribute = attributes.getAll();

        while(attribute.hasMoreElements()){

        Attribute attr = (Attribute) attribute.nextElement();

        if(!attr.toString().equals("") && !attr.toString().equals(null)){

        list.add(attr.toString());

        }

        }       

          }       

        }catch(Exception exe){

        System.out.println("Exception occured : "+exe.getLocalizedMessage());

        }                

return list;

}

}

IBM Case Manager script - Select User Dialog box on Filed Focus event - to select user from the list of LDAP Users (ecm.widget.dialog.SelectUserGroupDialog)

if(payload.eventName === "icm.FieldFocused"){

if(payload.id === "PRX_Name")

{

 callback = function(users){

                        this.propController.set("value", users[0].shortName);

                        }; 

                    var selectUserDialog = new ecm.widget.dialog.SelectUserGroupDialog({

                                            queryMode: "users",

                                            selectionMode :"single",

                                            callback: dojo.hitch(this,callback)

                                            });

                    selectUserDialog.show(solution.getTargetOS());    

}

}

FileNet Dojo Script in ACCE -Set List values to String List object (multi cardinality object values) - com.filenet.api.collection.StringList

 importClass(Packages.com.filenet.api.property.Properties); 

importClass(Packages.com.filenet.api.constants.RefreshMode);

importClass(Packages.com.filenet.api.collection.StringList);

function OnCustomProcess (CEObject)

{

CEObject.refresh(); 

var list =new Packages.com.filenet.api.core.Factory.StringList.createList();

var values = CEObject.getProperties().getStringValue("City").split(";");

for (var l = 0; l < values.length; l++) {

        list.add(values[l]);

}

CEObject.getProperties().putObjectValue("StatesList",list);

CEObject.save(RefreshMode.REFRESH);

}

FileNet ACCE Script to set Retention period on CE objects (Documents or Folders) - Packages.com.filenet.api.property.Properties

IBM FileNet ACCE Script to set Retention period on CE objects


importClass(Packages.com.filenet.api.property.Properties); 

importClass(Packages.com.filenet.api.constants.RefreshMode); 

function OnCustomProcess (CEObject) 

CEObject.refresh(); 

CEObject.set_CmRetentionDate(new Date(new Date().getTime()-4)); 

CEObject.save(RefreshMode.REFRESH); 

}

ACCE script to fetch document properties from ACCE - Packages.com.filenet.api.property.Properties


IBM FileNet ACCE Script - Fetch Document Properties


importClass(Packages.com.filenet.api.property.Properties); 

importClass(Packages.com.filenet.api.constants.RefreshMode);

function OnCustomProcess (CEObject)

{

    CEObject.refresh(); 

    CEObject.getProperties().putObjectValue("City", "xyz");

    CEObject.save(RefreshMode.REFRESH);

}

FileNet API - Java code to get CE Connection using FileNet Content Engine API


FileNet Content Engine Connection


          A Connection is a fairly lightweight class. It tells the API how to connect to the Content Engine server. Because interactions between the API and the CE server are stateless from the point of view of the CE server, 
The below code is for Content Engine Server connection,

try{
      String contentenginURI = "http://<hostname>:<portnumber>/wsi/FNCEWS40MTOM/"; 
      String userName ="username"; 
      String password = "password"; 
      if(connectionObj==null){ 
      connectionObj = Factory.Connection.getConnection(contentenginURI); 
      Subject subject = UserContext.createSubject(connectionObj, userName, password, null); 
      UserContext uc = UserContext.get(); \\get UserContext Object and push the subject 
      uc.pushSubject(subject);    
     }
 }catch(Exception exe) { 
         exe.printStackTrace(); 
 }  

            A Connection object contains enough information to establish communication with the Content Engine server. This information is carried in a URI and includes the transport protocol (connection type), host name, and port number that are used for server communication. An incorrect configuration, such as an incompatibility between the environment and the information in the Connection object, is the most frequent cause of an exception that is related to a connection failure.