Search in sources :

Example 6 with DSConfigMgr

use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.

the class DataLayer method initLdapPool.

/**
     * Initialize the pool shared by all DataLayer object(s).
     */
private synchronized void initLdapPool() throws UMSException {
    // Don't do anything if pool is already initialized
    if (_ldapPool != null)
        return;
    /*
         * Initialize the pool with minimum and maximum connections settings
         * retrieved from configuration
         */
    ServerInstance svrCfg = null;
    String hostName = null;
    try {
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        hostName = dsCfg.getHostName("default");
        baseFactory = dsCfg.getNewProxyConnectionFactory();
        svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_PROXY);
    } catch (LDAPServiceException ex) {
        debug.error("Error initializing connection pool " + ex.getMessage());
    }
    // Check if svrCfg was successfully obtained
    if (svrCfg == null) {
        debug.error("Error getting server config.");
        String[] args = new String[1];
        args[0] = hostName == null ? "default" : hostName;
        throw new UMSException(i18n.getString(IUMSConstants.NEW_INSTANCE_FAILED, args));
    }
    int poolMin = svrCfg.getMinConnections();
    int poolMax = svrCfg.getMaxConnections();
    m_releaseConnectionBeforeSearchCompletes = svrCfg.getBooleanValue(LDAP_RELEASECONNBEFORESEARCH, false);
    if (debug.messageEnabled()) {
        debug.message("Creating ldap connection pool with: poolMin {}, poolMax {}", poolMin, poolMax);
    }
    int idleTimeout = SystemProperties.getAsInt(Constants.LDAP_CONN_IDLE_TIME_IN_SECS, 0);
    if (idleTimeout == 0) {
        debug.warning("Idle timeout not set. Defaulting to 0.");
    }
    _ldapPool = Connections.newCachedConnectionPool(Connections.newNamedConnectionFactory(baseFactory, "DataLayer"), poolMin, poolMax, idleTimeout, TimeUnit.SECONDS);
    ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
    shutdownMan.addShutdownListener(new ShutdownListener() {

        public void shutdown() {
            if (_ldapPool != null) {
                _ldapPool.close();
            }
        }
    });
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ByteString(org.forgerock.opendj.ldap.ByteString) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 7 with DSConfigMgr

use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.

the class DataLayer method getInstance.

/**
     * Create the singleton DataLayer object if it doesn't exist already.
     * Assumes the server instance for "LDAPUser.Type.AUTH_PROXY".
     *
     * @supported.api
     */
public static DataLayer getInstance() throws UMSException {
    // Make sure only one instance of this class is created.
    if (m_instance == null) {
        try {
            DSConfigMgr cfgMgr = DSConfigMgr.getDSConfigMgr();
            ServerInstance serverCfg = cfgMgr.getServerInstance(LDAPUser.Type.AUTH_PROXY);
            m_instance = getInstance(serverCfg);
        } catch (LDAPServiceException ex) {
            debug.error("Error:  Unable to get server config instance " + ex.getMessage());
        }
    }
    return m_instance;
}
Also used : DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 8 with DSConfigMgr

use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.

the class Agent method federationConfig.

