| | |
| | | public final class LDAPManagementContextFactory implements |
| | | ManagementContextFactory { |
| | | |
| | | // The SecureConnectionCliArgsList object. |
| | | /** The SecureConnectionCliArgsList object. */ |
| | | private SecureConnectionCliArgs secureArgsList = null; |
| | | |
| | | // The management context. |
| | | /** The management context. */ |
| | | private ManagementContext context = null; |
| | | |
| | | // The connection parameters command builder. |
| | | /** The connection parameters command builder. */ |
| | | private CommandBuilder contextCommandBuilder; |
| | | |
| | | // This CLI is always using the administration connector with SSL |
| | | /** This CLI is always using the administration connector with SSL. */ |
| | | private boolean alwaysSSL = false; |
| | | |
| | | // Raw arguments |
| | | /** Raw arguments. */ |
| | | private String[] rawArgs = null; |
| | | |
| | | /** |
| | |
| | | this.alwaysSSL = alwaysSSL; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ManagementContext getManagementContext(ConsoleApplication app) |
| | | throws ArgumentException, ClientException |
| | |
| | | return context; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void close() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CommandBuilder getContextCommandBuilder() |
| | | { |
| | |
| | | } |
| | | catch (NamingException e) |
| | | { |
| | | if ( app.isInteractive() && ci.isTrustStoreInMemory()) |
| | | if (app.isInteractive() |
| | | && ci.isTrustStoreInMemory() |
| | | && e.getRootCause() != null |
| | | && e.getRootCause().getCause() instanceof OpendsCertificateException) |
| | | { |
| | | if ((e.getRootCause() != null) |
| | | && (e.getRootCause().getCause() |
| | | instanceof OpendsCertificateException)) |
| | | { |
| | | OpendsCertificateException oce = |
| | | OpendsCertificateException oce = |
| | | (OpendsCertificateException) e.getRootCause().getCause(); |
| | | String authType = null; |
| | | if (trustManager instanceof ApplicationTrustManager) |
| | | { |
| | | ApplicationTrustManager appTrustManager = |
| | | (ApplicationTrustManager)trustManager; |
| | | authType = appTrustManager.getLastRefusedAuthType(); |
| | | } |
| | | if (ci.checkServerCertificate(oce.getChain(), authType, |
| | | hostName)) |
| | | { |
| | | // If the certificate is trusted, update the trust manager. |
| | | trustManager = ci.getTrustManager(); |
| | | |
| | | // Try to connect again. |
| | | continue ; |
| | | } |
| | | String authType = null; |
| | | if (trustManager instanceof ApplicationTrustManager) |
| | | { |
| | | ApplicationTrustManager appTrustManager = |
| | | (ApplicationTrustManager) trustManager; |
| | | authType = appTrustManager.getLastRefusedAuthType(); |
| | | } |
| | | if (ci.checkServerCertificate(oce.getChain(), authType, hostName)) |
| | | { |
| | | // If the certificate is trusted, update the trust manager. |
| | | trustManager = ci.getTrustManager(); |
| | | // Try to connect again. |
| | | continue; |
| | | } |
| | | } |
| | | if (e.getRootCause() != null) { |
| | | if (e.getRootCause().getCause() != null) { |
| | | if (((e.getRootCause().getCause() |
| | | instanceof OpendsCertificateException)) || |
| | | (e.getRootCause() instanceof SSLHandshakeException)) { |
| | | LocalizableMessage message = |
| | | ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_NOT_TRUSTED.get(hostName, portNumber); |
| | | throw new ClientException( |
| | | ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message); |
| | | } |
| | | if (e.getRootCause().getCause() != null |
| | | && (e.getRootCause().getCause() instanceof OpendsCertificateException |
| | | || e.getRootCause() instanceof SSLHandshakeException)) |
| | | { |
| | | final LocalizableMessage message = |
| | | ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_NOT_TRUSTED.get( |
| | | hostName, portNumber); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | message); |
| | | } |
| | | if (e.getRootCause() instanceof SSLException) { |
| | | LocalizableMessage message = |
| | | final LocalizableMessage message = |
| | | ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_WRONG_PORT.get(hostName, portNumber); |
| | | throw new ClientException( |
| | | ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message); |
| | | } |
| | | } |
| | | LocalizableMessage message = ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT.get(hostName, portNumber); |
| | | final LocalizableMessage message = ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT.get(hostName, portNumber); |
| | | throw new ClientException( |
| | | ReturnCode.CLIENT_SIDE_CONNECT_ERROR, message); |
| | | } |
| | |
| | | { |
| | | if ( app.isInteractive() && ci.isTrustStoreInMemory()) |
| | | { |
| | | if ((e.getRootCause() != null) |
| | | && (e.getRootCause().getCause() |
| | | instanceof OpendsCertificateException)) |
| | | if (e.getRootCause() != null |
| | | && e.getRootCause().getCause() instanceof OpendsCertificateException) |
| | | { |
| | | String authType = null; |
| | | if (trustManager instanceof ApplicationTrustManager) |
| | |
| | | return context; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void setRawArguments(String[] args) { |
| | | this.rawArgs = args; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void registerGlobalArguments(SubCommandArgumentParser parser) |
| | | throws ArgumentException { |
| | |
| | | continue; |
| | | } |
| | | if (rawArg.contains(OPTION_LONG_HELP) || |
| | | (rawArg.charAt(1) == OPTION_SHORT_HELP) || (rawArg. |
| | | charAt(1) == '?')) { |
| | | rawArg.charAt(1) == OPTION_SHORT_HELP || rawArg.charAt(1) == '?') { |
| | | // used for usage help default values only |
| | | secureArgsList.initArgumentsWithConfiguration(); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void validateGlobalArguments() throws ArgumentException { |
| | | // Make sure that the user didn't specify any conflicting |