Login to Oracle Enterprise Manager Console (http://<hostname>:7001/em).
Expand WebLogic Domain, right click on the name of your domain, go to Security, and then click on Credentials.
You can read keys to existing map or create a new map with new keys. Each key can store credentials. For this example I am using existing map "oracle.wsm.security" and key "OIMAdmin".
Use Case: Read Credential from the Credentials Store in Java Embedding.
Use below code in Java Embedding to read xelsysadm credential and get OIM Client handle.
To execute below code you have to add following jars in <Application_Name><Project_Name>\SCA-INF\lib:
- jps-api.jar
- jps-manifest.jar
- oimclient.jar
String username = null, password = null;
String t3url = "t3://<hostname>:<port>"; //OIM host name and port
String credentialStoreProvider = "oracle.wsm.security"; //Map name
String OIMAdminName = "OIMAdmin"; //Key name
try {
//read xelsysadm credential from credential store
oracle.security.jps.JpsContextFactory jpsCtxFactory = oracle.security.jps.JpsContextFactory.getContextFactory();
oracle.security.jps.JpsContext jpsCtx = jpsCtxFactory.getContext();
oracle.security.jps.service.credstore.CredentialStore credStore = jpsCtx.getServiceInstance(oracle.security.jps.service.credstore.CredentialStore.class);
oracle.security.jps.service.credstore.PasswordCredential cred = (oracle.security.jps.service.credstore.PasswordCredential)credStore.getCredential(credentialStoreProvider,OIMAdminName);
if (cred != null) {
username = cred.getName();
password = String.valueOf(cred.getPassword());
} else {
System.out.println("Credential not found");
}
System.out.println("Username : " + username);
System.out.println("Password : " + password);
//get OIMClient Handle
java.util.Hashtable env = new java.util.Hashtable();
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
oracle.iam.platform.OIMClient client = new oracle.iam.platform.OIMClient(env);
client.login(username, password.toCharArray());
System.out.println("Connected, OIMClient Handle : " + client);
} catch (Exception e) {
e.printStackTrace();
}
No comments:
Post a Comment