Wednesday, 19 February 2014

Check OID connection programmatically

This snippet of code allow us to check whether the connection to an OID Identity store is available.

import oracle.security.jps.JpsContext;
import oracle.security.jps.JpsContextFactory;
import oracle.security.jps.JpsException;
import oracle.security.jps.service.idstore.IdentityStoreService;

/**
  * Method to check that I can connect to OID Server. If I can get a
  * valid Identity Store means that there is a valid connection.
  */
private boolean oidUpAndRunning() {
    logger.info("Checking that OID is up and running...");
    try {
 getStoreService().getIdmStore();
 return true;
    } catch (JpsException e) {
 e.printStackTrace();
 return false;
    }
}

/**
 * Get an Identity Store Service from the JPS Context.
 */
public IdentityStoreService getStoreService() throws JpsException {
    JpsContextFactory ctxf = JpsContextFactory.getContextFactory();
    JpsContext ctx = ctxf.getContext();
    return ctx.getServiceInstance(IdentityStoreService.class);
}

No comments:

Post a Comment