Search in sources :

Example 1 with ServerGroup

use of com.sun.identity.common.configuration.ServerConfigXML.ServerGroup in project OpenAM by OpenRock.

the class AddAMSDKIdRepoPlugin method updateServerConfigXML.

private void updateServerConfigXML() throws Exception {
    SSOToken adminSSOToken = getAdminSSOToken();
    Set servers = ServerConfiguration.getServers(adminSSOToken);
    Map newValues = new HashMap();
    newValues.put("com.sun.am.event.connection.disable.list", "");
    for (Iterator items = servers.iterator(); items.hasNext(); ) {
        String instance = (String) items.next();
        String serverconfig = ServerConfiguration.getServerConfigXML(adminSSOToken, instance);
        ServerConfigXML cxml = new ServerConfigXML(serverconfig);
        ServerGroup defaultGroup = cxml.getDefaultServerGroup();
        // Add directory servers
        if ((directoryServers != null) && !directoryServers.isEmpty()) {
            defaultGroup.hosts.clear();
            int i = 1;
            for (Iterator dshosts = directoryServers.iterator(); dshosts.hasNext(); i++) {
                String dshost = (String) dshosts.next();
                // Parse the dshost
                String name = "SERVER" + i;
                DSEntry dsEntry = new DSEntry(dshost);
                String type = (dsEntry.ssl) ? "SSL" : "SIMPLE";
                String host = dsEntry.host;
                String port = Integer.toString(dsEntry.port);
                defaultGroup.addHost(name, host, port, type);
            }
        }
        // Set the base dn
        defaultGroup.dsBaseDN = basedn;
        // Set admin & proxy user's password
        for (Iterator users = defaultGroup.dsUsers.iterator(); users.hasNext(); ) {
            DirUserObject user = (DirUserObject) users.next();
            if (user.type.equals("proxy")) {
                user.dn = "cn=puser,ou=DSAME Users," + basedn;
                user.password = Crypt.encode(pUserPwd);
            } else if (user.type.equals("admin")) {
                user.dn = "cn=dsameuser,ou=DSAME Users," + basedn;
                user.password = Crypt.encode(dUserPwd);
            }
        }
        // Saver serverconfig.xml
        ServerConfiguration.setServerConfigXML(adminSSOToken, instance, cxml.toXML());
        // Enable psearch for um, aci and sm
        ServerConfiguration.setServerInstance(adminSSOToken, instance, newValues);
    }
}
Also used : DirUserObject(com.sun.identity.common.configuration.ServerConfigXML.DirUserObject) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) ServerGroup(com.sun.identity.common.configuration.ServerConfigXML.ServerGroup) HashMap(java.util.HashMap) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) ServerConfigXML(com.sun.identity.common.configuration.ServerConfigXML)

Example 2 with ServerGroup

use of com.sun.identity.common.configuration.ServerConfigXML.ServerGroup in project OpenAM by OpenRock.

the class AMSetupServlet method syncServerInfoWithRelication.

/**
     * Synchronizes embedded replication state with current server list.
     * @return boolean true is sync succeeds else false.
     */
private static boolean syncServerInfoWithRelication() {
    // We need to execute syn only if we are in Embedded mode
    if (!isEmbeddedDS()) {
        return true;
    }
    try {
        if (getAdminSSOToken() == null) {
            Debug.getInstance(SetupConstants.DEBUG_NAME).error("AMSetupServlet.syncServerInfoWithRelication: " + "Could not sync servers with embedded replication:no admin token");
            return false;
        }
        // Determine which server this is
        String myName = WebtopNaming.getLocalServer();
        // See if we need to execute sync
        // Check if we are already replication with other servers
        Properties props = ServerConfiguration.getServerInstance(adminToken, myName);
        String syncFlag = props.getProperty(Constants.EMBED_SYNC_SERVERS);
        if ("off".equals(syncFlag)) {
            return true;
        }
        // Get server list
        Set<String> serverSet = ServerConfiguration.getServers(adminToken);
        if (serverSet == null) {
            return true;
        }
        String dsAdminPort = props.getProperty(Constants.DS_ADMIN_PORT);
        Set<String> currServerSet = new HashSet<String>();
        Set<String> currServerDSSet = new HashSet<String>();
        Set<String> currServerDSAdminPortsSet = new HashSet<String>();
        for (String sname : serverSet) {
            Properties p = ServerConfiguration.getServerInstance(adminToken, sname);
            String hname = p.getProperty(Constants.AM_SERVER_HOST);
            String rPort = p.getProperty(Constants.EMBED_REPL_PORT);
            currServerSet.add(hname + ":" + rPort);
            ServerGroup sg = getSMSServerGroup(sname);
            currServerDSSet.add(hname + ":" + getSMSPort(sg));
            currServerDSAdminPortsSet.add(hname + ":" + p.getProperty(Constants.DS_ADMIN_PORT));
        }
        // Ensure OpenDJ system properties are setup so that it can discover its installation root
        final String embeddedDjInstallRoot = getBaseDir() + "/" + SetupConstants.SMS_OPENDS_DATASTORE;
        for (String property : OpenDJUpgrader.INSTALL_ROOT_PROPERTIES) {
            System.setProperty(property, embeddedDjInstallRoot);
        }
        // Force initialization of embedded DJ configuration with the correct installation root
        if (!ConfigurationFramework.getInstance().isInitialized()) {
            ConfigurationFramework.getInstance().initialize(embeddedDjInstallRoot);
        }
        ServerGroup sGroup = getSMSServerGroup(myName);
        boolean stats = EmbeddedOpenDS.syncReplicatedServers(currServerSet, dsAdminPort, getSMSPassword(sGroup));
        boolean statd = EmbeddedOpenDS.syncReplicatedDomains(currServerSet, dsAdminPort, getSMSPassword(sGroup));
        boolean statl = EmbeddedOpenDS.syncReplicatedServerList(currServerDSAdminPortsSet, getSMSPort(sGroup), getSMSPassword(sGroup));
        return stats || statd || statl;
    } catch (Exception ex) {
        Debug.getInstance(SetupConstants.DEBUG_NAME).error("AMSetupServlet.syncServerInfoWithRelication: " + "Could not sync servers with embedded replication:", ex);
        return false;
    }
}
Also used : ServerGroup(com.sun.identity.common.configuration.ServerConfigXML.ServerGroup) Properties(java.util.Properties) SystemProperties(com.iplanet.am.util.SystemProperties) MissingResourceException(java.util.MissingResourceException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) HashSet(java.util.HashSet)

Aggregations

ServerGroup (com.sun.identity.common.configuration.ServerConfigXML.ServerGroup)2 HashSet (java.util.HashSet)2 SystemProperties (com.iplanet.am.util.SystemProperties)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)1 ServerConfigXML (com.sun.identity.common.configuration.ServerConfigXML)1 DirUserObject (com.sun.identity.common.configuration.ServerConfigXML.DirUserObject)1 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 PolicyException (com.sun.identity.policy.PolicyException)1 SMSException (com.sun.identity.sm.SMSException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 MissingResourceException (java.util.MissingResourceException)1 Properties (java.util.Properties)1