| | |
| | | package org.opends.admin.ads; |
| | | |
| | | import static org.opends.admin.ads.util.ConnectionUtils.*; |
| | | import static org.opends.quicksetup.util.Utils.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.quicksetup.Constants; |
| | | import org.opends.quicksetup.util.Utils; |
| | | import org.opends.server.config.ConfigConstants; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | |
| | |
| | | */ |
| | | public String getReplicationServerHostPort() |
| | | { |
| | | String hostPort = null; |
| | | if (isReplicationServer()) |
| | | { |
| | | hostPort = getHostName().toLowerCase()+ ":" + getReplicationServerPort(); |
| | | return getReplicationServer(getHostName(), getReplicationServerPort()); |
| | | } |
| | | return hostPort; |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public int getReplicationServerId() |
| | | { |
| | | int id = -1; |
| | | if (isReplicationServer()) |
| | | { |
| | | id = (Integer)serverProperties.get(ServerProperty.REPLICATION_SERVER_ID); |
| | | return (Integer) serverProperties.get(ServerProperty.REPLICATION_SERVER_ID); |
| | | } |
| | | return id; |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public int getReplicationServerPort() |
| | | { |
| | | int port = -1; |
| | | if (isReplicationServer()) |
| | | { |
| | | port = (Integer)serverProperties.get( |
| | | return (Integer) serverProperties.get( |
| | | ServerProperty.REPLICATION_SERVER_PORT); |
| | | } |
| | | return port; |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public boolean isReplicationSecure() |
| | | { |
| | | boolean isReplicationSecure; |
| | | if (isReplicationServer()) |
| | | { |
| | | isReplicationSecure = Boolean.TRUE.equals(serverProperties.get( |
| | | return Boolean.TRUE.equals(serverProperties.get( |
| | | ServerProperty.IS_REPLICATION_SECURE)); |
| | | } |
| | | else |
| | | { |
| | | isReplicationSecure = false; |
| | | } |
| | | return isReplicationSecure; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | String host = (String)serverProperties.get(ServerProperty.HOST_NAME); |
| | | if (host == null) |
| | | { |
| | | host = (String)adsProperties.get(ADSContext.ServerProperty.HOST_NAME); |
| | | return (String) adsProperties.get(ADSContext.ServerProperty.HOST_NAME); |
| | | } |
| | | return host; |
| | | } |
| | |
| | | */ |
| | | public String getLDAPURL() |
| | | { |
| | | String ldapUrl = null; |
| | | String host = getHostName(); |
| | | int port = -1; |
| | | |
| | | if (!serverProperties.isEmpty()) |
| | | { |
| | | ArrayList<?> s = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.LDAP_ENABLED); |
| | | ArrayList<?> p = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.LDAP_PORT); |
| | | if (s != null) |
| | | { |
| | | for (int i=0; i<s.size(); i++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(i))) |
| | | { |
| | | port = (Integer)p.get(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | int port = getPort(ServerProperty.LDAP_ENABLED, ServerProperty.LDAP_PORT); |
| | | if (port != -1) |
| | | { |
| | | ldapUrl = getLDAPUrl(host, port, false); |
| | | String host = getHostName(); |
| | | return getLDAPUrl(host, port, false); |
| | | } |
| | | return ldapUrl; |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String getLDAPsURL() |
| | | { |
| | | String ldapsUrl = null; |
| | | int port = getPort(ServerProperty.LDAPS_ENABLED, ServerProperty.LDAPS_PORT); |
| | | if (port != -1) |
| | | { |
| | | String host = getHostName(); |
| | | int port = -1; |
| | | return getLDAPUrl(host, port, true); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private int getPort(ServerProperty enabled, ServerProperty port) |
| | | { |
| | | if (!serverProperties.isEmpty()) |
| | | { |
| | | ArrayList<?> s = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.LDAPS_ENABLED); |
| | | ArrayList<?> p = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.LDAPS_PORT); |
| | | List<?> s = (List<?>) serverProperties.get(enabled); |
| | | List<?> p = (List<?>) serverProperties.get(port); |
| | | if (s != null) |
| | | { |
| | | for (int i=0; i<s.size(); i++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(i))) |
| | | { |
| | | port = (Integer)p.get(i); |
| | | break; |
| | | return (Integer) p.get(i); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (port != -1) |
| | | { |
| | | ldapsUrl = getLDAPUrl(host, port, true); |
| | | } |
| | | return ldapsUrl; |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String getAdminConnectorURL() |
| | | { |
| | | String adminConnectorUrl = null; |
| | | String host = getHostName(); |
| | | int port = -1; |
| | | |
| | | if (!serverProperties.isEmpty()) |
| | | { |
| | | ArrayList<?> s = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.ADMIN_ENABLED); |
| | | ArrayList<?> p = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.ADMIN_PORT); |
| | | if (s != null) |
| | | { |
| | | for (int i=0; i<s.size(); i++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(i))) |
| | | { |
| | | port = (Integer)p.get(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | int port = getPort(ServerProperty.ADMIN_ENABLED, ServerProperty.ADMIN_PORT); |
| | | if (port != -1) |
| | | { |
| | | adminConnectorUrl = getLDAPUrl(host, port, true); |
| | | return getLDAPUrl(host, port, true); |
| | | } |
| | | return adminConnectorUrl; |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String getHostPort(boolean securePreferred) |
| | | { |
| | | String host = getHostName(); |
| | | int port = -1; |
| | | |
| | | if (!serverProperties.isEmpty()) |
| | | { |
| | | ArrayList<?> s = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.LDAP_ENABLED); |
| | | ArrayList<?> p = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.LDAP_PORT); |
| | | if (s != null) |
| | | { |
| | | for (int i=0; i<s.size(); i++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(i))) |
| | | { |
| | | port = (Integer)p.get(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | port = getPort(port, ServerProperty.LDAP_ENABLED, ServerProperty.LDAP_PORT); |
| | | if (securePreferred) |
| | | { |
| | | s = (ArrayList<?>)serverProperties.get( |
| | | ServerProperty.ADMIN_ENABLED); |
| | | p = (ArrayList<?>)serverProperties.get(ServerProperty.ADMIN_PORT); |
| | | if (s != null) |
| | | { |
| | | for (int i=0; i<s.size(); i++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(i))) |
| | | { |
| | | port = (Integer)p.get(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | port = getPort(port, ServerProperty.ADMIN_ENABLED, ServerProperty.ADMIN_PORT); |
| | | } |
| | | } |
| | | else |
| | |
| | | Object v = adsProperties.get(prop); |
| | | if ((v != null) && "true".equalsIgnoreCase(String.valueOf(v))) |
| | | { |
| | | ADSContext.ServerProperty portProp; |
| | | if (prop == ADSContext.ServerProperty.ADMIN_ENABLED) |
| | | { |
| | | portProp = ADSContext.ServerProperty.ADMIN_PORT; |
| | | } |
| | | else if (prop == ADSContext.ServerProperty.LDAPS_ENABLED) |
| | | { |
| | | portProp = ADSContext.ServerProperty.LDAPS_PORT; |
| | | } |
| | | else if (prop == ADSContext.ServerProperty.LDAP_ENABLED) |
| | | { |
| | | portProp = ADSContext.ServerProperty.LDAP_PORT; |
| | | } |
| | | else |
| | | { |
| | | throw new IllegalStateException("Unexpected prop: "+prop); |
| | | } |
| | | ADSContext.ServerProperty portProp = getPortProperty(prop); |
| | | Object p = adsProperties.get(portProp); |
| | | if (p != null) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | String host = getHostName(); |
| | | return host + ":" + port; |
| | | } |
| | | |
| | | private ADSContext.ServerProperty getPortProperty(ADSContext.ServerProperty prop) |
| | | { |
| | | if (prop == ADSContext.ServerProperty.ADMIN_ENABLED) |
| | | { |
| | | return ADSContext.ServerProperty.ADMIN_PORT; |
| | | } |
| | | else if (prop == ADSContext.ServerProperty.LDAPS_ENABLED) |
| | | { |
| | | return ADSContext.ServerProperty.LDAPS_PORT; |
| | | } |
| | | else if (prop == ADSContext.ServerProperty.LDAP_ENABLED) |
| | | { |
| | | return ADSContext.ServerProperty.LDAP_PORT; |
| | | } |
| | | else |
| | | { |
| | | throw new IllegalStateException("Unexpected prop: "+prop); |
| | | } |
| | | } |
| | | |
| | | private int getPort(int port, ServerProperty adminEnabled, ServerProperty adminPort) |
| | | { |
| | | List<?> s = (List<?>) serverProperties.get(adminEnabled); |
| | | List<?> p = (List<?>) serverProperties.get(adminPort); |
| | | if (s != null) |
| | | { |
| | | for (int i=0; i<s.size(); i++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(i))) |
| | | { |
| | | return (Integer) p.get(i); |
| | | } |
| | | } |
| | | } |
| | | return port; |
| | | } |
| | | |
| | | /** |
| | | * Returns an Id that is unique for this server. |
| | | * @return an Id that is unique for this server. |
| | |
| | | ArrayList<?> p = (ArrayList<?>)serverProperties.get(sProps[i][1]); |
| | | if (s != null) |
| | | { |
| | | int port = -1; |
| | | for (int j=0; j<s.size(); j++) |
| | | { |
| | | if (Boolean.TRUE.equals(s.get(j))) |
| | | { |
| | | port = (Integer)p.get(j); |
| | | break; |
| | | } |
| | | } |
| | | int port = getPort(s, p); |
| | | if (port == -1) |
| | | { |
| | | adsProperties.put(adsProps[i][0], "false"); |
| | |
| | | getInstancePublicKeyCertificate()); |
| | | } |
| | | |
| | | private int getPort(List<?> enabled, List<?> port) |
| | | { |
| | | for (int j = 0; j < enabled.size(); j++) |
| | | { |
| | | if (Boolean.TRUE.equals(enabled.get(j))) |
| | | { |
| | | return (Integer) port.get(j); |
| | | } |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | | * Creates a ServerDescriptor object based on some ADS properties provided. |
| | | * @param adsProperties the ADS properties of the server. |
| | |
| | | Set<ReplicaDescriptor> replicas = desc.getReplicas(); |
| | | for (String baseDn : baseDns) |
| | | { |
| | | boolean addReplica = cacheFilter.searchAllBaseDNs(); |
| | | if (!addReplica) |
| | | { |
| | | for (String dn : cacheFilter.getBaseDNsToSearch()) |
| | | { |
| | | addReplica = Utils.areDnsEqual(dn, baseDn); |
| | | if (addReplica) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(addReplica) |
| | | if (isAddReplica(cacheFilter, baseDn)) |
| | | { |
| | | SuffixDescriptor suffix = new SuffixDescriptor(); |
| | | suffix.setDN(baseDn); |
| | |
| | | if (index != -1) |
| | | { |
| | | String dn = s.substring(index + 1); |
| | | if (Utils.areDnsEqual(baseDn, dn)) |
| | | if (areDnsEqual(baseDn, dn)) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private static boolean isAddReplica(TopologyCacheFilter cacheFilter, String baseDn) |
| | | { |
| | | if (cacheFilter.searchAllBaseDNs()) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | for (String dn : cacheFilter.getBaseDNsToSearch()) |
| | | { |
| | | if (areDnsEqual(dn, baseDn)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private static void updateReplication(ServerDescriptor desc, |
| | | InitialLdapContext ctx, TopologyCacheFilter cacheFilter) |
| | | throws NamingException |
| | |
| | | { |
| | | return "schema".equalsIgnoreCase(id); |
| | | } |
| | | /** |
| | | * Returns <CODE>true</CODE> if the the provided strings represent the same |
| | | * DN and <CODE>false</CODE> otherwise. |
| | | * @param dn1 the first dn to compare. |
| | | * @param dn2 the second dn to compare. |
| | | * @return <CODE>true</CODE> if the the provided strings represent the same |
| | | * DN and <CODE>false</CODE> otherwise. |
| | | */ |
| | | private static boolean areDnsEqual(String dn1, String dn2) |
| | | { |
| | | boolean areDnsEqual = false; |
| | | try |
| | | { |
| | | LdapName name1 = new LdapName(dn1); |
| | | LdapName name2 = new LdapName(dn2); |
| | | areDnsEqual = name1.equals(name2); |
| | | } catch (Exception ex) |
| | | { |
| | | /* ignore */ |
| | | } |
| | | return areDnsEqual; |
| | | } |
| | | |
| | | /** |
| | | * Returns the replication server normalized String for a given host name |
| | |
| | | * @return the replication server normalized String for a given host name |
| | | * and replication port. |
| | | */ |
| | | public static String getReplicationServer(String hostName, |
| | | int replicationPort) |
| | | public static String getReplicationServer(String hostName, int replicationPort) |
| | | { |
| | | return hostName.toLowerCase() + ":" + replicationPort; |
| | | return getServerRepresentation(hostName, replicationPort); |
| | | } |
| | | |
| | | /** |