OIMClient API / OIMConnection API

  1. package com.oimacademy.connection;
  2. import java.util.Hashtable;
  3. import java.util.Properties;
  4. import javax.security.auth.login.LoginException;
  5. import oracle.iam.platform.OIMClient;
  6. import com.oimacademy.properties.OIMProfileReader;
  7. import com.thortech.xl.util.LocalConfiguration;
  8. public class OIMConnection {
  9. private static String ctxFactory = null;
  10. private static String serverURL = null;
  11. private static String appServerType = null;
  12. private static OIMClient connectionObject = null;
  13. private static OIMProfileReader properties=null;
  14. private static String username = "xelsysadm";
  15. private static String password = "Welcome1";
  16. private static OIMClient connection() {
  17. System.out.println("Startup...");
  18. System.out.println("Getting configuration...");
  19. //getProperties();
  20. //setSystemProperties();
  21. OIMClient localConnection = new OIMClient(getEnvironment());
  22. try {
  23. localConnection.login(username, password.toCharArray());
  24. } catch (LoginException e) {
  25. e.printStackTrace();
  26. }
  27. Properties props = LocalConfiguration.getLocalCoreServerConfiguration();
  28. System.out.println(props.toString());
  29. return localConnection;
  30. }
  31. public static synchronized OIMClient getConnection() {
  32. if (connectionObject == null) {
  33. connectionObject = connection();
  34. }
  35. return connectionObject;
  36. }
  37. public static void closeConnection() {
  38. connectionObject.logout();
  39. }
  40. public static Hashtable<String, String> getEnvironment(){
  41. getProperties();
  42. setSystemProperties();
  43. Hashtable<String, String> env = new Hashtable<String, String>();
  44. env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, serverURL);
  45. env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, ctxFactory);
  46. return env;
  47. }
  48. public static void getProperties(){
  49. properties = new OIMProfileReader();
  50. appServerType=properties.getString("appserver.type");
  51. serverURL=properties.getString("oim.jndi.url");
  52. ctxFactory=properties.getString("bpelprovider.initial.factory");
  53. System.out.println(" serverURL -> "+serverURL);
  54. }
  55. public static void setSystemProperties(){
  56. //Update path of authwl.conf file according to your environment
  57. System.setProperty("java.security.auth.login.config","config/authwl.conf");
  58. System.setProperty("OIM.AppServerType", appServerType);
  59. System.setProperty("APPSERVER_TYPE", appServerType);
  60. System.setProperty("XL.HomeDir","");
  61. // SSL Port connection http://oimreferences.blogspot.in/2013/07/oim-java-api-to-connect-oim-ssl-port.html
  62. /*System.setProperty("javax.net.ssl.trustStoreType","JKS");
  63. System.setProperty("javax.net.ssl.trustStore","C:/Program Files (x86)/Java/jre1.7.0_45/lib/security/cacerts");
  64. System.setProperty("javax.net.ssl.trustStorePassword","changeit"); */
  65. // SSL Port connection
  66. }
  67. public static void main(String args[]){
  68. getConnection();
  69. // closeConnection();
  70. }
  71. }

No comments:

Post a Comment