OpenAM Java API : Retrieve LDAP Datastore credentials. When developing plugins in OpenAM, using the Java SDK API, you could need to retrieve some information from a registered LDAP datastore. But in order to do that, you have to extract the directory credentials from OpenAM configuration.

Developing for OpenAM can sometimes be tricky, mainly because there is not so much documentation about it. So, here is a snippet which describes how to retrieve from OpenAM, the connection information of the top realm embedded datastore, for example.

String REPO_NAME = "embedded";
String REALM_NAME = "/";
String SERVICE_NAME = "sunIdentityRepositoryService";

SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
ServiceConfigManager svcCfgMgr = new ServiceConfigManager(IdConstants.REPO_SERVICE, adminToken);

OrganizationConfigManager scm = new OrganizationConfigManager(adminToken, REALM_NAME);
ServiceConfig configServ = scm.getServiceConfig(SERVICE_NAME);
ServiceConfig ss = configServ.getSubConfig(REPO_NAME);
Map attrValues = ss.getAttributes();
String hostPort = CollectionHelper.getMapAttr(attrValues, "sun-idrepo-ldapv3-config-ldap-server");
String login = CollectionHelper.getMapAttr(attrValues, "sun-idrepo-ldapv3-config-authid");
String password = CollectionHelper.getMapAttr(attrValues, "sun-idrepo-ldapv3-config-authpw");
String isSSL = CollectionHelper.getMapAttr(attrValues, "sun-idrepo-ldapv3-config-ssl-enabled")

And if you want to connect to your LDAP directory using the OpenAM Java SDK API, you can use the LDAPConnection class, instead of importing an external LDAP library.

janua
Les derniers articles par janua (tout voir)