Search in sources :

Example 11 with DSConfigMgr

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);
}
Also used : DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ServerConfigurationFactory(org.forgerock.openam.sm.ServerConfigurationFactory) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Example 12 with DSConfigMgr

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);
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Options(org.forgerock.util.Options) Connection(org.forgerock.opendj.ldap.Connection) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ByteString(org.forgerock.opendj.ldap.ByteString) SimpleBindRequest(org.forgerock.opendj.ldap.requests.SimpleBindRequest) ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 13 with DSConfigMgr

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");
    }
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) MBeanServer(javax.management.MBeanServer) Iterator(java.util.Iterator) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) Collection(java.util.Collection) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 14 with DSConfigMgr

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;
}
Also used : ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) ServerGroup(com.iplanet.services.ldap.ServerGroup) SSOToken(com.iplanet.sso.SSOToken) DebugPropertiesObserver(com.sun.identity.common.DebugPropertiesObserver) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) SystemProperties(com.iplanet.am.util.SystemProperties) Properties(java.util.Properties)

Example 15 with DSConfigMgr

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);
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceManager(com.sun.identity.sm.ServiceManager) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) AuthContext(com.sun.identity.authentication.internal.AuthContext) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal) ServerInstance(com.iplanet.services.ldap.ServerInstance) FileInputStream(java.io.FileInputStream)

Aggregations

DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)18 ServerInstance (com.iplanet.services.ldap.ServerInstance)13 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)10 ServerGroup (com.iplanet.services.ldap.ServerGroup)8 LdapException (org.forgerock.opendj.ldap.LdapException)5 Connection (org.forgerock.opendj.ldap.Connection)4 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)4 ServerConfigurationFactory (org.forgerock.openam.sm.ServerConfigurationFactory)3 Test (org.testng.annotations.Test)3 SystemProperties (com.iplanet.am.util.SystemProperties)2 Server (com.iplanet.services.ldap.Server)2 SSOToken (com.iplanet.sso.SSOToken)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 MBeanServer (javax.management.MBeanServer)2 LoginException (javax.security.auth.login.LoginException)2 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)2 ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)2 Matchers.anyString (org.mockito.Matchers.anyString)2 EventException (com.iplanet.services.ldap.event.EventException)1