Tuesday 2 June 2015

Update User Profile Attribute Value in OIM

Below code will update the User Profile attribute value.

===============================================================
For Client Code below JAR need to be added in Eclipse or JDeveloper.

1) commons-logging.jar
2) jrf-api.jar
3) oimclient.jar
4) spring.jar
5) wlfullclient.jar

==============================================================
Update User Profile Attribute Code-
==============================================================
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import javax.security.auth.login.LoginException;
import oracle.iam.identity.exception.NoSuchUserException;
import oracle.iam.identity.exception.SearchKeyNotUniqueException;
import oracle.iam.identity.exception.UserModifyException;
import oracle.iam.identity.exception.ValidationFailedException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.authz.exception.AccessDeniedException;


public class UpdateProfileAttribute {

public static OIMClient oimClient;

public void OIMConnection(){

String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL,oimInitialContextFactory);
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://10.2.78.11:14000");
System.setProperty("java.security.auth.login.config", "C:\\Software\\designconsole\\designconsole\\config\\authwl.conf");
System.setProperty("OIM.AppServerType", "wls");        
   System.setProperty("APPSERVER_TYPE", "wls");
   oimClient = new OIMClient(env);
   try {
oimClient.login("xelsysadm","Password".toCharArray());
System.out.println("Connected Successfully");
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void updateProfileAttribute() throws ValidationFailedException, UserModifyException, SearchKeyNotUniqueException{
System.out.println("<----Inside Assign Mail Method---->");
UserManager usrmgr=oimClient.getService(UserManager.class);

Set<String> resAttr=new HashSet<String>();
try {
HashMap<String, Object> userAttributeValueMap = new HashMap<String, Object>();
userAttributeValueMap.put("Email", "test@gmail.com");
System.out.println("User Attribute Map is"+userAttributeValueMap);
//Provide the user key for user which attribute need to be updated
String ukey="369";
User user = new User(ukey, userAttributeValueMap);
System.out.println("User  Map is"+user);
try {
usrmgr.modify(user);
System.out.println("User Modified Successfully");
} catch (NoSuchUserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

   
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

public static void main(String args[]) throws ValidationFailedException, UserModifyException, SearchKeyNotUniqueException{
UpdateProfileAttribute upa=new UpdateProfileAttribute();
upa.OIMConnection();  //Calling the method for OIM Connection
upa.updateProfileAttribute();  //Calling the update method

}

}

No comments:

Post a Comment