Lets start with the first and foremost thing anybody who is looking to write OIM API code will require to know: Connecting to and disconnecting from the OIM server.
We will also take a look at how to setup our eclipse project for developing OIM API code.
So lets begin...
1) Creating an eclipse project.
2) Setting up the project with required libraries
We will also take a look at how to setup our eclipse project for developing OIM API code.
So lets begin...
1) Creating an eclipse project.
2) Setting up the project with required libraries
- Extract the oimclient.zip file present in the $OIM_CLIENT_HOME/server/client/
- It will have a oimclient.jar and a lib, conf, sample folders within the extracted folder
- Copy the wlfullclient.jar from the $WL_HOME/server/lib into the lib folder of the extracted oimclient.zip
- If wlfullclient is not present in the $WL_HOME/server/lib folder, you have to build it manually using the follo\wing command
- cd $WL_HOME/server/lib
- java -jar wljarbuilder.jar
- The wlfullclient.jar is created now
- Copy the oimclient.jar and the contents of the lib folder of the extracted oimclient.zip, including the wlfullclient.jar
3) Writing code
package com.oim;import java.util.Hashtable;import javax.security.auth.login.LoginException;import oracle.iam.platform.OIMClient;public class OIMConnect {OIMClient client;public void connect(){System.setProperty("java.security.auth.login.config","<oimclient.zip extracted folder>/config/authwl.conf");Hashtable oimenv= new Hashtable();oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,"weblogic.jndi.WLInitialContextFactory" );oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,"t3://<host>:<port>");client= new OIMClient(oimenv);try {client.login("<Username>", "<Password>".toCharArray());System.out.println("Connected");} catch (LoginException e) {e.printStackTrace();}}public void disconnect(){client.logout();System.out.println("Disconnected");}public static void main(String[] args) {OIMConnect oimConn = new OIMConnect();oimConn.connect();oimConn.disconnect();}}
4) Running and testing
Test results:
Test results:
Connected
Disconnected
5) Possible errors
- javax.security.auth.login.LoginException: unable to find LoginModule class: weblogic.security.auth.login.UsernamePasswordLoginModule
- wlfullclient.jar is missing in the buildpath
- javax.security.auth.login.LoginException: java.net.ConnectException: t3://localhost:14000: Destination unreachable; nested exception is:
- java.net.ConnectException: Connection refused; No available router to destination
- OIM server is not up and running
- hostname or port may be wrong
- Exception in thread "main" java.lang.SecurityException: /oracle/Middleware/Oracle_IDM1/server1/config/authwl.conf (No such file or directory)
- at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:110)
- Wrong path specified for the authwl.conf file
"Destination unreachable; nested exception" error can be due to Proxy settings.
ReplyDeleteOpen Jdev -> Tools -> preferences -> Web Browser and Proxy -> Proxy Settings
Select Manual Proxy settings and provide correct proxy details from your network. If not leave it blank.
Connection worked for me if i leave those fields blank.
One can also try selecting Use Automatic Configuration Script and providing the Proxy URL for your Network.