| | |
| | | */ |
| | | package org.opends.admin.ads; |
| | | |
| | | import static org.forgerock.opendj.ldap.Filter.*; |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | |
| | | */ |
| | | public void registerServer(Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | String dn = makeDNFromServerProperties(serverProperties); |
| | | DN dn = makeDNFromServerProperties(serverProperties); |
| | | |
| | | AddRequest request = newAddRequest(dn); |
| | | for (ServerProperty prop : serverProperties.keySet()) |
| | |
| | | private void updateServer(Map<ServerProperty, Object> serverProperties, String newServerId) |
| | | throws ADSContextException |
| | | { |
| | | String dn = makeDNFromServerProperties(serverProperties); |
| | | DN dn = makeDNFromServerProperties(serverProperties); |
| | | |
| | | try |
| | | { |
| | |
| | | { |
| | | Map<ServerProperty, Object> newServerProps = new HashMap<>(serverProperties); |
| | | newServerProps.put(ServerProperty.ID, newServerId); |
| | | String newDn = makeDNFromServerProperties(newServerProps); |
| | | throwIfNotSuccess(connectionWrapper.getConnection().modifyDN(dn, newDn)); |
| | | DN newDn = makeDNFromServerProperties(newServerProps); |
| | | throwIfNotSuccess(connectionWrapper.getConnection().modifyDN(dn.toString(), newDn.toString())); |
| | | dn = newDn; |
| | | serverProperties.put(ServerProperty.ID, newServerId); |
| | | } |
| | |
| | | */ |
| | | public void unregisterServer(Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | String dn = makeDNFromServerProperties(serverProperties); |
| | | DN dn = makeDNFromServerProperties(serverProperties); |
| | | Connection conn = connectionWrapper.getConnection(); |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | throwIfNotSuccess(conn.delete(dn)); |
| | | throwIfNotSuccess(conn.delete(newDeleteRequest(dn))); |
| | | } |
| | | catch (EntryNotFoundException x) |
| | | { |
| | |
| | | { |
| | | // Unregister the server in server groups |
| | | String memberAttrName = ServerGroupProperty.MEMBERS.getAttributeName(); |
| | | String filter = "(" + memberAttrName + "=cn=" + serverID + ")"; |
| | | Filter filter = Filter.valueOf("(" + memberAttrName + "=cn=" + serverID + ")"); |
| | | SearchRequest request = newSearchRequest(getServerGroupContainerDN(), SINGLE_LEVEL, filter); |
| | | try (ConnectionEntryReader entryReader = conn.search(request);) |
| | | { |
| | |
| | | { |
| | | Set<Map<ServerProperty, Object>> result = new HashSet<>(); |
| | | |
| | | SearchRequest request = newSearchRequest(getServerContainerDN(), SINGLE_LEVEL, "(objectclass=*)"); |
| | | SearchRequest request = newSearchRequest(getServerContainerDN(), SINGLE_LEVEL, objectClassPresent()); |
| | | try (ConnectionEntryReader entryReader = connectionWrapper.getConnection().search(request)) |
| | | { |
| | | while (entryReader.hasNext()) |
| | |
| | | if (keyId != null) |
| | | { |
| | | SearchRequest request2 = newSearchRequest( |
| | | getInstanceKeysContainerDN(), SINGLE_LEVEL, "(ds-cfg-key-id=" + keyId + ")", |
| | | getInstanceKeysContainerDN(), SINGLE_LEVEL, Filter.valueOf("(ds-cfg-key-id=" + keyId + ")"), |
| | | "ds-cfg-public-key-certificate;binary"); |
| | | try (ConnectionEntryReader entryReader2 = connectionWrapper.getConnection().search(request2)) |
| | | { |
| | |
| | | */ |
| | | private Set<Map<ServerGroupProperty, Object>> readServerGroupRegistry() throws ADSContextException |
| | | { |
| | | SearchRequest request = newSearchRequest(getServerGroupContainerDN(), SINGLE_LEVEL, "(objectclass=*)"); |
| | | SearchRequest request = newSearchRequest(getServerGroupContainerDN(), SINGLE_LEVEL, objectClassPresent()); |
| | | try (ConnectionEntryReader entryReader = connectionWrapper.getConnection().search(request)) |
| | | { |
| | | Set<Map<ServerGroupProperty, Object>> result = new HashSet<>(); |
| | |
| | | { |
| | | Set<Map<AdministratorProperty, Object>> result = new HashSet<>(); |
| | | SearchRequest request = newSearchRequest( |
| | | getAdministratorContainerDN(), SINGLE_LEVEL, "(objectclass=*)", |
| | | getAdministratorContainerDN(), SINGLE_LEVEL, objectClassPresent(), |
| | | "cn", "userpassword", "ds-privilege-name", "description"); |
| | | try (ConnectionEntryReader entryReader = connectionWrapper.getConnection().search(request)) |
| | | { |
| | |
| | | */ |
| | | public void removeAdminData(boolean removeAdministrators) throws ADSContextException |
| | | { |
| | | String[] dns = { getServerContainerDN(), getServerGroupContainerDN(), |
| | | DN[] dns = { getServerContainerDN(), getServerGroupContainerDN(), |
| | | removeAdministrators ? getAdministratorContainerDN() : null }; |
| | | try |
| | | { |
| | | for (String dn : dns) |
| | | for (DN dn : dns) |
| | | { |
| | | if (dn != null) |
| | | { |
| | |
| | | */ |
| | | public boolean hasAdminData() throws ADSContextException |
| | | { |
| | | String[] dns = { getAdministratorContainerDN(), getAllServerGroupDN(), getServerContainerDN(), |
| | | DN[] dns = { getAdministratorContainerDN(), getAllServerGroupDN(), getServerContainerDN(), |
| | | getInstanceKeysContainerDN(), getSecretKeysContainerDN() }; |
| | | boolean hasAdminData = true; |
| | | for (int i = 0; i < dns.length && hasAdminData; i++) |
| | |
| | | * the UID to be used to generate the DN. |
| | | * @return the DN of the administrator for the given UID: |
| | | */ |
| | | public static String getAdministratorDN(String uid) |
| | | public static DN getAdministratorDN(String uid) |
| | | { |
| | | return "cn=" + Rdn.escapeValue(uid) + "," + getAdministratorContainerDN(); |
| | | return DN.valueOf("cn=" + Rdn.escapeValue(uid) + "," + getAdministratorContainerDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public void deleteAdministrator(Map<AdministratorProperty, Object> adminProperties) throws ADSContextException |
| | | { |
| | | String dnCentralAdmin = getAdministratorDN(getAdministratorUID(adminProperties)); |
| | | DN dnCentralAdmin = getAdministratorDN(getAdministratorUID(adminProperties)); |
| | | try |
| | | { |
| | | throwIfNotSuccess(connectionWrapper.getConnection().delete(dnCentralAdmin)); |
| | | throwIfNotSuccess(connectionWrapper.getConnection().delete(newDeleteRequest(dnCentralAdmin))); |
| | | } |
| | | catch (EntryNotFoundException x) |
| | | { |
| | |
| | | * |
| | | * @return the DN of the suffix that contains the administration data. |
| | | */ |
| | | public static String getAdministrationSuffixDN() |
| | | public static DN getAdministrationSuffixDN() |
| | | { |
| | | return "cn=admin data"; |
| | | return DN.valueOf("cn=admin data"); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws ADSContextException |
| | | * if something goes wrong. |
| | | */ |
| | | private static String makeDNFromHostnameAndPath(String hostname, String ipath) throws ADSContextException |
| | | private static DN makeDNFromHostnameAndPath(String hostname, String ipath) throws ADSContextException |
| | | { |
| | | return "cn=" + Rdn.escapeValue(hostname + "@" + ipath) + "," + getServerContainerDN(); |
| | | return DN.valueOf("cn=" + Rdn.escapeValue(hostname + "@" + ipath) + "," + getServerContainerDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws ADSContextException |
| | | * if something goes wrong. |
| | | */ |
| | | private static String makeDNFromServerUniqueId(String serverUniqueId) throws ADSContextException |
| | | private static DN makeDNFromServerUniqueId(String serverUniqueId) throws ADSContextException |
| | | { |
| | | return "cn=" + Rdn.escapeValue(serverUniqueId) + "," + getServerContainerDN(); |
| | | return DN.valueOf("cn=" + Rdn.escapeValue(serverUniqueId) + "," + getServerContainerDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws ADSContextException |
| | | * if something goes wrong. |
| | | */ |
| | | private static String makeDNFromServerProperties(Map<ServerProperty, Object> serverProperties) |
| | | private static DN makeDNFromServerProperties(Map<ServerProperty, Object> serverProperties) |
| | | throws ADSContextException |
| | | { |
| | | String serverID = getServerID(serverProperties); |
| | |
| | | * |
| | | * @return the parent entry of the server entries. |
| | | */ |
| | | private static String getServerContainerDN() |
| | | private static DN getServerContainerDN() |
| | | { |
| | | return "cn=Servers," + getAdministrationSuffixDN(); |
| | | return DN.valueOf("cn=Servers," + getAdministrationSuffixDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return the parent entry of the administrator entries. |
| | | */ |
| | | public static String getAdministratorContainerDN() |
| | | public static DN getAdministratorContainerDN() |
| | | { |
| | | return "cn=Administrators," + getAdministrationSuffixDN(); |
| | | return DN.valueOf("cn=Administrators," + getAdministrationSuffixDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return the parent entry of the server group entries. |
| | | */ |
| | | private static String getServerGroupContainerDN() |
| | | private static DN getServerGroupContainerDN() |
| | | { |
| | | return "cn=Server Groups," + getAdministrationSuffixDN(); |
| | | return DN.valueOf("cn=Server Groups," + getAdministrationSuffixDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return the all server group entry DN. |
| | | */ |
| | | private static String getAllServerGroupDN() |
| | | private static DN getAllServerGroupDN() |
| | | { |
| | | return "cn=" + Rdn.escapeValue(ALL_SERVERGROUP_NAME) + "," + getServerGroupContainerDN(); |
| | | return DN.valueOf("cn=" + Rdn.escapeValue(ALL_SERVERGROUP_NAME) + "," + getServerGroupContainerDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws ADSContextException |
| | | * if an error occurred while checking if the entry exists or not. |
| | | */ |
| | | private boolean isExistingEntry(String dn) throws ADSContextException |
| | | private boolean isExistingEntry(DN dn) throws ADSContextException |
| | | { |
| | | SearchRequest request = newSearchRequest(dn, BASE_OBJECT, "(objectclass=*)", NO_ATTRIBUTES); |
| | | SearchRequest request = newSearchRequest(dn, BASE_OBJECT, objectClassPresent(), NO_ATTRIBUTES); |
| | | try (ConnectionEntryReader entryReader = getConnection().getConnection().search(request)) |
| | | { |
| | | while (entryReader.hasNext()) |
| | |
| | | * @throws ADSContextException |
| | | * if the entry could not be created. |
| | | */ |
| | | private void createContainerEntry(String dn) throws ADSContextException |
| | | private void createContainerEntry(DN dn) throws ADSContextException |
| | | { |
| | | createEntry(newAddRequest(dn).addAttribute("objectclass", "top", "ds-cfg-branch")); |
| | | } |
| | |
| | | * |
| | | * @return the parent entry of the server key entries in ADS. |
| | | */ |
| | | static String getInstanceKeysContainerDN() |
| | | static DN getInstanceKeysContainerDN() |
| | | { |
| | | return "cn=instance keys," + getAdministrationSuffixDN(); |
| | | return DN.valueOf("cn=instance keys," + getAdministrationSuffixDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return the parent entry of the secret key entries in ADS. |
| | | */ |
| | | private static String getSecretKeysContainerDN() |
| | | private static DN getSecretKeysContainerDN() |
| | | { |
| | | return "cn=secret keys," + getAdministrationSuffixDN(); |
| | | return DN.valueOf("cn=secret keys," + getAdministrationSuffixDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws ADSContextException |
| | | * In case there is a problem registering the instance public key certificate ID |
| | | */ |
| | | private void registerInstanceKeyCertificate(Map<ServerProperty, Object> serverProperties, String serverEntryDn) |
| | | private void registerInstanceKeyCertificate(Map<ServerProperty, Object> serverProperties, DN serverEntryDn) |
| | | throws ADSContextException |
| | | { |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | |
| | | */ |
| | | public Map<String, byte[]> getTrustedCertificates() throws ADSContextException |
| | | { |
| | | final String baseDN = getInstanceKeysContainerDN(); |
| | | final DN baseDN = getInstanceKeysContainerDN(); |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | final String FILTER_OC_INSTANCE_KEY = "(objectclass=" + helper.getOcCryptoInstanceKey() + ")"; |
| | | final String FILTER_NOT_COMPROMISED = "(!(" + helper.getAttrCryptoKeyCompromisedTime() + "=*))"; |
| | | final String searchFilter = "(&" + FILTER_OC_INSTANCE_KEY + FILTER_NOT_COMPROMISED + ")"; |
| | | final Filter searchFilter = Filter.valueOf("(&" + FILTER_OC_INSTANCE_KEY + FILTER_NOT_COMPROMISED + ")"); |
| | | |
| | | String instanceKeyId = ADSContext.ServerProperty.INSTANCE_KEY_ID.getAttributeName(); |
| | | String instanceKeyCertificate = |