| | |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | |
| | | import java.io.File; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.Set; |
| | | import java.util.HashSet; |
| | | import java.util.Map; |
| | | import java.util.HashMap; |
| | | import java.util.Set; |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | |
| | | import javax.naming.CompositeName; |
| | | import javax.naming.InvalidNameException; |
| | | import javax.naming.NameAlreadyBoundException; |
| | |
| | | import javax.naming.NamingException; |
| | | import javax.naming.NoPermissionException; |
| | | import javax.naming.NotContextException; |
| | | import javax.naming.directory.DirContext; |
| | | import javax.naming.directory.SearchResult; |
| | | import javax.naming.directory.Attribute; |
| | | import javax.naming.directory.Attributes; |
| | | import javax.naming.directory.BasicAttribute; |
| | | import javax.naming.directory.BasicAttributes; |
| | | import javax.naming.directory.DirContext; |
| | | import javax.naming.directory.SearchControls; |
| | | import javax.naming.directory.SearchResult; |
| | | import javax.naming.ldap.Control; |
| | | import javax.naming.ldap.InitialLdapContext; |
| | | import javax.naming.ldap.LdapContext; |
| | | import javax.naming.ldap.LdapName; |
| | | import javax.naming.ldap.Rdn; |
| | | import javax.naming.ldap.Control; |
| | | import javax.naming.ldap.LdapContext; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.admin.ads.ADSContextException.ErrorType; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.quicksetup.Constants; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | |
| | | /** |
| | | * Class used to update and read the contents of the Administration Data. |
| | | */ |
| | | /** Class used to update and read the contents of the Administration Data. */ |
| | | public class ADSContext |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | |
| | | { |
| | | /** String syntax. */ |
| | | STRING, |
| | | |
| | | /** Integer syntax. */ |
| | | INTEGER, |
| | | |
| | | /** Boolean syntax. */ |
| | | BOOLEAN, |
| | | |
| | | /** Certificate;binary syntax. */ |
| | | CERTIFICATE_BINARY |
| | | } |
| | |
| | | public enum ServerProperty |
| | | { |
| | | /** The ID used to identify the server. */ |
| | | ID("id", ADSPropertySyntax.STRING), |
| | | |
| | | ID("id",ADSPropertySyntax.STRING), |
| | | /** The host name of the server. */ |
| | | HOST_NAME("hostname", ADSPropertySyntax.STRING), |
| | | |
| | | HOST_NAME("hostname",ADSPropertySyntax.STRING), |
| | | /** The LDAP port of the server. */ |
| | | LDAP_PORT("ldapport", ADSPropertySyntax.INTEGER), |
| | | |
| | | LDAP_PORT("ldapport",ADSPropertySyntax.INTEGER), |
| | | /** The JMX port of the server. */ |
| | | JMX_PORT("jmxport", ADSPropertySyntax.INTEGER), |
| | | |
| | | JMX_PORT("jmxport",ADSPropertySyntax.INTEGER), |
| | | /** The JMX secure port of the server. */ |
| | | JMXS_PORT("jmxsport", ADSPropertySyntax.INTEGER), |
| | | |
| | | JMXS_PORT("jmxsport",ADSPropertySyntax.INTEGER), |
| | | /** The LDAPS port of the server. */ |
| | | LDAPS_PORT("ldapsport", ADSPropertySyntax.INTEGER), |
| | | |
| | | LDAPS_PORT("ldapsport",ADSPropertySyntax.INTEGER), |
| | | /** The administration connector port of the server. */ |
| | | ADMIN_PORT("adminport", ADSPropertySyntax.INTEGER), |
| | | |
| | | ADMIN_PORT("adminport",ADSPropertySyntax.INTEGER), |
| | | /** The certificate used by the server. */ |
| | | CERTIFICATE("certificate", ADSPropertySyntax.STRING), |
| | | |
| | | CERTIFICATE("certificate",ADSPropertySyntax.STRING), |
| | | /** The path where the server is installed. */ |
| | | INSTANCE_PATH("instancepath", ADSPropertySyntax.STRING), |
| | | |
| | | INSTANCE_PATH("instancepath",ADSPropertySyntax.STRING), |
| | | /** The description of the server. */ |
| | | DESCRIPTION("description", ADSPropertySyntax.STRING), |
| | | |
| | | DESCRIPTION("description",ADSPropertySyntax.STRING), |
| | | /** The OS of the machine where the server is installed. */ |
| | | HOST_OS("os", ADSPropertySyntax.STRING), |
| | | |
| | | HOST_OS("os",ADSPropertySyntax.STRING), |
| | | /** Whether LDAP is enabled or not. */ |
| | | LDAP_ENABLED("ldapEnabled", ADSPropertySyntax.BOOLEAN), |
| | | |
| | | LDAP_ENABLED("ldapEnabled",ADSPropertySyntax.BOOLEAN), |
| | | /** Whether LDAPS is enabled or not. */ |
| | | LDAPS_ENABLED("ldapsEnabled", ADSPropertySyntax.BOOLEAN), |
| | | |
| | | LDAPS_ENABLED("ldapsEnabled",ADSPropertySyntax.BOOLEAN), |
| | | /** Whether ADMIN is enabled or not. */ |
| | | ADMIN_ENABLED("adminEnabled", ADSPropertySyntax.BOOLEAN), |
| | | |
| | | ADMIN_ENABLED("adminEnabled",ADSPropertySyntax.BOOLEAN), |
| | | /** Whether StartTLS is enabled or not. */ |
| | | STARTTLS_ENABLED("startTLSEnabled", ADSPropertySyntax.BOOLEAN), |
| | | |
| | | STARTTLS_ENABLED("startTLSEnabled",ADSPropertySyntax.BOOLEAN), |
| | | /** Whether JMX is enabled or not. */ |
| | | JMX_ENABLED("jmxEnabled", ADSPropertySyntax.BOOLEAN), |
| | | |
| | | JMX_ENABLED("jmxEnabled",ADSPropertySyntax.BOOLEAN), |
| | | /** Whether JMX is enabled or not. */ |
| | | JMXS_ENABLED("jmxsEnabled", ADSPropertySyntax.BOOLEAN), |
| | | |
| | | JMXS_ENABLED("jmxsEnabled",ADSPropertySyntax.BOOLEAN), |
| | | /** The location of the server. */ |
| | | LOCATION("location", ADSPropertySyntax.STRING), |
| | | |
| | | LOCATION("location",ADSPropertySyntax.STRING), |
| | | /** The groups to which this server belongs. */ |
| | | GROUPS("memberofgroups", ADSPropertySyntax.STRING), |
| | | |
| | | GROUPS("memberofgroups",ADSPropertySyntax.STRING), |
| | | /** The unique name of the instance key public-key certificate. */ |
| | | INSTANCE_KEY_ID("ds-cfg-key-id", ADSPropertySyntax.STRING), |
| | | |
| | | INSTANCE_KEY_ID("ds-cfg-key-id",ADSPropertySyntax.STRING), |
| | | /** |
| | | * The instance key-pair public-key certificate. Note: This attribute |
| | | * belongs to an instance key entry, separate from the server entry and |
| | |
| | | return NAME_TO_SERVER_PROPERTY.get(name); |
| | | } |
| | | |
| | | /** |
| | | * The list of server properties that are multivalued. |
| | | */ |
| | | /** The list of server properties that are multivalued. */ |
| | | private static final Set<ServerProperty> MULTIVALUED_SERVER_PROPERTIES = new HashSet<>(); |
| | | static |
| | | { |
| | | MULTIVALUED_SERVER_PROPERTIES.add(ServerProperty.GROUPS); |
| | | } |
| | | |
| | | /** |
| | | * The default server group which will contain all registered servers. |
| | | */ |
| | | /** The default server group which will contain all registered servers. */ |
| | | public static final String ALL_SERVERGROUP_NAME = "all-servers"; |
| | | |
| | | /** |
| | | * Enumeration containing the different server group properties that are |
| | | * stored in the ADS. |
| | | */ |
| | | /** Enumeration containing the different server group properties that are stored in the ADS. */ |
| | | public enum ServerGroupProperty |
| | | { |
| | | /** |
| | | * The UID of the server group. |
| | | */ |
| | | /** The UID of the server group. */ |
| | | UID("cn"), |
| | | /** |
| | | * The description of the server group. |
| | | */ |
| | | /** The description of the server group. */ |
| | | DESCRIPTION("description"), |
| | | /** |
| | | * The members of the server group. |
| | | */ |
| | | /** The members of the server group. */ |
| | | MEMBERS("uniqueMember"); |
| | | |
| | | private String attrName; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * The list of server group properties that are multivalued. |
| | | */ |
| | | /** The list of server group properties that are multivalued. */ |
| | | private static final Set<ServerGroupProperty> MULTIVALUED_SERVER_GROUP_PROPERTIES = new HashSet<>(); |
| | | static |
| | | { |
| | | MULTIVALUED_SERVER_GROUP_PROPERTIES.add(ServerGroupProperty.MEMBERS); |
| | | } |
| | | |
| | | /** |
| | | * The enumeration containing the different Administrator properties. |
| | | */ |
| | | /** The enumeration containing the different Administrator properties. */ |
| | | public enum AdministratorProperty |
| | | { |
| | | /** |
| | | * The UID of the administrator. |
| | | */ |
| | | /** The UID of the administrator. */ |
| | | UID("id", ADSPropertySyntax.STRING), |
| | | /** |
| | | * The password of the administrator. |
| | | */ |
| | | /** The password of the administrator. */ |
| | | PASSWORD("password", ADSPropertySyntax.STRING), |
| | | /** |
| | | * The description of the administrator. |
| | | */ |
| | | /** The description of the administrator. */ |
| | | DESCRIPTION("description", ADSPropertySyntax.STRING), |
| | | /** |
| | | * The DN of the administrator. |
| | | */ |
| | | /** The DN of the administrator. */ |
| | | ADMINISTRATOR_DN("administrator dn", ADSPropertySyntax.STRING), |
| | | /** |
| | | * The administrator privilege. |
| | | */ |
| | | /** The administrator privilege. */ |
| | | PRIVILEGE("privilege", ADSPropertySyntax.STRING); |
| | | |
| | | private String attrName; |
| | |
| | | Set<String> groupList = new HashSet<>(); |
| | | if (rawGroupList != null) |
| | | { |
| | | for (Object elm : rawGroupList.toArray()) |
| | | for (Object elm : rawGroupList) |
| | | { |
| | | groupList.add(elm.toString()); |
| | | } |
| | |
| | | groupList.add(ALL_SERVERGROUP_NAME); |
| | | serverProperties.put(ServerProperty.GROUPS, groupList); |
| | | updateServer(serverProperties, null); |
| | | |
| | | } |
| | | catch (ADSContextException ace) |
| | | { |
| | |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED); |
| | | throw new ADSContextException(ErrorType.ALREADY_REGISTERED); |
| | | } |
| | | catch (Exception x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED); |
| | | throw new ADSContextException(ErrorType.NOT_YET_REGISTERED); |
| | | } |
| | | catch (Exception x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED); |
| | | throw new ADSContextException(ErrorType.NOT_YET_REGISTERED); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | |
| | | // Unregister the server in server groups |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL); |
| | | throw new ADSContextException(ErrorType.BROKEN_INSTALL); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (ADSContextException x) |
| | | { |
| | | if (x.getError() == ADSContextException.ErrorType.ALREADY_REGISTERED) |
| | | if (x.getError() == ErrorType.ALREADY_REGISTERED) |
| | | { |
| | | updateServer(serverProperties, null); |
| | | return 1; |
| | |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL); |
| | | throw new ADSContextException(ErrorType.BROKEN_INSTALL); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED); |
| | | throw new ADSContextException(ErrorType.ALREADY_REGISTERED); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL, x); |
| | | throw new ADSContextException(ErrorType.BROKEN_INSTALL, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED); |
| | | throw new ADSContextException(ErrorType.NOT_YET_REGISTERED); |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED); |
| | | throw new ADSContextException(ErrorType.ALREADY_REGISTERED); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | public void removeServerGroupProp(String groupID, Set<ServerGroupProperty> serverGroupProperties) |
| | | throws ADSContextException |
| | | { |
| | | |
| | | LdapName dn = nameFromDN("cn=" + Rdn.escapeValue(groupID) + "," + getServerGroupContainerDN()); |
| | | BasicAttributes attrs = makeAttrsFromServerGroupProperties(serverGroupProperties); |
| | | try |
| | |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED); |
| | | throw new ADSContextException(ErrorType.ALREADY_REGISTERED); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL); |
| | | throw new ADSContextException(ErrorType.BROKEN_INSTALL); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.BROKEN_INSTALL); |
| | | throw new ADSContextException(ErrorType.BROKEN_INSTALL); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ALREADY_REGISTERED); |
| | | throw new ADSContextException(ErrorType.ALREADY_REGISTERED); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public void deleteAdministrator(Map<AdministratorProperty, Object> adminProperties) throws ADSContextException |
| | | { |
| | | |
| | | LdapName dnCentralAdmin = makeDNFromAdministratorProperties(adminProperties); |
| | | |
| | | try |
| | | { |
| | | dirContext.destroySubcontext(dnCentralAdmin); |
| | | } |
| | | catch (NameNotFoundException x) |
| | | catch (NameNotFoundException | NotContextException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED); |
| | | } |
| | | catch (NotContextException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED); |
| | | throw new ADSContextException(ErrorType.NOT_YET_REGISTERED); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | public void updateAdministrator(Map<AdministratorProperty, Object> adminProperties, String newAdminUserId) |
| | | throws ADSContextException |
| | | { |
| | | |
| | | LdapName dnCentralAdmin = makeDNFromAdministratorProperties(adminProperties); |
| | | |
| | | boolean updatePassword = adminProperties.containsKey(AdministratorProperty.PASSWORD); |
| | |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOT_YET_REGISTERED); |
| | | throw new ADSContextException(ErrorType.NOT_YET_REGISTERED); |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | String serverGroupId = (String) serverGroupProperties.get(ServerGroupProperty.UID); |
| | | if (serverGroupId == null) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.MISSING_NAME); |
| | | throw new ADSContextException(ErrorType.MISSING_NAME); |
| | | } |
| | | return nameFromDN("cn=" + Rdn.escapeValue(serverGroupId) + "," + getServerGroupContainerDN()); |
| | | } |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | |
| | | String result = (String) serverProperties.get(ServerProperty.HOST_NAME); |
| | | if (result == null) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.MISSING_HOSTNAME); |
| | | throw new ADSContextException(ErrorType.MISSING_HOSTNAME); |
| | | } |
| | | else if (result.length() == 0) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOVALID_HOSTNAME); |
| | | throw new ADSContextException(ErrorType.NOVALID_HOSTNAME); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | String result = (String) serverProperties.get(ServerProperty.INSTANCE_PATH); |
| | | if (result == null) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.MISSING_IPATH); |
| | | throw new ADSContextException(ErrorType.MISSING_IPATH); |
| | | } |
| | | else if (result.length() == 0) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.NOVALID_IPATH); |
| | | throw new ADSContextException(ErrorType.NOVALID_IPATH); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | String result = (String) adminProperties.get(AdministratorProperty.UID); |
| | | if (result == null) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.MISSING_ADMIN_UID); |
| | | throw new ADSContextException(ErrorType.MISSING_ADMIN_UID); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | String result = (String) adminProperties.get(AdministratorProperty.PASSWORD); |
| | | if (result == null) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.MISSING_ADMIN_PASSWORD); |
| | | throw new ADSContextException(ErrorType.MISSING_ADMIN_PASSWORD); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | catch (InvalidNameException x) |
| | | { |
| | | logger.error(LocalizableMessage.raw("Error parsing dn " + dn, x)); |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | catch (InvalidNameException x) |
| | | { |
| | | logger.error(LocalizableMessage.raw("Error parsing rdn " + rdnName, x)); |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private boolean isExistingEntry(LdapName dn) throws ADSContextException |
| | | { |
| | | boolean result; |
| | | |
| | | try |
| | | { |
| | | SearchControls sc = new SearchControls(); |
| | |
| | | sc.setSearchScope(SearchControls.OBJECT_SCOPE); |
| | | sc.setReturningAttributes(new String[] { SchemaConstants.NO_ATTRIBUTES }); |
| | | NamingEnumeration<SearchResult> sr = getDirContext().search(dn, "(objectclass=*)", sc); |
| | | result = false; |
| | | boolean result = false; |
| | | try |
| | | { |
| | | while (sr.hasMore()) |
| | |
| | | { |
| | | sr.close(); |
| | | } |
| | | return result; |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | | result = false; |
| | | return false; |
| | | } |
| | | catch (NoPermissionException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ACCESS_PERMISSION); |
| | | throw new ADSContextException(ErrorType.ACCESS_PERMISSION); |
| | | } |
| | | catch (javax.naming.NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Removes the administration suffix. |
| | | * |
| | | * @throws ADSContextException |
| | | * if something goes wrong. |
| | | */ |
| | | //private void removeAdministrationSuffix() throws ADSContextException |
| | | //{ |
| | | //ADSContextHelper helper = new ADSContextHelper(); |
| | | //helper.removeAdministrationSuffix(getDirContext(), |
| | | //getDefaultBackendName()); |
| | | //} |
| | | |
| | | /** |
| | | * Returns the default backend name of the administration data. |
| | | * |
| | | * @return the default backend name of the administration data. |
| | |
| | | */ |
| | | public static boolean isRegistered(ServerDescriptor server, Set<Map<ADSContext.ServerProperty, Object>> registry) |
| | | { |
| | | boolean isRegistered = false; |
| | | for (Map<ADSContext.ServerProperty, Object> s : registry) |
| | | { |
| | | ServerDescriptor servInRegistry = ServerDescriptor.createStandalone(s); |
| | | if (servInRegistry.getId().equals(server.getId())) |
| | | { |
| | | isRegistered = true; |
| | | break; |
| | | return true; |
| | | } |
| | | } |
| | | return isRegistered; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Unregister instance key-pair public-key certificate provided in |
| | | * serverProperties.. |
| | | * |
| | | * @param serverProperties |
| | | * Properties of the server being unregistered to which the instance |
| | | * key entry belongs. |
| | | * @param serverEntryDn |
| | | * The server's ADS entry DN. |
| | | * @throws NamingException |
| | | * In case some JNDI operation fails. |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | private void unregisterInstanceKeyCertificate(Map<ServerProperty, Object> serverProperties, LdapName serverEntryDn) |
| | | throws ADSContextException |
| | | { |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | helper.unregisterInstanceKeyCertificate(dirContext, serverProperties, serverEntryDn); |
| | | } |
| | | |
| | | /** |
| | | * Return the set of valid (i.e., not tagged as compromised) instance key-pair |
| | | * public-key certificate entries in ADS. NOTE: calling this method assumes |
| | | * that all the jar files are present in the classpath. |
| | |
| | | } |
| | | catch (NamingException x) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return certificateMap; |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | // Merge administrators. |
| | | mergeAdministrators(adsCtx); |
| | | |
| | | // Merge groups. |
| | | mergeServerGroups(adsCtx); |
| | | |
| | | // Merge servers. |
| | | mergeServers(adsCtx); |
| | | } |
| | | catch (ADSContextException adce) |
| | | { |
| | | LocalizableMessage msg = ERR_ADS_MERGE.get(ConnectionUtils.getHostPort(getDirContext()), |
| | | ConnectionUtils.getHostPort(adsCtx.getDirContext()), adce.getMessageObject()); |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_MERGING, msg, adce); |
| | | throw new ADSContextException(ErrorType.ERROR_MERGING, msg, adce); |
| | | } |
| | | } |
| | | |
| | |
| | | LocalizableMessage msg = ERR_ADS_ADMINISTRATOR_MERGE.get( |
| | | ConnectionUtils.getHostPort(adsCtx.getDirContext()), ConnectionUtils.getHostPort(getDirContext()), |
| | | joinAsString(Constants.LINE_SEPARATOR, notDefinedAdmins), ConnectionUtils.getHostPort(getDirContext())); |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_MERGING, msg, null); |
| | | throw new ADSContextException(ErrorType.ERROR_MERGING, msg, null); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private void mergeServers(ADSContext adsCtx) throws ADSContextException |
| | | { |
| | | Set<Map<ServerProperty, Object>> servers2 = adsCtx.readServerRegistry(); |
| | | for (Map<ServerProperty, Object> server2 : servers2) |
| | | for (Map<ServerProperty, Object> server2 : adsCtx.readServerRegistry()) |
| | | { |
| | | if (!isServerAlreadyRegistered(server2)) |
| | | { |
| | |
| | | } |
| | | catch (NamingException ex) |
| | | { |
| | | throw new ADSContextException(ADSContextException.ErrorType.ERROR_UNEXPECTED, ex); |
| | | throw new ADSContextException(ErrorType.ERROR_UNEXPECTED, ex); |
| | | } |
| | | } |
| | | } |