| | |
| | | * |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.server.tools.status; |
| | |
| | | controlInfo.setConnectTimeout(argParser.getConnectTimeout()); |
| | | controlInfo.regenerateDescriptor(); |
| | | boolean authProvided = false; |
| | | if (controlInfo.getServerDescriptor().getStatus() == |
| | | ServerDescriptor.ServerStatus.STARTED) { |
| | | String bindDn; |
| | | String bindPwd; |
| | | if (argParser.isInteractive()) { |
| | | ManagementContext ctx = null; |
| | | if (controlInfo.getServerDescriptor().getStatus() |
| | | == ServerDescriptor.ServerStatus.STARTED) |
| | | { |
| | | String bindDn = null; |
| | | String bindPwd = null; |
| | | ManagementContext mContext = null; |
| | | |
| | | // This is done because we do not need to ask the user about these |
| | | // parameters. If we force their presence the class |
| | |
| | | LDAPConnectionConsoleInteraction ci = |
| | | new LDAPConnectionConsoleInteraction( |
| | | this, argParser.getSecureArgsList()); |
| | | try { |
| | | try |
| | | { |
| | | ci.run(true, false); |
| | | |
| | | if (argParser.isInteractive()) |
| | | { |
| | | bindDn = ci.getBindDN(); |
| | | bindPwd = ci.getBindPassword(); |
| | | |
| | | LDAPManagementContextFactory factory = |
| | | new LDAPManagementContextFactory(alwaysSSL); |
| | | ctx = factory.getManagementContext(this, ci); |
| | | interactiveTrustManager = ci.getTrustManager(); |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | } catch (ArgumentException e) { |
| | | println(e.getMessageObject()); |
| | | return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode(); |
| | | } catch (ClientException e) { |
| | | println(e.getMessageObject()); |
| | | writeStatus(controlInfo); |
| | | return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode(); |
| | | } finally { |
| | | if (ctx != null) { |
| | | try { |
| | | ctx.close(); |
| | | } catch (Throwable t) { |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | else |
| | | { |
| | | bindDn = argParser.getBindDN(); |
| | | bindPwd = argParser.getBindPassword(); |
| | | } |
| | | |
| | | authProvided = bindPwd != null; |
| | | |
| | | if (bindDn == null) { |
| | | bindDn = ""; |
| | | LDAPManagementContextFactory factory = |
| | | new LDAPManagementContextFactory(alwaysSSL); |
| | | mContext = factory.getManagementContext(this, ci); |
| | | interactiveTrustManager = ci.getTrustManager(); |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | authProvided = true; |
| | | } |
| | | if (bindPwd == null) { |
| | | bindPwd = ""; |
| | | catch (ArgumentException e) |
| | | { |
| | | println(e.getMessageObject()); |
| | | return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode(); |
| | | } |
| | | catch (ClientException e) |
| | | { |
| | | println(e.getMessageObject()); |
| | | writeStatus(controlInfo); |
| | | return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode(); |
| | | } |
| | | finally |
| | | { |
| | | if (mContext != null) |
| | | { |
| | | try |
| | | { |
| | | mContext.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | // Nothing to do. |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (authProvided) { |