Search in sources :

Example 1 with Server

use of com.iplanet.services.ldap.Server 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 2 with Server

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

the class ServerGroupConfiguration method getLDAPURLs.

/**
     * Creates a list of {@link LDAPURL} instances based on the server instances available in the servergroup.
     *
     * @return A non null, but possibly empty list of {@link LDAPURL} instances based on the configured server
     * instances in the corresponding server group.
     */
public Set<LDAPURL> getLDAPURLs() {
    Collection<Server> servers = group.getServersList();
    Set<LDAPURL> ret = new LinkedHashSet<LDAPURL>(servers.size());
    for (Server server : servers) {
        ret.add(LDAPURL.valueOf(server.getServerName(), server.getPort(), Server.Type.CONN_SSL.equals(server.getConnectionType())));
    }
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Server(com.iplanet.services.ldap.Server) LDAPURL(org.forgerock.openam.ldap.LDAPURL)

Example 3 with Server

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

the class ServerGroupConfigurationTest method shouldReturnCorrectLDAPURLforSSLConnections.

@Test
public void shouldReturnCorrectLDAPURLforSSLConnections() {
    // Given
    String hostName = "localhost";
    int port = 389;
    Server one = mock(Server.class);
    given(one.getServerName()).willReturn(hostName);
    given(one.getPort()).willReturn(port);
    given(one.getConnectionType()).willReturn(Server.Type.CONN_SSL);
    ServerInstance mockInstance = mock(ServerInstance.class);
    ServerGroup mockGroup = mock(ServerGroup.class);
    given(mockGroup.getServersList()).willReturn(Arrays.asList(one));
    ServerGroupConfiguration config = new ServerGroupConfiguration(mockGroup, mockInstance);
    // When
    Set<LDAPURL> result = config.getLDAPURLs();
    // Then
    assertThat(result).hasSize(1);
    LDAPURL url = result.iterator().next();
    assertThat(url.getHost()).isEqualTo(hostName);
    assertThat(url.getPort()).isEqualTo(port);
    assertThat(url.isSSL()).isTrue();
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) LDAPURL(org.forgerock.openam.ldap.LDAPURL) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Example 4 with Server

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

the class ServerGroupConfigurationTest method shouldReturnCorrectLDAPURLforSimpleConnections.

@Test
public void shouldReturnCorrectLDAPURLforSimpleConnections() {
    // Given
    String hostName = "localhost";
    int port = 389;
    Server one = mock(Server.class);
    given(one.getServerName()).willReturn(hostName);
    given(one.getPort()).willReturn(port);
    given(one.getConnectionType()).willReturn(Server.Type.CONN_SIMPLE);
    ServerInstance mockInstance = mock(ServerInstance.class);
    ServerGroup mockGroup = mock(ServerGroup.class);
    given(mockGroup.getServersList()).willReturn(Arrays.asList(one));
    ServerGroupConfiguration config = new ServerGroupConfiguration(mockGroup, mockInstance);
    // When
    Set<LDAPURL> result = config.getLDAPURLs();
    // Then
    assertThat(result).hasSize(1);
    LDAPURL url = result.iterator().next();
    assertThat(url.getHost()).isEqualTo(hostName);
    assertThat(url.getPort()).isEqualTo(port);
    assertThat(url.isSSL()).isFalse();
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) LDAPURL(org.forgerock.openam.ldap.LDAPURL) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Example 5 with Server

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

the class BootstrapCreator method getBootStrapURL.

/**
     * Returns the bootstrap url.
     *
     * @param dsCfg instance of the <code>IDSConfigMgr</code> containing
     *              the connection information to the config store.
     * @exception ConfigurationException if there is an error and cannot
     *     obtain the bootstrap URL. This may be due to connection error.
     */
public String getBootStrapURL(IDSConfigMgr dsCfg) throws ConfigurationException {
    String bootstrapStr = null;
    try {
        ServerGroup sg = dsCfg.getServerGroup("sms");
        ServerGroup defaultGroup = dsCfg.getServerGroup("default");
        ServerInstance svrCfg;
        if (sg == null) {
            sg = defaultGroup;
            svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        } else {
            svrCfg = sg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        }
        ServerInstance userInstance = defaultGroup.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        String dsameUserName = userInstance.getAuthID();
        String dsameUserPwd = JCECrypt.encode(userInstance.getPasswd());
        String connDN = svrCfg.getAuthID();
        String connPwd = JCECrypt.encode(svrCfg.getPasswd());
        String rootSuffix = svrCfg.getBaseDN();
        Collection serverList = sg.getServersList();
        StringBuilder bootstrap = new StringBuilder();
        for (Iterator i = serverList.iterator(); i.hasNext(); ) {
            Server serverObj = (Server) i.next();
            Server.Type connType = serverObj.getConnectionType();
            String proto = (connType.equals(Server.Type.CONN_SIMPLE)) ? "ldap" : "ldaps";
            String url = StringUtils.strReplaceAll(template, "@DS_PROTO@", proto);
            String host = serverObj.getServerName() + ":" + serverObj.getPort();
            url = StringUtils.strReplaceAll(url, "@DS_HOST@", host);
            url = StringUtils.strReplaceAll(url, "@INSTANCE_NAME@", URLEncoder.encode(SystemProperties.getServerInstanceName(), "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@DSAMEUSER_NAME@", URLEncoder.encode(dsameUserName, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@DSAMEUSER_PWD@", URLEncoder.encode(dsameUserPwd, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@BASE_DN@", URLEncoder.encode(rootSuffix, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@BIND_DN@", URLEncoder.encode(connDN, "UTF-8"));
            url = StringUtils.strReplaceAll(url, "@BIND_PWD@", URLEncoder.encode(connPwd, "UTF-8"));
            bootstrap.append(url).append("\n");
        }
        bootstrapStr = bootstrap.toString();
    } catch (IOException e) {
        throw new ConfigurationException(e.getMessage());
    }
    return bootstrapStr;
}
Also used : ServerGroup(com.iplanet.services.ldap.ServerGroup) Server(com.iplanet.services.ldap.Server) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) Iterator(java.util.Iterator) Collection(java.util.Collection) IOException(java.io.IOException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Aggregations

Server (com.iplanet.services.ldap.Server)7 ServerGroup (com.iplanet.services.ldap.ServerGroup)6 ServerInstance (com.iplanet.services.ldap.ServerInstance)4 LDAPURL (org.forgerock.openam.ldap.LDAPURL)3 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 MBeanServer (javax.management.MBeanServer)2 Test (org.testng.annotations.Test)2 SystemProperties (com.iplanet.am.util.SystemProperties)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)1 HtmlAdaptorServer (com.sun.jdmk.comm.HtmlAdaptorServer)1 SnmpAdaptorServer (com.sun.management.comm.SnmpAdaptorServer)1 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)1 MalformedURLException (java.net.MalformedURLException)1 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1