Environment : Tomcat 4.1 , JBoss 4.0.3 SP1, OIM 9.0.3.1
===================================
File: raj.jsp
===================================
<%@page import="com.oim.xl.integration.UserOperations" %>
<%@page import="java.util.*" %>
<html>
<title>OIM</title>
<body>
Finding user with first name System <BR>
<%
String s="";
UserOperations uo=new UserOperations();
List lst=uo.getUserLogin("System");
ListIterator it = lst.listIterator();
while (it.hasNext()) {
s = (String) it.next();
}
%>
The result is : <%=s %>
</body>
</html>
===================================
File: UserOperations.class
===================================
package com.oim.xl.integration;
import java.util.*;
import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import com.thortech.xl.util.config.ConfigurationClient;
import Thor.API.Operations.tcOrganizationOperationsIntf;
import Thor.API.Operations.tcUserOperationsIntf;
public class UserOperations {
/** The utility factory instance. */
private tcUtilityFactory ioUtilityFactory;
public UserOperations(){
Hashtable env=new Hashtable();
env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.provider.url", "jnp://192.168.1.101:1099");
System.setProperty("java.security.manager", "");
System.setProperty("XL.HomeDir", "C:\\tomcat4.1\\config");
System.setProperty("java.security.policy", "C:\\tomcat4.1\\config\\xl.policy");
System.setProperty("java.security.auth.login.config", "C:\\tomcat4.1\\config\\auth.conf");
System.setProperty("java.naming.provider.url", "jnp://192.168.1.101:1099/UserOperations");
Enumeration enum = env.keys();
while(enum.hasMoreElements())
{
String s = (String)enum.nextElement();
}
try{
log("Connect as : xelsysadm ");
ioUtilityFactory = new tcUtilityFactory(env, "xelsysadm","xelsysadm");
log("Connected as : " + ioUtilityFactory.getUserName());
}catch(Exception ex)
{
ex.printStackTrace();
}
}
/** Retrieves user login based on the first name. */
public List getUserLogin(String psFirstName){
Vector mvUsers=new Vector();
try{
tcUserOperationsIntf moUserUtility =(tcUserOperationsIntf)ioUtilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
log("Interface tcUserOperationsIntf moUserUtility successfully created.");
Hashtable mhSearchCriteria = new Hashtable();
mhSearchCriteria.put("Users.First Name", psFirstName);
tcResultSet moResultSet = moUserUtility.findUsers(mhSearchCriteria);
log("Finding Users with First Name "+ psFirstName);
for (int i=0; i<moResultSet.getRowCount(); i++){
moResultSet.goToRow(i);
mvUsers.add(moResultSet.getStringValue("Users.User ID"));
log("Key is : "+ String.valueOf(moResultSet.getLongValue("Users.Key")) + " for user id : "+ moResultSet.getStringValue("Users.User ID"));
}
} catch(Exception ex){ex.printStackTrace();}
return mvUsers;
}
private void log(String msg){
System.out.println(msg);
}
public String setEmailID(String userLogin, String emailid){
String rtnval="SUCCESS";
try
{
log("Changing Email Id for user : "+userLogin+" to "+emailid);
tcUserOperationsIntf moUserUtility =(tcUserOperationsIntf)ioUtilityFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
Hashtable mhSearchCriteria = new Hashtable();
mhSearchCriteria.put("Users.User ID", userLogin);
tcResultSet moResultSet = moUserUtility.findUsers(mhSearchCriteria);
for (int i=0; i<moResultSet.getRowCount(); i++){
moResultSet.goToRow(i);
log("Key is : "+ String.valueOf(moResultSet.getLongValue("Users.Key")) + " for user id : "+ moResultSet.getStringValue("Users.User ID") + " with old email id: "+ moResultSet.getStringValue("Users.Email"));
}
HashMap hm = new HashMap();
hm.put("Users.Email",emailid);
moUserUtility.updateUser(moResultSet, hm);
log("Email Id Changed Successfully to "+emailid);
}
catch(Exception e)
{
log("Change User Email Id Failed... Exception...." + e.getMessage());
rtnval="Error "+e.getMessage();
}
return rtnval;
}
/** Retrieves the administrators of an organization based on the organization name. */
public List getAdministratorsOfOrganization(String psOrganizationName){
Vector mvOrganizations=new Vector();
try{
tcOrganizationOperationsIntf moOrganizationUtility =(tcOrganizationOperationsIntf)ioUtilityFactory.getUtility("Thor.API.Operations.tcOrganizationOperationsIntf");
Hashtable mhSearchCriteria = new Hashtable();
mhSearchCriteria.put("Organizations.Organization Name", psOrganizationName);
tcResultSet moResultSet =moOrganizationUtility.findOrganizations(mhSearchCriteria);
tcResultSet moAdmins;
for (int i=0; i<moResultSet.getRowCount(); i++){
moResultSet.goToRow(i);
moAdmins=moOrganizationUtility.getAdministrators(moResultSet.getLongValue("Organizations.Key"));
mvOrganizations.add(moAdmins.getStringValue("Groups.Group Name"));
}
}
catch(Exception ex) { ex.printStackTrace();}
return mvOrganizations;
}
/**
* @param args
*
public static void main(String[] args) {
List moList;
UserOperations uo=new UserOperations();
moList=uo.getUserLogin("System");
uo.setEmailID("teste43", "rajnishbhatia19@hotmail.com");
System.exit(0);
}*/
}
================================
Results
================================
See attached OIM.jpg :
Monday, August 6, 2007
Calling OIM User Operations from a JSP Web Page
Posted by Rajnish Bhatia at 5:34 PM
Subscribe to:
Post Comments (Atom)
2 comments:
This is exactly what i want. But, i have lot of problems about this.
1) Where we put these files.
2) What are the configuration that has to be done from jboss, oim and java side to run this file?
Hi Rajnish,
I am not sure whether you are still updating this post. I have a query on deploying SPML webservices with OIM11g. Can you help me providing the steps to proceed with writing the webservice. I am trying to create user in OIM using SPML
Post a Comment