Partial OPENDJ-2625 Convert all code that uses JNDI to use the SDK instead
Replace all mentions of "DirContext" by "Connection"
1 files renamed
17 files modified
| | |
| | | GENERIC_CREATING_CONNECTION, |
| | | /** Error reading the configuration of a particular server. */ |
| | | GENERIC_READING_SERVER, |
| | | /** The DN provided in the DirContext of ADS is not of a global administrator. */ |
| | | /** The DN provided in the connection of ADS is not of a global administrator. */ |
| | | NOT_GLOBAL_ADMINISTRATOR, |
| | | /** Not enough permissions to read the server configuration. */ |
| | | NO_PERMISSIONS, |
| | |
| | | import org.opends.guitools.controlpanel.task.Task; |
| | | import org.opends.guitools.controlpanel.task.Task.State; |
| | | import org.opends.guitools.controlpanel.task.Task.Type; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromDirContext; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromConnection; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromFile; |
| | | import org.opends.guitools.controlpanel.util.ConfigReader; |
| | | import org.opends.guitools.controlpanel.util.Utilities; |
| | |
| | | * @throws LdapException |
| | | * if there is a problem updating the connection pool. |
| | | */ |
| | | public void setUserDataDirContext(ConnectionWrapper conn) throws LdapException |
| | | public void setUserDataConnection(ConnectionWrapper conn) throws LdapException |
| | | { |
| | | if (userDataConn != null) |
| | | { |
| | |
| | | * |
| | | * @return the connection to be used by the ControlPanelInfo to retrieve user data. |
| | | */ |
| | | public ConnectionWrapper getUserDataDirContext() |
| | | public ConnectionWrapper getUserDataConnection() |
| | | { |
| | | return userDataConn; |
| | | } |
| | |
| | | { |
| | | if (isLocal) |
| | | { |
| | | connWrapper = Utilities.getAdminDirContext(this, lastWorkingBindDN, lastWorkingBindPwd); |
| | | connWrapper = Utilities.getAdminConnection(this, lastWorkingBindDN, lastWorkingBindPwd); |
| | | } |
| | | else if (lastRemoteHostPort != null) |
| | | { |
| | |
| | | |
| | | if (reader != null) |
| | | { |
| | | desc.setAuthenticated(reader instanceof ConfigFromDirContext); |
| | | desc.setAuthenticated(reader instanceof ConfigFromConnection); |
| | | desc.setJavaVersion(reader.getJavaVersion()); |
| | | desc.setOpenConnections(reader.getOpenConnections()); |
| | | desc.setTaskEntries(reader.getTaskEntries()); |
| | | if (reader instanceof ConfigFromDirContext) |
| | | if (reader instanceof ConfigFromConnection) |
| | | { |
| | | ConfigFromDirContext rCtx = (ConfigFromDirContext)reader; |
| | | ConfigFromConnection rCtx = (ConfigFromConnection)reader; |
| | | desc.setRootMonitor(rCtx.getRootMonitor()); |
| | | desc.setEntryCachesMonitor(rCtx.getEntryCaches()); |
| | | desc.setJvmMemoryUsageMonitor(rCtx.getJvmMemoryUsage()); |
| | |
| | | |
| | | private ConfigReader newRemoteConfigReader() |
| | | { |
| | | ConfigFromDirContext reader = new ConfigFromDirContext(); |
| | | ConfigFromConnection reader = new ConfigFromConnection(); |
| | | reader.setIsLocal(isLocal); |
| | | reader.readConfiguration(connWrapper); |
| | | return reader; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromDirContext; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromConnection; |
| | | import org.opends.quicksetup.UserData; |
| | | import org.opends.server.tools.tasks.TaskEntry; |
| | | import org.opends.server.types.Schema; |
| | |
| | | { |
| | | String start = rootMonitor.getAttribute(START_DATE.getAttributeName()).firstValueAsString(); |
| | | String current = rootMonitor.getAttribute(CURRENT_DATE.getAttributeName()).firstValueAsString(); |
| | | Date startTime = ConfigFromDirContext.utcParser.parse(start); |
| | | Date currentTime = ConfigFromDirContext.utcParser.parse(current); |
| | | Date startTime = ConfigFromConnection.utcParser.parse(start); |
| | | Date currentTime = ConfigFromConnection.utcParser.parse(current); |
| | | return currentTime.getTime() - startTime.getTime(); |
| | | } |
| | | catch (Throwable t) |
| | |
| | | * Deletes an index. The code assumes that the server is running and that the |
| | | * provided connection is active. |
| | | * |
| | | * @param connWrapper |
| | | * the connection to the server. |
| | | * @param index |
| | | * the index to be deleted. |
| | | * @param ctx |
| | | * the connection to the server. |
| | | * @throws OpenDsException |
| | | * if an error occurs. |
| | | */ |
| | |
| | | // is what we use to clone connections and to launch scripts. |
| | | // The environment will also be used if we want to reconnect. |
| | | rebind(getInfo().getConnection()); |
| | | if (getInfo().getUserDataDirContext() != null) |
| | | if (getInfo().getUserDataConnection() != null) |
| | | { |
| | | rebind(getInfo().getUserDataDirContext()); |
| | | rebind(getInfo().getUserDataConnection()); |
| | | } |
| | | } |
| | | state = State.FINISHED_SUCCESSFULLY; |
| | |
| | | { |
| | | ConnectionWrapper conn = useAdminConnector |
| | | ? getInfo().getConnection() |
| | | : getInfo().getUserDataDirContext(); |
| | | : getInfo().getUserDataConnection(); |
| | | |
| | | List<String> args = new ArrayList<>(); |
| | | if (isServerRunning() && conn != null) |
| | |
| | | updateNumSubordinateHacker(desc); |
| | | if (setConnection) |
| | | { |
| | | if (getInfo().getUserDataDirContext() == null) |
| | | if (getInfo().getUserDataConnection() == null) |
| | | { |
| | | ConnectionWrapper connUserData = createUserDataDirContext(conn.getBindDn(), conn.getBindPassword()); |
| | | getInfo().setUserDataDirContext(connUserData); |
| | | getInfo().setUserDataConnection(createUserDataConnection(conn.getBindDn(), conn.getBindPassword())); |
| | | } |
| | | Runnable runnable = new Runnable() |
| | | { |
| | |
| | | { |
| | | ControlPanelInfo info = getInfo(); |
| | | controller.setConnections( |
| | | info.getServerDescriptor(), info.getConnection(), info.getUserDataDirContext()); |
| | | info.getServerDescriptor(), info.getConnection(), info.getUserDataConnection()); |
| | | applyButtonClicked(); |
| | | } |
| | | }; |
| | |
| | | * @throws ConfigReadException |
| | | * if an error occurs reading the configuration. |
| | | */ |
| | | private ConnectionWrapper createUserDataDirContext(final DN bindDN, final String bindPassword) |
| | | private ConnectionWrapper createUserDataConnection(final DN bindDN, final String bindPassword) |
| | | throws IOException, ConfigReadException |
| | | { |
| | | createdUserDataConn = null; |
| | | try |
| | | { |
| | | createdUserDataConn = Utilities.getUserDataDirContext(getInfo(), bindDN, bindPassword); |
| | | createdUserDataConn = Utilities.getUserDataConnection(getInfo(), bindDN, bindPassword); |
| | | } |
| | | catch (LdapException e) |
| | | { |
| | |
| | | { |
| | | logger.info(LocalizableMessage.raw("Accepting certificate presented by host " + host)); |
| | | getInfo().getTrustManager().acceptCertificate(chain, authType, host); |
| | | createdUserDataConn = createUserDataDirContext(bindDN, bindPassword); |
| | | createdUserDataConn = createUserDataConnection(bindDN, bindPassword); |
| | | } |
| | | else |
| | | { |
| | |
| | | if (isLocal) |
| | | { |
| | | usedHostPort = info.getAdminConnectorHostPort(); |
| | | conn = Utilities.getAdminDirContext(info, bindDn, bindPwd); |
| | | conn = Utilities.getAdminConnection(info, bindDn, bindPwd); |
| | | } |
| | | else |
| | | { |
| | |
| | | closeInfoConnections(); |
| | | info.setIsLocal(isLocal); |
| | | info.setConnection(conn); |
| | | info.setUserDataDirContext(null); |
| | | info.setUserDataConnection(null); |
| | | info.regenerateDescriptor(); |
| | | return conn; |
| | | } catch (Throwable t) |
| | |
| | | private void closeInfoConnections() |
| | | { |
| | | StaticUtils.close(getInfo().getConnection()); |
| | | StaticUtils.close(getInfo().getUserDataDirContext()); |
| | | StaticUtils.close(getInfo().getUserDataConnection()); |
| | | } |
| | | } |
| | |
| | | { |
| | | ControlPanelInfo info = getInfo(); |
| | | usedHostPort = info.getAdminConnectorHostPort(); |
| | | conn = Utilities.getAdminDirContext(info, DN.valueOf(dn.getText()), String.valueOf(pwd.getPassword())); |
| | | conn = Utilities.getAdminConnection(info, DN.valueOf(dn.getText()), String.valueOf(pwd.getPassword())); |
| | | |
| | | org.forgerock.util.Utils.closeSilently(info.getConnection(), info.getUserDataDirContext()); |
| | | org.forgerock.util.Utils.closeSilently(info.getConnection(), info.getUserDataConnection()); |
| | | try |
| | | { |
| | | Thread.sleep(500); |
| | |
| | | } |
| | | }); |
| | | info.setConnection(conn); |
| | | info.setUserDataDirContext(null); |
| | | info.setUserDataConnection(null); |
| | | info.regenerateDescriptor(); |
| | | return conn; |
| | | } catch (Throwable t) |
| | |
| | | } |
| | | } |
| | | |
| | | private void createVLVIndexOnline(ConnectionWrapper ctx) throws Exception |
| | | private void createVLVIndexOnline(ConnectionWrapper conn) throws Exception |
| | | { |
| | | final BackendCfgClient backend = ctx.getRootConfiguration().getBackend(backendName.getText()); |
| | | final BackendCfgClient backend = conn.getRootConfiguration().getBackend(backendName.getText()); |
| | | createBackendVLVIndexOnline((PluggableBackendCfgClient) backend); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes; |
| | | import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromDirContext; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromConnection; |
| | | import org.opends.guitools.controlpanel.util.Utilities; |
| | | |
| | | import static org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes.*; |
| | |
| | | { |
| | | String start = sr.getAttribute(START_DATE.getAttributeName()).firstValueAsString(); |
| | | String current = sr.getAttribute(CURRENT_DATE.getAttributeName()).firstValueAsString(); |
| | | Date startTime = ConfigFromDirContext.utcParser.parse(start); |
| | | Date currentTime = ConfigFromDirContext.utcParser.parse(current); |
| | | Date startTime = ConfigFromConnection.utcParser.parse(start); |
| | | Date currentTime = ConfigFromConnection.utcParser.parse(current); |
| | | |
| | | long upSeconds = (currentTime.getTime() - startTime.getTime()) / 1000; |
| | | long upDays = upSeconds / 86400; |
| | |
| | | /** |
| | | * Modifies index using the provided connection. |
| | | * |
| | | * @param ctx |
| | | * @param connWrapper |
| | | * the connection to be used to update the index configuration. |
| | | * @throws Exception |
| | | * if there is an error updating the server. |
| | |
| | | |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if the displayed entry is the top entry of a |
| | | * suffix and <CODE>false</CODE> otherwise. |
| | | * @return <CODE>true</CODE> if the displayed entry is the top entry of a |
| | | * suffix and <CODE>false</CODE> otherwise. |
| | | * Returns whether the displayed entry is the top entry of a suffix. |
| | | * @return {@code true} if the displayed entry is the top entry of a suffix, |
| | | * {@code false} otherwise. |
| | | */ |
| | | boolean isSuffix(); |
| | | |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if the displayed entry is the root node of the |
| | | * server (the dn="" entry) and <CODE>false</CODE> otherwise. |
| | | * @return <CODE>true</CODE> if the displayed entry is the root node of the |
| | | * server (the dn="" entry) and <CODE>false</CODE> otherwise. |
| | | * Returns whether the displayed entry is the root node of the |
| | | * server (the dn="" entry).. |
| | | * @return {@code true} if the displayed entry is the root node of the |
| | | * server (the dn="" entry) and {@code false} otherwise. |
| | | */ |
| | | boolean isRootNode(); |
| | | |
| | | /** |
| | | * Returns <CODE>true</CODE> if the displayed entry is not located on the |
| | | * Returns whether the displayed entry is not located on the |
| | | * current server. An entry is declared 'remote' when the host/port of |
| | | * getURL() is different from the host/port of the DirContext associated to |
| | | * the browser controller. Returns <CODE>false</CODE> otherwise. |
| | | * @return <CODE>true</CODE> if the displayed entry is not located on the |
| | | * current server. An entry is declared 'remote' when the host/port of |
| | | * getURL() is different from the host/port of the DirContext associated to |
| | | * the browser controller. Returns <CODE>false</CODE> otherwise. |
| | | * getURL() is different from the host/port of the connection associated to |
| | | * the browser controller. |
| | | * @return {@code true} if the displayed entry is not located on the |
| | | * current server, {@code false} otherwise. |
| | | */ |
| | | boolean isRemote(); |
| | | |
| File was renamed from opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java |
| | |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | | /** |
| | | * A class that reads the configuration and monitoring information using a |
| | | * DirContext through LDAP. |
| | | */ |
| | | public class ConfigFromDirContext extends ConfigReader |
| | | /** A class that reads the configuration and monitoring information using an LDAP connection. */ |
| | | public class ConfigFromConnection extends ConfigReader |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | |
| | | * or the provided credentials do not have enough rights. |
| | | * @throws ConfigReadException if there is an error reading the configuration. |
| | | */ |
| | | public static ConnectionWrapper getAdminDirContext(ControlPanelInfo controlInfo, DN bindDN, String pwd) |
| | | public static ConnectionWrapper getAdminConnection(ControlPanelInfo controlInfo, DN bindDN, String pwd) |
| | | throws IOException, ConfigReadException |
| | | { |
| | | return createConnection(controlInfo.getAdminConnectorHostPort(), LDAPS, bindDN, pwd, controlInfo); |
| | |
| | | * or the provided credentials do not have enough rights. |
| | | * @throws ConfigReadException if there is an error reading the configuration. |
| | | */ |
| | | public static ConnectionWrapper getUserDataDirContext(ControlPanelInfo controlInfo, |
| | | public static ConnectionWrapper getUserDataConnection(ControlPanelInfo controlInfo, |
| | | DN bindDN, String pwd) throws IOException, ConfigReadException |
| | | { |
| | | if (controlInfo.connectUsingStartTLS()) |
| | |
| | | } |
| | | Long l = Long.parseLong(monitoringValue); |
| | | Date date = new Date(l); |
| | | return ConfigFromDirContext.formatter.format(date); |
| | | return ConfigFromConnection.formatter.format(date); |
| | | } |
| | | else if (attr.isTime()) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | Date date = ConfigFromDirContext.utcParser.parse(monitoringValue); |
| | | return ConfigFromDirContext.formatter.format(date); |
| | | Date date = ConfigFromConnection.utcParser.parse(monitoringValue); |
| | | return ConfigFromConnection.formatter.format(date); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | |
| | | throw new ApplicationException(ReturnCode.APPLICATION_ERROR, |
| | | ERR_COULD_NOT_FIND_VALID_LDAPURL.get(), null); |
| | | } |
| | | connWrapper = org.opends.guitools.controlpanel.util.Utilities.getAdminDirContext(info, dn, pwd); |
| | | connWrapper = org.opends.guitools.controlpanel.util.Utilities.getAdminConnection(info, dn, pwd); |
| | | return true; // server is running |
| | | } |
| | | catch (LdapException e) |
| | |
| | | import org.opends.admin.ads.util.ServerLoader; |
| | | import org.opends.guitools.controlpanel.datamodel.BackendDescriptor; |
| | | import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromDirContext; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromConnection; |
| | | import org.opends.guitools.controlpanel.util.ConfigFromFile; |
| | | import org.opends.guitools.controlpanel.util.ControlPanelLog; |
| | | import org.opends.guitools.controlpanel.util.ProcessReader; |
| | |
| | | { |
| | | List<TaskEntry> taskEntries = new ArrayList<>(); |
| | | List<Exception> exceptions = new ArrayList<>(); |
| | | ConfigFromDirContext cfg = new ConfigFromDirContext(); |
| | | ConfigFromConnection cfg = new ConfigFromConnection(); |
| | | cfg.updateTaskInformation(conn, exceptions, taskEntries); |
| | | for (Exception ode : exceptions) |
| | | { |
| | |
| | | |
| | | if (managementContextOpened) |
| | | { |
| | | try (ConnectionWrapper conn = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd)) |
| | | try (ConnectionWrapper conn = Utilities.getAdminConnection(controlInfo, bindDn, bindPwd)) |
| | | { |
| | | controlInfo.setConnection(conn); |
| | | controlInfo.regenerateDescriptor(); |