Wednesday, January 27, 2021

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;

}

}

No comments:

Post a Comment