use of org.forgerock.opendj.ldap.Connection in project OpenAM by OpenRock.
the class Bootstrap method getConfiguration.
/**
* Returns System Property with an URL.
*
* @param bootstrapData an URL that contains information on how to
* fetch the server configuration properties.
* @param reinit <code>true</code> to re initialize the system.
* @throws Exception if properties cannot be loaded.
*/
private static Properties getConfiguration(BootstrapData bootstrapData, boolean reinit, boolean bStartDS) throws Exception {
Properties properties = null;
bootstrapData.initSMS(bStartDS);
if (reinit) {
AdminUtils.initialize();
SMSAuthModule.initialize();
}
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
ServerGroup sg = dsCfg.getServerGroup("sms");
if (sg == null) {
return null;
}
try (ConnectionFactory factory = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN);
Connection conn = factory.getConnection()) {
// Success case. Managed to get connection
} catch (LDAPServiceException e) {
// ignore, DS is down
return null;
}
String dsbasedn = bootstrapData.getUserBaseDN();
String pwd = bootstrapData.getDsameUserPassword();
String dsameUser = "cn=dsameuser,ou=DSAME Users," + dsbasedn;
String instanceName = bootstrapData.getInstanceName();
SSOToken ssoToken = getSSOToken(dsbasedn, dsameUser, JCECrypt.decode(pwd));
try {
properties = ServerConfiguration.getServerInstance(ssoToken, instanceName);
if (properties != null) {
// set debug level to error because debug.message in
// SMSEntry.initializedClass won't work and will print out
// error message. Save the debug level and will be restored
// after SMSEntry.initializedClass.
String debugLevel = (String) properties.get(Constants.SERVICES_DEBUG_LEVEL);
boolean debugSetAtDefault = false;
if (debugLevel == null) {
debugSetAtDefault = true;
}
properties.setProperty(Constants.SERVICES_DEBUG_LEVEL, Debug.STR_ERROR);
SystemProperties.initializeProperties(properties, true, false);
DebugPropertiesObserver debugPO = DebugPropertiesObserver.getInstance();
String serverConfigXML = ServerConfiguration.getServerConfigXML(ssoToken, instanceName);
Crypt.reinitialize();
BootstrapData.loadServerConfigXML(serverConfigXML);
SMSEntry.initializeClass();
if (debugSetAtDefault) {
properties.remove(Constants.SERVICES_DEBUG_LEVEL);
} else {
properties.setProperty(Constants.SERVICES_DEBUG_LEVEL, debugLevel);
}
SystemProperties.initializeProperties(properties, true, true);
String defaultDebugLevel = SystemProperties.getProperties().getProperty(Constants.SERVICES_DEBUG_LEVEL);
if (debugSetAtDefault) {
properties.setProperty(Constants.SERVICES_DEBUG_LEVEL, defaultDebugLevel);
SystemProperties.initializeProperties(properties, true, true);
}
AdminUtils.initialize();
SMSAuthModule.initialize();
debugPO.notifyChanges();
SMSPropertiesObserver.getInstance().notifyChanges();
SystemProperties.setServerInstanceName(instanceName);
// ConfigurationObserver is already added when
// DebugPropertiesObserver.getInstance().notifyChanges();
// is called. Adding again causes 2 notification events
// to be sent.
// ServiceConfigManager scm = new ServiceConfigManager(
// Constants.SVC_NAME_PLATFORM, (SSOToken)
// AccessController.doPrivileged(
// AdminTokenAction.getInstance()));
// scm.addListener(ConfigurationObserver.getInstance());
}
} catch (SMSException e) {
//ignore. product is not configured yet.
System.out.println("Bootstrap.getConfiguration :" + e);
properties = null;
}
return properties;
}
use of org.forgerock.opendj.ldap.Connection in project OpenAM by OpenRock.
the class AMSetupDSConfig method isDITLoaded.
/**
* Check if DS is loaded with OpenAM entries
*
* @param ssl <code>true</code> of directory server is running on LDAPS.
* @return <code>true</code> if Service Schema is loaded into
* Directory Server.
*/
String isDITLoaded(boolean ssl) {
String baseDN = "ou=services," + suffix;
String filter = "(|(ou=DAI)(ou=sunIdentityRepositoryService))";
try (Connection conn = getLDAPConnection(ssl)) {
ConnectionEntryReader results = conn.search(LDAPRequests.newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, filter, "dn"));
return Boolean.toString(results.hasNext());
} catch (LdapException e) {
if (Debug.getInstance(SetupConstants.DEBUG_NAME).messageEnabled()) {
Debug.getInstance(SetupConstants.DEBUG_NAME).message("AMSetupDSConfig.isDITLoaded: LDAP Operation return code: " + e.getResult().getResultCode());
}
return "false";
}
}
use of org.forgerock.opendj.ldap.Connection in project OpenAM by OpenRock.
the class UserIdRepo method loadSchema.
private void loadSchema(Map userRepo, String basedir, ServletContext servletCtx, String strFiles, String type) throws Exception {
try (Connection conn = getLDAPConnection(userRepo)) {
String dbName = getDBName(userRepo, conn);
for (String file : writeSchemaFiles(basedir, dbName, servletCtx, strFiles, userRepo, type)) {
Object[] params = { file };
SetupProgress.reportStart("emb.loadingschema", params);
LdifUtils.createSchemaFromLDIF(file, conn);
SetupProgress.reportEnd("emb.success", null);
File f = new File(file);
f.delete();
}
}
}
use of org.forgerock.opendj.ldap.Connection in project OpenAM by OpenRock.
the class SMSLdapObject method modify.
/**
* Save the entry using the token provided. The principal provided will be
* used to get the proxy connection.
*/
public void modify(SSOToken token, String dn, ModificationItem[] mods) throws SMSException, SSOException {
int retry = 0;
ModifyRequest request = copyModItemsToModifyRequest(DN.valueOf(dn), mods);
while (retry <= connNumRetry) {
debug.message("SMSLdapObject.modify() retry: {}", retry);
try (Connection conn = getConnection(token.getPrincipal())) {
conn.modify(request);
debug.message("SMSLdapObject.modify(): Successfully modified entry: {}", dn);
break;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
debug.error("SMSLdapObject.modify(): Error modifying: {} By Principal {}", dn, token.getPrincipal().getName(), e);
throw new SMSException(e, "sms-entry-cannot-modify");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
// ignored
}
}
}
}
use of org.forgerock.opendj.ldap.Connection in project OpenAM by OpenRock.
the class SMSLdapObject method getSubEntries.
private Set<String> getSubEntries(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
SearchRequest request = getSearchRequest(dn, filter, SearchScope.SINGLE_LEVEL, numOfEntries, 0, sortResults, ascendingOrder, getNamingAttribute(), O_ATTR);
int retry = 0;
Set<String> answer = new LinkedHashSet<>();
ConnectionEntryReader results;
while (retry <= connNumRetry) {
debug.message("SMSLdapObject.subEntries() retry: {}", retry);
try (Connection conn = getConnection(token.getPrincipal())) {
// Get the sub entries
ConnectionEntryReader iterResults = conn.search(request);
iterResults.hasNext();
results = iterResults;
// Construct the results and return
try {
while (results != null && results.hasNext()) {
try {
if (results.isReference()) {
debug.warning("Skipping reference result: {}", results.readReference());
continue;
}
SearchResultEntry entry = results.readEntry();
// Workaround for 3823, where (objectClass=*) is used
if (entry.getName().toString().toLowerCase().startsWith("ou=")) {
answer.add(entry.getName().rdn().getFirstAVA().getAttributeValue().toString());
}
} catch (SearchResultReferenceIOException e) {
debug.error("SMSLdapObject.subEntries: Reference should be handled already for dn {}", dn, e);
}
}
} catch (LdapException e) {
debug.warning("SMSLdapObject.subEntries: Error in obtaining sub-entries: {}", dn, e);
throw new SMSException(e, "sms-entry-cannot-obtain");
}
break;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
debug.message("SMSLdapObject.subEntries(): entry not present: {}", dn);
break;
}
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
debug.warning("SMSLdapObject.subEntries: Unable to search for sub-entries: {}", dn, e);
throw new SMSException(e, "sms-entry-cannot-search");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
// ignored
}
}
}
debug.message("SMSLdapObject.subEntries: Successfully obtained sub-entries for {}", dn);
return answer;
}
Aggregations