| | |
| | | private boolean configurationInitialized; |
| | | |
| | | /** Defines if the CLI always use the SSL connection type. */ |
| | | private final boolean alwaysSSL; |
| | | private final boolean alwaysUseSSL; |
| | | |
| | | /** |
| | | * Creates a new instance of secure arguments. |
| | | * |
| | | * @param alwaysSSL |
| | | * If true, always use the SSL connection type. In this case, the |
| | | * @param alwaysUseSSL |
| | | * Whether to always use the SSL connection type. In this case, the |
| | | * arguments useSSL and startTLS are not present. |
| | | */ |
| | | public SecureConnectionCliArgs(boolean alwaysSSL) |
| | | public SecureConnectionCliArgs(boolean alwaysUseSSL) |
| | | { |
| | | this.alwaysSSL = alwaysSSL; |
| | | this.alwaysUseSSL = alwaysUseSSL; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String getAdministratorUID() |
| | | { |
| | | if (adminUidArg.isPresent()) |
| | | { |
| | | return adminUidArg.getValue(); |
| | | } |
| | | return adminUidArg.getDefaultValue(); |
| | | return getValueOrDefault(adminUidArg); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String getBindDN() |
| | | { |
| | | if (bindDnArg.isPresent()) |
| | | { |
| | | return bindDnArg.getValue(); |
| | | } |
| | | return bindDnArg.getDefaultValue(); |
| | | return getValueOrDefault(bindDnArg); |
| | | } |
| | | |
| | | /** |
| | |
| | | argList = new LinkedHashSet<>(); |
| | | |
| | | useSSLArg = useSSLArgument(); |
| | | if (!alwaysSSL) |
| | | if (!alwaysUseSSL) |
| | | { |
| | | argList.add(useSSLArg); |
| | | } |
| | |
| | | } |
| | | |
| | | useStartTLSArg = startTLSArgument(); |
| | | if (!alwaysSSL) |
| | | if (!alwaysUseSSL) |
| | | { |
| | | argList.add(useStartTLSArg); |
| | | } |
| | |
| | | */ |
| | | public String getHostName() |
| | | { |
| | | if (hostNameArg.isPresent()) |
| | | { |
| | | return hostNameArg.getValue(); |
| | | } |
| | | return hostNameArg.getDefaultValue(); |
| | | return getValueOrDefault(hostNameArg); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public String getPort() |
| | | { |
| | | if (portArg.isPresent()) |
| | | { |
| | | return portArg.getValue(); |
| | | return getValueOrDefault(portArg); |
| | | } |
| | | return portArg.getDefaultValue(); |
| | | |
| | | private String getValueOrDefault(Argument arg) |
| | | { |
| | | if (arg.isPresent()) |
| | | { |
| | | return arg.getValue(); |
| | | } |
| | | return arg.getDefaultValue(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return True if SSL mode is always used. |
| | | */ |
| | | public boolean alwaysSSL() |
| | | public boolean alwaysUseSsl() |
| | | { |
| | | return alwaysSSL; |
| | | return alwaysUseSSL; |
| | | } |
| | | |
| | | /** |
| | |
| | | TrustManagerProviderCfg trustManagerCfg = null; |
| | | AdministrationConnectorCfg administrationConnectorCfg = null; |
| | | |
| | | boolean couldInitializeConfig = configurationInitialized; |
| | | // Initialization for admin framework |
| | | if (!configurationInitialized) |
| | | { |
| | | couldInitializeConfig = initializeConfiguration(); |
| | | } |
| | | if (couldInitializeConfig) |
| | | if (configurationInitialized || initializeConfiguration()) |
| | | { |
| | | RootCfg root = DirectoryServer.getInstance().getServerContext().getRootConfig(); |
| | | administrationConnectorCfg = root.getAdministrationConnector(); |
| | |
| | | { |
| | | truststoreFileAbsolute = DirectoryServer.getInstanceRoot() + File.separator + truststoreFile; |
| | | } |
| | | |
| | | File f = new File(truststoreFileAbsolute); |
| | | if (!f.exists() || !f.canRead() || f.isDirectory()) |
| | | { |
| | |
| | | public int getAdminPortFromConfig() throws ConfigException |
| | | { |
| | | // Initialization for admin framework |
| | | boolean couldInitializeConfiguration = configurationInitialized; |
| | | if (!configurationInitialized) |
| | | { |
| | | couldInitializeConfiguration = initializeConfiguration(); |
| | | } |
| | | if (couldInitializeConfiguration) |
| | | if (configurationInitialized || initializeConfiguration()) |
| | | { |
| | | RootCfg root = DirectoryServer.getInstance().getServerContext().getRootConfig(); |
| | | return root.getAdministrationConnector().getListenPort(); |
| | |
| | | */ |
| | | public int getPortFromConfig() |
| | | { |
| | | int portNumber; |
| | | if (alwaysSSL()) |
| | | if (alwaysUseSsl()) |
| | | { |
| | | portNumber = AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT; |
| | | // Try to get the port from the config file |
| | | try |
| | | { |
| | | portNumber = getAdminPortFromConfig(); |
| | | // Try to get the port from the config file |
| | | return getAdminPortFromConfig(); |
| | | } |
| | | catch (ConfigException ex) |
| | | { |
| | | // Nothing to do |
| | | return AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | portNumber = CliConstants.DEFAULT_SSL_PORT; |
| | | return CliConstants.DEFAULT_SSL_PORT; |
| | | } |
| | | return portNumber; |
| | | } |
| | | |
| | | /** |
| | |
| | | private IntegerArgument createPortArgument(final int defaultValue) throws ArgumentException |
| | | { |
| | | return portArgument( |
| | | defaultValue, alwaysSSL ? INFO_DESCRIPTION_ADMIN_PORT.get() : INFO_DESCRIPTION_PORT.get()); |
| | | defaultValue, alwaysUseSSL ? INFO_DESCRIPTION_ADMIN_PORT.get() : INFO_DESCRIPTION_PORT.get()); |
| | | } |
| | | |
| | | /** |