public static int federationConfig(SSOServerRealmFedInfo srfi) {
    String classMethod = "Agent.federationConfig:";
    Date startDate = new Date();
    String realm = srfi.realmName;
    Integer ri = getRealmIndexFromName(realm);
    Set<String> cots = srfi.cots;
    Map<String, Map<String, String>> saml2Ents = srfi.samlv2Ents;
    Map<String, Map<String, String>> wsEnts = srfi.wsEnts;
    Map<String, Map<String, String>> idffEnts = srfi.idffEnts;
    Map<String, Map<String, Set<String>>> cotMembs = srfi.membEnts;
    StringBuilder sb = new StringBuilder(classMethod);
    if (debug.messageEnabled()) {
        sb.append("fed entities for realm ").append(realm).append(":\n");
        sb.append("  Circle of Trusts set has ");
    }
    if (server == null) {
        // can't do anything without a server
        debug.error(classMethod + "no server");
        return -1;
    }
    SsoServerFedCOTs ssfc = getFedCOTsMBean();
    if ((cots != null) && (cots.size() > 0)) {
        if (debug.messageEnabled()) {
            sb.append(cots.size()).append(" entries:\n");
        }
        TableSsoServerFedCOTsTable ftab = null;
        try {
            ftab = ssfc.accessSsoServerFedCOTsTable();
        } catch (SnmpStatusException ex) {
            debug.error(classMethod + "getting fed COTs table: ", ex);
        }
        if (ftab != null) {
            int i = 1;
            for (String ss : cots) {
                ss = getEscapedString(ss);
                if (debug.messageEnabled()) {
                    sb.append("  #").append(i).append(": ").append(ss).append("\n");
                }
                SsoServerFedCOTsEntryImpl cei = new SsoServerFedCOTsEntryImpl(sunMib);
                cei.SsoServerRealmIndex = ri;
                cei.FedCOTName = ss;
                cei.FedCOTIndex = new Integer(i++);
                ObjectName oname = cei.createSsoServerFedCOTsEntryObjectName(server);
                if (oname == null) {
                    debug.error(classMethod + "Error creating object for Fed COT '" + ss + "'");
                    continue;
                }
                try {
                    ftab.addEntry(cei, oname);
                    if (cei != null) {
                        server.registerMBean(cei, oname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + ss, ex);
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + ss, ex);
                }
            }
        } else {
            if (debug.messageEnabled()) {
                sb.append("no entries\n");
            }
        }
    }
    /*
         *  the federation entities all go into the
         *  SsoServerFedEntitiesTable
         */
    SsoServerFedEntities ssfe = getFedEntsMBean();
    TableSsoServerFedEntitiesTable ftab = null;
    try {
        ftab = ssfe.accessSsoServerFedEntitiesTable();
    } catch (SnmpStatusException ex) {
        debug.error(classMethod + "getting FederationEntities table: ", ex);
        // can't proceed without the table
        return -1;
    }
    if (ftab != null) {
        /*
             *  the SAML2 entities map:
             *    entity name -> hashmap of:
             *      key="location"; value="hosted" or "remote"
             *      key="roles"; value=some combo of IDP;SP
             */
        // increments for all entries
        int tabinx = 1;
        if (debug.messageEnabled()) {
            sb.append("\n  SAML2 entities map has ");
        }
        if ((saml2Ents != null) && (saml2Ents.size() > 0)) {
            TableSsoServerSAML2IDPTable iTab = null;
            TableSsoServerSAML2SPTable sTab = null;
            SsoServerSAML2SvcImpl ss2s = getSaml2SvcMBean();
            try {
                iTab = ss2s.accessSsoServerSAML2IDPTable();
                sTab = ss2s.accessSsoServerSAML2SPTable();
            } catch (SnmpStatusException ex) {
                debug.error(classMethod + "getting SAML2 IDP and/or SP tables: ", ex);
                // can't proceed without the tables
                return -1;
            }
            if (debug.messageEnabled()) {
                sb.append(saml2Ents.size()).append(" entries:\n");
            }
            Set ks = saml2Ents.keySet();
            int idpi = 1;
            int spi = 1;
            for (Map.Entry<String, Map<String, String>> entry : saml2Ents.entrySet()) {
                String entname = entry.getKey();
                Map<String, String> hm = entry.getValue();
                String loc = hm.get("location");
                String roles = hm.get("roles");
                SsoServerFedEntitiesEntryImpl cei = new SsoServerFedEntitiesEntryImpl(sunMib);
                cei.SsoServerRealmIndex = ri;
                cei.FedEntityName = getEscapedString(entname);
                cei.FedEntityIndex = new Integer(tabinx++);
                cei.FedEntityProto = "SAMLv2";
                cei.FedEntityType = roles;
                cei.FedEntityLoc = loc;
                ObjectName oname = cei.createSsoServerFedEntitiesEntryObjectName(server);
                if (oname == null) {
                    debug.error(classMethod + "Error creating object for SAML2 Entity '" + entname + "'");
                    continue;
                }
                try {
                    ftab.addEntry(cei, oname);
                    if (cei != null) {
                        server.registerMBean(cei, oname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + "JMEx adding SAMLv2 entity " + entname + " in realm " + realm, ex);
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + "SnmpEx adding SAMLv2 entity " + entname + " in realm " + realm, ex);
                }
                /*
                     * these also need to be added to either (possibly
                     * both if in both roles?) SAML2's IDP or SP table
                     */
                if (((roles.indexOf("IDP")) >= 0) && loc.equalsIgnoreCase("hosted")) {
                    if (iTab == null) {
                        continue;
                    }
                    SsoServerSAML2IDPEntryImpl sei = new SsoServerSAML2IDPEntryImpl(sunMib);
                    sei.SAML2IDPArtifactsIssued = 0L;
                    sei.SAML2IDPAssertionsIssued = 0L;
                    sei.SAML2IDPInvalRqtsRcvd = 0L;
                    sei.SAML2IDPRqtsRcvd = 0L;
                    sei.SAML2IDPArtifactsInCache = 0L;
                    sei.SAML2IDPAssertionsInCache = 0L;
                    sei.SAML2IDPIndex = new Integer(idpi++);
                    sei.SAML2IDPName = getEscapedString(entname);
                    sei.SsoServerRealmIndex = ri;
                    oname = sei.createSsoServerSAML2IDPEntryObjectName(server);
                    ss2s.incHostedIDPCount();
                    try {
                        iTab.addEntry(sei, oname);
                        if (sei != null) {
                            server.registerMBean(sei, oname);
                        }
                        /* is a Map of realm/saml2idp to index needed? */
                        String rai = realm + "|" + entname;
                        // sei is this bean's instance
                        realmSAML2IDPs.put(rai, sei);
                    } catch (JMException ex) {
                        debug.error(classMethod + "JMEx adding SAMLv2 IDP entity " + entname + " in realm " + realm, ex);
                    } catch (SnmpStatusException ex) {
                        debug.error(classMethod + "SnmpEx adding SAMLv2 IDP entity " + entname + " in realm " + realm, ex);
                    }
                }
                if (((roles.indexOf("IDP")) >= 0) && loc.equalsIgnoreCase("remote")) {
                    ss2s.incRemoteIDPCount();
                }
                if (((roles.indexOf("SP")) >= 0) && loc.equalsIgnoreCase("hosted")) {
                    if (sTab == null) {
                        continue;
                    }
                    SsoServerSAML2SPEntryImpl sei = new SsoServerSAML2SPEntryImpl(sunMib);
                    sei.SAML2SPInvalidArtifactsRcvd = 0L;
                    sei.SAML2SPValidAssertionsRcvd = 0L;
                    sei.SAML2SPRqtsSent = 0L;
                    sei.SAML2SPName = getEscapedString(entname);
                    sei.SsoServerRealmIndex = ri;
                    sei.SAML2SPIndex = new Integer(spi++);
                    oname = sei.createSsoServerSAML2SPEntryObjectName(server);
                    try {
                        sTab.addEntry(sei, oname);
                        if (sei != null) {
                            server.registerMBean(sei, oname);
                        }
                        /* is a Map of realm/saml2sp to index needed? */
                        String rai = realm + "|" + entname;
                        // sei is this bean's instance
                        realmSAML2SPs.put(rai, sei);
                    } catch (JMException ex) {
                        debug.error(classMethod + "JMEx adding SAMLv2 SP entity " + entname + " in realm " + realm, ex);
                    } catch (SnmpStatusException ex) {
                        debug.error(classMethod + "SnmpEx adding SAMLv2 SP entity " + entname + " in realm " + realm, ex);
                    }
                }
                if (debug.messageEnabled()) {
                    sb.append("    name=").append(entname).append(", loc=").append(loc).append(", roles=").append(roles).append("\n");
                }
            }
        } else {
            if (debug.messageEnabled()) {
                sb.append("no entries\n");
            }
        }
        /*
             *  the WSFed entities map:
             *    entity name -> hashmap of:
             *      key="location"; value="hosted" or "remote"
             *      key="roles"; value=some combo of IDP;SP
             */
        if (debug.messageEnabled()) {
            sb.append("\n  WSFed entities map has ");
        }
        if ((wsEnts != null) && (wsEnts.size() > 0)) {
            if (debug.messageEnabled()) {
                sb.append(wsEnts.size()).append(" entries:\n");
            }
            for (Map.Entry<String, Map<String, String>> entry : wsEnts.entrySet()) {
                String entname = entry.getKey();
                Map<String, String> hm = entry.getValue();
                String loc = hm.get("location");
                String roles = hm.get("roles");
                SsoServerFedEntitiesEntryImpl cei = new SsoServerFedEntitiesEntryImpl(sunMib);
                cei.SsoServerRealmIndex = ri;
                cei.FedEntityName = getEscapedString(entname);
                cei.FedEntityIndex = new Integer(tabinx++);
                cei.FedEntityProto = "WSFed";
                cei.FedEntityType = roles;
                cei.FedEntityLoc = loc;
                ObjectName oname = cei.createSsoServerFedEntitiesEntryObjectName(server);
                if (oname == null) {
                    debug.error(classMethod + "Error creating object for WSFed Entity '" + entname + "'");
                    continue;
                }
                try {
                    ftab.addEntry(cei, oname);
                    if (cei != null) {
                        server.registerMBean(cei, oname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + "JMEx adding WSFed entity " + entname + " in realm " + realm, ex);
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + "SnmpEx adding WSFed entity " + entname + " in realm " + realm, ex);
                }
                sb.append("    name=").append(entname).append(", loc=").append(loc).append(", roles=").append(roles).append("\n");
            }
        } else {
            if (debug.messageEnabled()) {
                sb.append("no entries\n");
            }
        }
        /*
             *  the IDFF entities map:
             *    entity name -> hashmap of:
             *      key="location"; value="hosted" or "remote"
             *      key="roles"; value=some combo of IDP;SP
             */
        if (debug.messageEnabled()) {
            sb.append("\n  IDFF entities map has ");
        }
        if ((idffEnts != null) && (idffEnts.size() > 0)) {
            if (debug.messageEnabled()) {
                sb.append(idffEnts.size()).append(" entries:\n");
            }
            for (Map.Entry<String, Map<String, String>> entry : idffEnts.entrySet()) {
                String entname = entry.getKey();
                Map<String, String> hm = entry.getValue();
                String loc = hm.get("location");
                String roles = hm.get("roles");
                SsoServerFedEntitiesEntryImpl cei = new SsoServerFedEntitiesEntryImpl(sunMib);
                cei.SsoServerRealmIndex = ri;
                cei.FedEntityName = getEscapedString(entname);
                cei.FedEntityIndex = new Integer(tabinx++);
                cei.FedEntityProto = "IDFF";
                cei.FedEntityType = roles;
                cei.FedEntityLoc = loc;
                ObjectName oname = cei.createSsoServerFedEntitiesEntryObjectName(server);
                if (oname == null) {
                    debug.error(classMethod + "Error creating object for IDFF Entity '" + entname + "'");
                    continue;
                }
                try {
                    ftab.addEntry(cei, oname);
                    if (cei != null) {
                        server.registerMBean(cei, oname);
                    }
                } catch (JMException ex) {
                    debug.error(classMethod + "JMEx adding IDFF entity " + entname + " in realm " + realm, ex);
                } catch (SnmpStatusException ex) {
                    debug.error(classMethod + "SnmpEx adding IDFF entity " + entname + " in realm " + realm, ex);
                }
                if (debug.messageEnabled()) {
                    sb.append("    name=").append(entname).append(", loc=").append(loc).append(", roles=").append(roles).append("\n");
                }
            }
        } else {
            if (debug.messageEnabled()) {
                sb.append("no entries\n");
            }
        }
    } else {
        debug.error(classMethod + "FederationEntities table is null");
    }
    /*
         *  the COT members map:
         *    cot name -> hashmap of:
         *      key="SAML"; value=Set of member names
         *      key="IDFF"; value=Set of member names
         *      key="WSFed"; value=Set of member names
         */
    if (debug.messageEnabled()) {
        sb.append("\n  COT Members map has ");
    }
    if ((cotMembs != null) && (cotMembs.size() > 0)) {
        if (debug.messageEnabled()) {
            sb.append(cotMembs.size()).append(" entries:\n");
        }
        int coti = 1;
        TableSsoServerFedCOTMemberTable mtab = null;
        try {
            mtab = ssfc.accessSsoServerFedCOTMemberTable();
        } catch (SnmpStatusException ex) {
            debug.error(classMethod + "getting fed COT members table: ", ex);
        }
        for (Map.Entry<String, Map<String, Set<String>>> entry : cotMembs.entrySet()) {
            String cotname = entry.getKey();
            Map<String, Set<String>> hm = entry.getValue();
            cotname = getEscapedString(cotname);
            if (debug.messageEnabled()) {
                sb.append("  COT name = ").append(cotname).append(", SAML members = ");
            }
            Set<String> fset = hm.get("SAML");
            int mi = 1;
            Integer cotI = new Integer(coti++);
            if ((fset != null) && fset.size() > 0) {
                for (String mbm : fset) {
                    if (debug.messageEnabled()) {
                        sb.append("    ").append(mbm).append("\n");
                    }
                    SsoServerFedCOTMemberEntryImpl cmi = new SsoServerFedCOTMemberEntryImpl(sunMib);
                    cmi.FedCOTMemberType = "SAMLv2";
                    cmi.FedCOTMemberName = getEscapedString(mbm);
                    cmi.FedCOTMemberIndex = new Integer(mi++);
                    cmi.SsoServerRealmIndex = ri;
                    // xxx - need to get from tbl
                    cmi.FedCOTIndex = cotI;
                    ObjectName ceName = cmi.createSsoServerFedCOTMemberEntryObjectName(server);
                    if (ceName == null) {
                        debug.error(classMethod + "Error creating object for SAMLv2 COT Member '" + mbm + "'");
                        continue;
                    }
                    try {
                        mtab.addEntry(cmi, ceName);
                        if (ceName != null) {
                            server.registerMBean(cmi, ceName);
                        }
                    } catch (Exception ex) {
                        debug.error(classMethod + "cotmember = " + mbm, ex);
                    }
                }
            } else {
                if (debug.messageEnabled()) {
                    sb.append("    NONE\n");
                }
            }
            fset = hm.get("IDFF");
            if (debug.messageEnabled()) {
                sb.append("    IDFF members = ");
            }
            if ((fset != null) && fset.size() > 0) {
                for (String mbm : fset) {
                    if (debug.messageEnabled()) {
                        sb.append("    ").append(mbm).append("\n");
                    }
                    SsoServerFedCOTMemberEntryImpl cmi = new SsoServerFedCOTMemberEntryImpl(sunMib);
                    cmi.FedCOTMemberType = "IDFF";
                    cmi.FedCOTMemberName = getEscapedString(mbm);
                    cmi.FedCOTMemberIndex = new Integer(mi++);
                    cmi.SsoServerRealmIndex = ri;
                    // xxx - need to get from tbl
                    cmi.FedCOTIndex = cotI;
                    ObjectName ceName = cmi.createSsoServerFedCOTMemberEntryObjectName(server);
                    if (ceName == null) {
                        debug.error(classMethod + "Error creating object for IDFF COT Member '" + mbm + "'");
                        continue;
                    }
                    try {
                        mtab.addEntry(cmi, ceName);
                        if (ceName != null) {
                            server.registerMBean(cmi, ceName);
                        }
                    } catch (Exception ex) {
                        debug.error(classMethod + "cotmember = " + mbm, ex);
                    }
                }
            } else {
                if (debug.messageEnabled()) {
                    sb.append("    NONE\n");
                }
            }
            fset = hm.get("WSFed");
            if (debug.messageEnabled()) {
                sb.append("    WSFed members = ");
            }
            if ((fset != null) && fset.size() > 0) {
                for (String mbm : fset) {
                    if (debug.messageEnabled()) {
                        sb.append("    ").append(mbm).append("\n");
                    }
                    SsoServerFedCOTMemberEntryImpl cmi = new SsoServerFedCOTMemberEntryImpl(sunMib);
                    cmi.FedCOTMemberType = "WSFed";
                    cmi.FedCOTMemberName = getEscapedString(mbm);
                    cmi.FedCOTMemberIndex = new Integer(mi++);
                    cmi.SsoServerRealmIndex = ri;
                    // xxx - need to get from tbl
                    cmi.FedCOTIndex = cotI;
                    ObjectName ceName = cmi.createSsoServerFedCOTMemberEntryObjectName(server);
                    if (ceName == null) {
                        debug.error(classMethod + "Error creating object for WSFed Member '" + mbm + "'");
                        continue;
                    }
                    try {
                        mtab.addEntry(cmi, ceName);
                        if (ceName != null) {
                            server.registerMBean(cmi, ceName);
                        }
                    } catch (Exception ex) {
                        debug.error(classMethod + "cotmember = " + mbm, ex);
                    }
                }
            } else {
                if (debug.messageEnabled()) {
                    sb.append("    NONE\n");
                }
            }
        }
    }
    if (debug.messageEnabled()) {
        debug.message(sb.toString());
    }
    /*
         *  have to do it here?
         */
    if (debug.messageEnabled()) {
        try {
            DSConfigMgr dscm = DSConfigMgr.getDSConfigMgr();
            ServerGroup sgrp = dscm.getServerGroup("sms");
            Collection<Server> slist = sgrp.getServersList();
            StringBuilder sbp1 = new StringBuilder("DSConfigMgr:\n");
            for (Server sobj : slist) {
                String svr = sobj.getServerName();
                int port = sobj.getPort();
                sbp1.append("  svrname = ").append(svr).append(", port = ").append(port).append("\n");
            }
            debug.message(classMethod + sbp1.toString());
        } catch (Exception d) {
            debug.message(classMethod + "trying to get Directory Server Config");
        }
        Properties props = SystemProperties.getProperties();
        StringBuilder sbp = new StringBuilder("SYSPROPS:\n");
        for (Map.Entry<Object, Object> entry : props.entrySet()) {
            String entname = (String) entry.getKey();
            String val = (String) entry.getValue();
            sbp.append("  key = ").append(entname).append(", val = ").append(val).append("\n");
        }
        debug.message(classMethod + sbp.toString());
        String dirHost = SystemProperties.get(Constants.AM_DIRECTORY_HOST);
        String dirPort = SystemProperties.get(Constants.AM_DIRECTORY_PORT);
        String drSSL = SystemProperties.get(Constants.AM_DIRECTORY_SSL_ENABLED);
        boolean dirSSL = SystemProperties.getAsBoolean(Constants.AM_DIRECTORY_SSL_ENABLED);
        debug.message(classMethod + "SMS CONFIG:\n    host = " + dirHost + "\n    port = " + dirPort + "\n    ssl = " + drSSL + "\n    dirSSL = " + dirSSL);
        Date stopDate = new Date();
        String stDate = sdf.format(startDate);
        String endDate = sdf.format(stopDate);
        debug.message("Agent.federationConfig:\n    Start Time = " + stDate + "\n      End Time = " + endDate);
    }
    return 0;
}
Also used : Set(java.util.Set) ServerGroup(com.iplanet.services.ldap.ServerGroup) JMXConnectorServer(javax.management.remote.JMXConnectorServer) HtmlAdaptorServer(com.sun.jdmk.comm.HtmlAdaptorServer) SnmpAdaptorServer(com.sun.management.comm.SnmpAdaptorServer) Server(com.iplanet.services.ldap.Server) MBeanServer(javax.management.MBeanServer) SystemProperties(com.iplanet.am.util.SystemProperties) Properties(java.util.Properties) SnmpStatusException(com.sun.management.snmp.SnmpStatusException) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) Date(java.util.Date) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) RuntimeOperationsException(javax.management.RuntimeOperationsException) SnmpStatusException(com.sun.management.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMException(javax.management.JMException) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with DSConfigMgr

use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.

the class LDAPEventManager method getBase.

/**
     * Returns the base DN for the persistent searches. Since this function
     * can be called asynchronously by the EventService, should not have
     * dependency on any classes in SMS package.
     * @see com.iplanet.services.ldap.event.IDSEventListener#getBase()
     */
public String getBase() {
    if (baseDN != null) {
        return (baseDN);
    }
    try {
        // Obtain server instance for SMS, group=sms get baseDN
        // else use the default group
        ServerInstance serverInstance = null;
        DSConfigMgr mgr = DSConfigMgr.getDSConfigMgr();
        if (mgr != null) {
            // Try SMS first
            serverInstance = mgr.getServerInstance("sms", LDAPUser.Type.AUTH_PROXY);
            if (serverInstance == null) {
                serverInstance = mgr.getServerInstance(LDAPUser.Type.AUTH_PROXY);
                if (debug.messageEnabled()) {
                    debug.message("LDAPEventManager: SMS servergroup " + "not available. Using default AMSDK DN");
                }
            }
            if (serverInstance != null) {
                baseDN = serverInstance.getBaseDN();
            } else {
                if (debug.warningEnabled()) {
                    debug.warning("LDAPEventManager: SMS & AMSDK " + "servergroup not available. Using hardcoded value");
                }
            }
        } else {
            if (debug.warningEnabled()) {
                debug.warning("LDAPEventManager: DSConfigMgr is NULL " + "Using hardcoded value");
            }
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("LDAPEventManager: Exception obtaing baseDN " + "from DSConfigMgr and ServerInstances", e);
        }
    }
    if (baseDN == null) {
        debug.error("LDAPEventManager.getBase(): Unable to get base DN " + " from serverconfig.xml");
    }
    return ((baseDN == null) ? "o=isp" : baseDN);
}
Also used : DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ServerInstance(com.iplanet.services.ldap.ServerInstance) EventException(com.iplanet.services.ldap.event.EventException) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 10 with DSConfigMgr

use of com.iplanet.services.ldap.DSConfigMgr in project OpenAM by OpenRock.

the class SMDataLayer method initLdapPool.

/**
     * Initialize the pool shared by all SMDataLayer object(s).
     */
private synchronized void initLdapPool() {
    // Dont' do anything if pool is already initialized
    if (_ldapPool != null)
        return;
    // Initialize the pool with minimum and maximum connections settings
    // retrieved from configuration
    ServerInstance svrCfg;
    try {
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        // Get "sms" ServerGroup if present
        ServerGroup sg = dsCfg.getServerGroup("sms");
        final ConnectionFactory baseFactory;
        if (sg != null) {
            baseFactory = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN);
            svrCfg = sg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        } else {
            baseFactory = dsCfg.getNewAdminConnectionFactory();
            svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        }
        if (svrCfg == null) {
            debug.error("SMDataLayer:initLdapPool()-" + "Error getting server config.");
        }
        int poolMin = 1;
        int poolMax = 2;
        // Initialize the Connection Pool size only for the server
        if (SystemProperties.isServerMode()) {
            poolMin = svrCfg.getMinConnections();
            poolMax = svrCfg.getMaxConnections();
        }
        debug.message("SMDataLayer:initLdapPool(): Creating ldap connection pool with: poolMin {} poolMax {}", poolMin, poolMax);
        int idleTimeout = SystemProperties.getAsInt(LDAP_CONN_IDLE_TIME_IN_SECS, 0);
        if (idleTimeout == 0 && StringUtils.isNotBlank(SystemProperties.get(LDAP_CONN_IDLE_TIME_IN_SECS))) {
            debug.error("SMDataLayer: Idle timeout could not be parsed, connection reaping is disabled");
        } else if (idleTimeout == 0) {
            debug.message("SMDataLayer: Idle timeout is set to 0 - connection reaping is disabled");
        }
        _ldapPool = Connections.newCachedConnectionPool(baseFactory, poolMin, poolMax, idleTimeout, TimeUnit.SECONDS);
        ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
        shutdownMan.addShutdownListener(new ShutdownListener() {

            public void shutdown() {
                if (_ldapPool != null) {
                    _ldapPool.close();
                }
            }
        });
    } catch (LDAPServiceException ex) {
        debug.error("SMDataLayer:initLdapPool()-" + "Error initializing connection pool " + ex.getMessage());
        ex.printStackTrace();
    }
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) ServerGroup(com.iplanet.services.ldap.ServerGroup) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

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