use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.
the class ServerConfigurationFactoryTest method shouldIndicateInvalidIfServerGroupIsNull.
@Test(expectedExceptions = ServerConfigurationNotFound.class)
public void shouldIndicateInvalidIfServerGroupIsNull() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound {
// Given
ServerInstance mockInstance = mock(ServerInstance.class);
DSConfigMgr mockConfig = mock(DSConfigMgr.class);
given(mockConfig.getServerGroup(anyString())).willReturn(null);
given(mockConfig.getServerInstance(anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance);
ServerConfigurationFactory parser = new ServerConfigurationFactory(mockConfig);
// When / Then
parser.getServerConfiguration("", LDAPUser.Type.AUTH_ADMIN);
}
use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.
the class DataLayer method changePassword.
/**
* Changes user password.
*
* @param guid globally unique identifier for the entry.
* @param attrName password attribute name
* @param oldPassword old password
* @param newPassword new password
* @exception AccessRightsException if insufficient access
* @exception EntryNotFoundException if the entry is not found.
* @exception UMSException if failure
*
* @supported.api
*/
public void changePassword(Guid guid, String attrName, String oldPassword, String newPassword) throws UMSException {
Modification modification = new Modification(ModificationType.REPLACE, Attributes.singletonAttribute(attrName, newPassword));
String id = guid.getDn();
try {
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
String hostAndPort = dsCfg.getHostName("default");
// All connections will use authentication
SimpleBindRequest bindRequest = LDAPRequests.newSimpleBindRequest(id, oldPassword.toCharArray());
Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, bindRequest);
try (ConnectionFactory factory = new LDAPConnectionFactory(hostAndPort, 389, options)) {
Connection ldc = factory.getConnection();
ldc.modify(LDAPRequests.newModifyRequest(id).addModification(modification));
} catch (LdapException ldex) {
if (debug.warningEnabled()) {
debug.warning("DataLayer.changePassword:", ldex);
}
ResultCode errorCode = ldex.getResult().getResultCode();
if (ResultCode.NO_SUCH_OBJECT.equals(errorCode)) {
throw new EntryNotFoundException(id, ldex);
} else if (ResultCode.INSUFFICIENT_ACCESS_RIGHTS.equals(errorCode)) {
throw new AccessRightsException(id, ldex);
} else {
throw new UMSException(id, ldex);
}
}
} catch (LDAPServiceException ex) {
debug.error("DataLayer.changePassword:", ex);
throw new UMSException(id, ex);
}
}
use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.
the class SsoServerSvcMgmtSvcImpl method init.
private void init(SnmpMib myMib, MBeanServer server) {
if (debug == null) {
debug = Debug.getInstance("amMonitoring");
}
String classMethod = "SsoServerSvcMgmtSvcImpl.init:";
boolean dsEmbedded = Agent.getDsIsEmbedded();
String dirSSL = SystemProperties.get(Constants.AM_DIRECTORY_SSL_ENABLED);
String dsType = "embedded";
if (!dsEmbedded) {
dsType = "remote";
}
try {
DSConfigMgr dscm = DSConfigMgr.getDSConfigMgr();
ServerGroup sgrp = dscm.getServerGroup("sms");
Collection slist = sgrp.getServersList();
StringBuffer sbp1 = new StringBuffer("DSConfigMgr:\n");
int port = 0;
String svr = null;
for (Iterator it = slist.iterator(); it.hasNext(); ) {
Server sobj = (Server) it.next();
svr = sobj.getServerName();
port = sobj.getPort();
if (debug.messageEnabled()) {
sbp1.append(" svrname = ").append(svr).append(", port = ").append(port).append("\n");
}
}
if (debug.messageEnabled()) {
debug.message(classMethod + sbp1.toString());
}
ServerInstance si = dscm.getServerInstance(LDAPUser.Type.AUTH_BASIC);
String bindDN = si.getAuthID();
String orgDN = si.getBaseDN();
boolean siStat = si.getActiveStatus();
String conntype = si.getConnectionType().toString();
if (debug.messageEnabled()) {
sbp1 = new StringBuffer("ServerInstance:\n");
sbp1.append(" bindDN = ").append(bindDN).append("\n").append(" orgDN = ").append(orgDN).append("\n").append(" active status = ").append(siStat).append("\n").append(" conn type = ").append(conntype).append("\n");
debug.message(classMethod + sbp1.toString());
}
SvcMgmtRepositoryType = dsType;
SvcMgmtStatus = "operational";
if (!siStat) {
SvcMgmtStatus = "dormant";
}
SvcMgmtRepositorySSL = dirSSL;
SvcMgmtRepositoryOrgDN = orgDN;
SvcMgmtRepositoryBindDN = bindDN;
String portS = "0";
try {
portS = Integer.toString(port);
} catch (NumberFormatException nex) {
debug.error(classMethod + "port retrieved invalid (" + port + ": " + nex.getMessage());
}
SvcMgmtRepositoryHostPort = portS;
} catch (Exception d) {
debug.error(classMethod + "trying to get Directory Server Config");
}
}
use of com.iplanet.services.ldap.DSConfigMgr 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 com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.
the class ImportConfig method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.err.println("usage: serverAdmin import xmlFile");
System.exit(1);
}
if (args[0].equals("import")) {
try {
FileInputStream fisSchema = new FileInputStream(args[1]);
DSConfigMgr cfgMgr = DSConfigMgr.getDSConfigMgr();
ServerInstance sInst = cfgMgr.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
authPcpl = new AuthPrincipal(sInst.getAuthID());
AuthContext authCtx = new AuthContext(authPcpl, sInst.getPasswd().toCharArray());
SSOToken userSSOToken = authCtx.getSSOToken();
ServiceManager smsMgr = new ServiceManager(userSSOToken);
smsMgr.registerServices(fisSchema);
} catch (Exception e) {
e.printStackTrace();
System.err.println(e);
}
}
}
Aggregations