Groovy script to access Oracle Identity Management using OIM Client library.
Need following libraries:
spring.jaroimclient.jarwlfullclient.jar
authwl.conf file content:
xellerate{
weblogic.security.auth.login.UsernamePasswordLoginModule
required debug=true;
};
Class loading:
#!/usr/bin/env groovy
this.getClass().classLoader.rootLoader.addURL(new File("lib/spring.jar").toURL());
this.getClass().classLoader.rootLoader.addURL(new File("lib/oimclient.jar").toURL());
this.getClass().classLoader.rootLoader.addURL(new File("lib/wlfullclient.jar").toURL());
import oracle.iam.platform.*;
import oracle.iam.identity.usermgmt.api.*;
Connecting OIM:
String oimUrl = "<server_url>";
String oimAdmin = "<privileged_user>";
String oimPasswd = "<password>";
String authwlFileName = "authwl.conf";
String authwl = getClass().getClassLoader().getResource(authwlFileName).toString();
System.setProperty("java.security.auth.login.config", authwl);
System.setProperty("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
System.setProperty("java.naming.provider.url", oimUrl);
System.setProperty("OIM.AppServerType", "wls");
System.setProperty("APPSERVER_TYPE", "wls");
def OIMClient = Class.forName("oracle.iam.platform.OIMClient").newInstance();
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
env.put("java.naming.provider.url", oimUrl);
OIMClient.login(oimAdmin, oimPasswd.toCharArray(), env);
println "Connected to OIM => ${oimUrl}\n";
Read an entry:
usrMgr = OIMClient.getService(Class.forName("oracle.iam.identity.usermgmt.api.UserManager"));
//Parameters to be read from OIM. Add additional fields based on need
usrAttrs = new HashSet<String>();
usrAttrs.add("Common Name");
usrAttrs.add("Display Name");
usrAttrs.add("Email");
usrAttrs.add("First Name");
usrAttrs.add("Initials");
usrAttrs.add("Last Name");
usrAttrs.add("User Login");
user = usrMgr.getDetails("User Login", "<user_login_unique_value>", usrAttrs);
//Print
usrAttrs.each {
println "$it \t\t=> ${user.getAttribute(it)}";
}
Modify an entry:
usrMgr = OIMClient.getService(Class.forName("oracle.iam.identity.usermgmt.api.UserManager"));
//collect entityid
HashSet<String> retAttrs = new HashSet<String>();
user = usrMgr.getDetails("User Login", "<user_login>", retAttrs);
entityId = user.getEntityId();
//create user entry using entityid
updateUser = Class.forName("oracle.iam.identity.usermgmt.vo.User").newInstance(entityId);
//update the user
updateUser.setAttribute("<field_name>", "<new_value>"); //refer OIM form mappings for attribute name
usrMgr.modify(updateUser);
println "User modified";
No comments:
Post a Comment