JPS Credential Store API To Search JpsCredentialStore Operations and Create Map


package com.jps;

import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.remote.JMXConnector;

import com.connection.GetJMXConnector;

import oracle.security.jps.mas.mgmt.jmx.credstore.PortableCredentialMap;
import oracle.security.jps.mas.mgmt.jmx.credstore.PortablePasswordCredential;
public class JPSCredentialStoreAPIToCreateMap {
 public static void main(String[] args) throws Exception {
  
 JMXConnector connector = GetJMXConnector.getJMXConnection();
  MBeanServerConnection conn = connector.getMBeanServerConnection();

  ObjectName name = new ObjectName("com.oracle.jps:type=JpsCredentialStore");

  MBeanInfo mbi = conn.getMBeanInfo(name);
  MBeanOperationInfo[] mboarr = mbi.getOperations();
  System.out.println(" JpsCredentialStore Operations Are -> ");
  for (int i = 0; i < mboarr.length; i++) {
   MBeanOperationInfo mbo = mboarr[i];
   System.out.println(mbo.getName());
  }

  String ALIAS = "oim";
  String KEY="Custom-keystore.jks";
    /*MBean Name com.oracle.jps:type=JpsCredentialStore
    Operation Name containsMap
    Description Returns true if a map associated with the specified alias exist in this store.
    Return Type boolean*/
  boolean containsMap = (Boolean) conn.invoke(name, "containsMap",
    new Object[] { ALIAS }, new String[] { String.class
      .getName() });

  
  PortableCredentialMap pcm = null;
  /*MBean Name com.oracle.jps:Location=oim_server1,type=JpsCredentialStore
    Operation Name getPortableCredentialMap
    Description Returns the Map of Credential objects associated with the specified alias.
    Return Type javax.management.openmbean.CompositeData*/
  if (containsMap) {
   CompositeData cd = (CompositeData) conn.invoke(name,
     "getPortableCredentialMap", new Object[] { ALIAS },
     new String[] { String.class.getName() });
   
   pcm = PortableCredentialMap.from(cd);
  } else {
   pcm = new PortableCredentialMap();
  }
  
  PortablePasswordCredential pc = new PortablePasswordCredential("IDENTITY1", "Welcome1".toCharArray());
  pcm.setPortableCredential(KEY, pc);
  
 }
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts