Hi William,
Try changing these two lines as given below.
var mods = new ModificationItem[1]();
var mod0 = new BasicAttribute("mail", "aa@aa.com");
javascript with above changes:
function LDAPSearch(query, attributes, baseDN) {
// Params:
// query LDAP filter - ex: '(cn=IAM_*)'
// attributes Comma-separeted list of attributes to retrieve - ex: 'cn,description,owner'
// baseDN base DN used for the search - ex: 'o=acme, c=br'
// Allows the usage of 'importPackage' with JRE8
try{
load("nashorn:mozilla_compat.js");
}
catch(e){}
// Import LDAP Packages
importPackage(Packages.java.util.Hashtable);
importPackage(Packages.java.util.HashMap);
importPackage(Packages.javax.naming.Context);
importPackage(Packages.javax.naming.NamingEnumeration);
importPackage(Packages.javax.naming.NamingException);
importPackage(Packages.javax.naming.directory.DirContext);
importPackage(Packages.javax.naming.directory.InitialDirContext);
importPackage(Packages.javax.naming.directory.SearchControls);
importPackage(Packages.javax.naming.directory.ModificationItem);
importPackage(Packages.javax.naming.directory.Attribute);
importPackage(Packages.javax.naming.directory.BasicAttribute);
// Connexion and Search Control Variables
var host = "192.168.1.119"; // i.e. "127.0.0.1"
var port = "19289" // i.e. "19289"
var bindDN = "cn=dsaadmin,ou=im,ou=ca,o=com" // i.e. "cn=dsaadmin,ou=im,ou=ca,o=com";
var pwd = "CAdemo123";
var cLimit = 100;
var tLimit = 60 * 1000;
// Formats the attribute list into a String Array
var attr = attributes.split(",");
// Connection info
var env = new java.util.Hashtable(11);
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(javax.naming.Context.PROVIDER_URL, "ldap://" + host + ":" + port);
env.put(javax.naming.Context.SECURITY_PRINCIPAL, bindDN);
env.put(javax.naming.Context.SECURITY_CREDENTIALS, pwd);
// Start the context and launches the query
try {
var ctx = new javax.naming.directory.InitialDirContext(env);
var mods = new ModificationItem[1]();
var mod0 = new BasicAttribute("mail", "aa@aa.com");
//Attribute mod1 = new BasicAttribute("1", "AAA");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
// mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod1);
ctx.modifyAttributes("uid=7788,ou=people,ou=im,ou=ca,o=com", mods);
ctx.close();
//return retvalMap;
}
catch (e) {
return 'Error: ' + e.toString();
}
}
Original Message:
Sent: 08-19-2019 07:35 PM
From: William Cheang
Subject: Identity Portal - Plugins perform ldap modify attribute
Hi Kavita, this is the plugins javascript.
function LDAPSearch(query, attributes, baseDN) {try{load("nashorn:mozilla_compat.js");}catch(e){} importPackage(Packages.java.util.Hashtable);importPackage(Packages.java.util.HashMap);importPackage(Packages.javax.naming.Context);importPackage(Packages.javax.naming.NamingEnumeration);importPackage(Packages.javax.naming.NamingException);importPackage(Packages.javax.naming.directory.DirContext);importPackage(Packages.javax.naming.directory.InitialDirContext);importPackage(Packages.javax.naming.directory.SearchControls);importPackage(Packages.javax.naming.directory.ModificationItem);importPackage(Packages.javax.naming.directory.Attribute);importPackage(Packages.javax.naming.directory.BasicAttribute); var host = "192.168.1.119"; var port = "19289" var bindDN = "cn=dsaadmin,ou=im,ou=ca,o=com" var pwd = "CAdemo123";var cLimit = 100;var tLimit = 60 * 1000; var attr = attributes.split(","); var env = new java.util.Hashtable(11);env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");env.put(javax.naming.Context.PROVIDER_URL, "ldap://" + host + ":" + port);env.put(javax.naming.Context.SECURITY_PRINCIPAL, bindDN);env.put(javax.naming.Context.SECURITY_CREDENTIALS, pwd); try {var ctx = new javax.naming.directory.InitialDirContext(env);ModificationItem[] mods = new ModificationItem[1]; Attribute mod0 = new BasicAttribute("mail", "aa@aa.com"); mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0); ctx.modifyAttributes("uid=7788,ou=people,ou=im,ou=ca,o=com", mods); ctx.close(); }catch (e) {return 'Error: ' + e.toString();} }
Original Message:
Sent: 08-16-2019 01:59 AM
From: Kavita Nethinti
Subject: Identity Portal - Plugins perform ldap modify attribute
Hi William,
Please send me the java file to get some clue.
Regards
Kavita
Original Message:
Sent: 08-16-2019 01:40 AM
From: William Cheang
Subject: Identity Portal - Plugins perform ldap modify attribute
tried, still the same error.
Original Message:
Sent: 08-15-2019 11:42 PM
From: Kavita Nethinti
Subject: Identity Portal - Plugins perform ldap modify attribute
Try using
ModificationItem[] mods = new ModificationItem[1];
Regards
Kavita
Original Message:
Sent: 08-14-2019 12:09 AM
From: William Cheang
Subject: Identity Portal - Plugins perform ldap modify attribute
Hi Team,
Identity Suite 14.3 vapp.
As i understand we can use plug-ins(java) to query LDAP servers.
Due to special requirement where we have to build a custom form in Identity Portal and allow user to perform reset password on this LDAP server.
When perform resetpassword in LDAP, basically we are triggering a java ctx.modifyAttributes command to modify LDAP attributes.
I have created 2 plugins, 1 plugins is to perform search on LDAP, which is working fine.
2nd plugins is to perform modifyattribute, which is not working.
I have included the correct package, "ModificationItem"
Anyone have experience this error ?
Note: in IP logs, i saw the error "javax.script.ScriptException:45:18:Expected ; but found mods in ModificationItem mods[] = new ModificationItem[1];
regards,
William