| | |
| | | * named by the ds-cfg-key-id attribute from the server entry. |
| | | */ |
| | | INSTANCE_PUBLIC_KEY_CERTIFICATE( |
| | | "ds-cfg-public-key-certificate", |
| | | ADSPropertySyntax.CERTIFICATE_BINARY); |
| | | "ds-cfg-public-key-certificate", |
| | | ADSPropertySyntax.CERTIFICATE_BINARY); |
| | | |
| | | private String attrName; |
| | | private ADSPropertySyntax attSyntax; |
| | |
| | | } |
| | | |
| | | private static HashMap<String, AdministratorProperty> |
| | | nameToAdminUserProperty = null; |
| | | nameToAdminUserProperty = null; |
| | | |
| | | /** |
| | | * Get a AdministratorProperty associated to a name. |
| | |
| | | } |
| | | dirContext.createSubcontext(dn, attrs).close(); |
| | | if (serverProperties.containsKey( |
| | | ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) |
| | | ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) |
| | | { |
| | | registerInstanceKeyCertificate(serverProperties, dn); |
| | | } |
| | |
| | | memberList = new HashSet<String>(); |
| | | } |
| | | String newMember = "cn=" |
| | | + Rdn.escapeValue(serverProperties.get(ServerProperty.ID)); |
| | | + Rdn.escapeValue(serverProperties.get(ServerProperty.ID)); |
| | | |
| | | memberList.add(newMember); |
| | | serverGroupProperties.put(ServerGroupProperty.MEMBERS, memberList); |
| | |
| | | } |
| | | groupList.add(ALL_SERVERGROUP_NAME); |
| | | serverProperties.put(ServerProperty.GROUPS, groupList); |
| | | updateServer(serverProperties, null); |
| | | updateServer(serverProperties, null); |
| | | |
| | | } |
| | | catch (ADSContextException ace) |
| | |
| | | */ |
| | | public void updateServer(Map<ServerProperty, Object> serverProperties, |
| | | String newServerId) throws ADSContextException |
| | | { |
| | | { |
| | | LdapName dn = makeDNFromServerProperties(serverProperties); |
| | | |
| | | try |
| | |
| | | dirContext.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, |
| | | attrs); |
| | | if (serverProperties.containsKey( |
| | | ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) |
| | | ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) |
| | | { |
| | | registerInstanceKeyCertificate(serverProperties, dn); |
| | | } |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Method called to unregister a server in the ADS. Note that the server's |
| | |
| | | */ |
| | | public int registerOrUpdateServer( |
| | | Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | { |
| | | int result = 0; |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns the member list of a group of server. |
| | |
| | | */ |
| | | public Set<String> getServerGroupMemberList( |
| | | String serverGroupId) throws ADSContextException |
| | | { |
| | | { |
| | | LdapName dn = nameFromDN("cn=" + Rdn.escapeValue(serverGroupId) + "," |
| | | + getServerGroupContainerDN()); |
| | | |
| | |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns a set containing the servers that are registered in the |
| | |
| | | if (serverGroupProperties.containsKey(ServerGroupProperty.UID)) |
| | | { |
| | | String newGroupId = serverGroupProperties |
| | | .get(ServerGroupProperty.UID).toString(); |
| | | .get(ServerGroupProperty.UID).toString(); |
| | | if (!newGroupId.equals(groupID)) |
| | | { |
| | | // Rename to entry |
| | |
| | | |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | | String[] attList = { "cn", "userpassword", "ds-privilege-name", |
| | | "description" }; |
| | | "description" }; |
| | | sc.setReturningAttributes(attList); |
| | | ne = dirContext.search(getAdministratorContainerDN(), "(objectclass=*)", |
| | | sc); |
| | |
| | | makeDNFromAdministratorProperties(adminProperties); |
| | | |
| | | boolean updatePassword = adminProperties |
| | | .containsKey(AdministratorProperty.PASSWORD); |
| | | .containsKey(AdministratorProperty.PASSWORD); |
| | | try |
| | | { |
| | | // Entry renaming |
| | |
| | | SearchResult sr = (SearchResult)ne.next(); |
| | | |
| | | currentPrivileges = sr.getAttributes().get("ds-privilege-name") |
| | | .getAll(); |
| | | .getAll(); |
| | | } |
| | | |
| | | // Replace properties, if needed. |
| | |
| | | */ |
| | | private static LdapName makeDNFromHostnameAndPath(String hostname, |
| | | String ipath) throws ADSContextException |
| | | { |
| | | { |
| | | String cnValue = Rdn.escapeValue(hostname + "@" + ipath); |
| | | return nameFromDN("cn=" + cnValue + "," + getServerContainerDN()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * This method returns the DN of the entry that corresponds to the given host |
| | |
| | | throw new ADSContextException(ADSContextException.ErrorType.MISSING_NAME); |
| | | } |
| | | return nameFromDN("cn=" + Rdn.escapeValue(serverGroupId) + "," + |
| | | getServerGroupContainerDN()); |
| | | getServerGroupContainerDN()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static LdapName makeDNFromServerProperties( |
| | | Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | { |
| | | String serverID ; |
| | | if ( (serverID = getServerID(serverProperties)) != null ) |
| | | { |
| | |
| | | ServerDescriptor s = ServerDescriptor.createStandalone(serverProperties); |
| | | return makeDNFromServerUniqueId(s.getHostPort(true)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * This method returns the DN of the entry that corresponds to the given |
| | |
| | | */ |
| | | public static String getServerIdFromServerProperties( |
| | | Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | { |
| | | LdapName ldapName = makeDNFromServerProperties(serverProperties); |
| | | String rdn = ldapName.get(ldapName.size() -1); |
| | | int pos = rdn.indexOf("="); |
| | | return rdn.substring(pos+1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * This method returns the DN of the entry that corresponds to the given |
| | |
| | | } |
| | | |
| | | LinkedList privileges = (LinkedList) |
| | | adminProperties.get(AdministratorProperty.PRIVILEGE); |
| | | adminProperties.get(AdministratorProperty.PRIVILEGE); |
| | | for( Object o : privileges) |
| | | { |
| | | String p = o.toString() ; |
| | |
| | | |
| | | switch(property) |
| | | { |
| | | case INSTANCE_PUBLIC_KEY_CERTIFICATE: |
| | | result = null; // used in separate instance key entry |
| | | break; |
| | | case GROUPS: |
| | | result = new BasicAttribute(ServerProperty.GROUPS.getAttributeName()); |
| | | for (Object o : ((Set) value)) { |
| | | result.add(o); |
| | | } |
| | | break; |
| | | default: |
| | | result = new BasicAttribute(property.getAttributeName(), value); |
| | | case INSTANCE_PUBLIC_KEY_CERTIFICATE: |
| | | result = null; // used in separate instance key entry |
| | | break; |
| | | case GROUPS: |
| | | result = new BasicAttribute(ServerProperty.GROUPS.getAttributeName()); |
| | | for (Object o : ((Set) value)) { |
| | | result.add(o); |
| | | } |
| | | break; |
| | | default: |
| | | result = new BasicAttribute(property.getAttributeName(), value); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | case MEMBERS: |
| | | result = new BasicAttribute( |
| | | ServerGroupProperty.MEMBERS.getAttributeName()); |
| | | for (Object o : ((Set) value)) { |
| | | result.add(o); |
| | | } |
| | | break; |
| | | for (Object o : ((Set) value)) { |
| | | result.add(o); |
| | | } |
| | | break; |
| | | default: |
| | | result = new BasicAttribute(property.getAttributeName(), value); |
| | | } |
| | |
| | | */ |
| | | private Map<ServerGroupProperty, Object> makePropertiesFromServerGroupAttrs( |
| | | Attributes attrs) throws ADSContextException |
| | | { |
| | | { |
| | | HashMap<ServerGroupProperty, Object> result = |
| | | new HashMap<ServerGroupProperty, Object>(); |
| | | try |
| | |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns the properties of a server for some LDAP attributes. |
| | |
| | | */ |
| | | private Map<ServerProperty, Object> makePropertiesFromServerAttrs( |
| | | Attributes attrs) throws ADSContextException |
| | | { |
| | | { |
| | | HashMap<ServerProperty, Object> result = |
| | | new HashMap<ServerProperty, Object>(); |
| | | try |
| | |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | private static String getHostname( |
| | | Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | { |
| | | String result = (String)serverProperties.get(ServerProperty.HOST_NAME); |
| | | if (result == null) |
| | | { |
| | |
| | | ADSContextException.ErrorType.NOVALID_HOSTNAME); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns the Server ID for the given properties. |
| | |
| | | */ |
| | | private static String getInstallPath( |
| | | Map<ServerProperty, Object> serverProperties) throws ADSContextException |
| | | { |
| | | { |
| | | String result = (String)serverProperties.get(ServerProperty.INSTANCE_PATH); |
| | | if (result == null) |
| | | { |
| | |
| | | ADSContextException.ErrorType.NOVALID_IPATH); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | oc.add("groupofurls"); |
| | | attrs.put(oc); |
| | | attrs.put("memberURL", "ldap:///" + getAdministratorContainerDN() + |
| | | "??one?(objectclass=*)"); |
| | | "??one?(objectclass=*)"); |
| | | attrs.put("description", "Group of identities which have full access."); |
| | | createEntry(getAdministratorContainerDN(), attrs); |
| | | } |
| | |
| | | * Removes the administration suffix. |
| | | * @throws ADSContextException if something goes wrong. |
| | | */ |
| | | // private void removeAdministrationSuffix() throws ADSContextException |
| | | // { |
| | | // ADSContextHelper helper = new ADSContextHelper(); |
| | | // helper.removeAdministrationSuffix(getDirContext(), |
| | | // getDefaultBackendName()); |
| | | // } |
| | | //private void removeAdministrationSuffix() throws ADSContextException |
| | | //{ |
| | | //ADSContextHelper helper = new ADSContextHelper(); |
| | | //helper.removeAdministrationSuffix(getDirContext(), |
| | | //getDefaultBackendName()); |
| | | //} |
| | | |
| | | /** |
| | | * Returns the default backend name of the administration data. |
| | |
| | | |
| | | |
| | | /* |
| | | *** CryptoManager related types, fields, and methods. *** |
| | | *** CryptoManager related types, fields, and methods. *** |
| | | */ |
| | | |
| | | /** |
| | |
| | | /** |
| | | Returns the parent entry of the secret key entries in ADS. |
| | | @return the parent entry of the secret key entries in ADS. |
| | | */ |
| | | public static String getSecretKeysContainerDN() |
| | | { |
| | | return "cn=secret keys," + getAdministrationSuffixDN(); |
| | | } |
| | | */ |
| | | public static String getSecretKeysContainerDN() |
| | | { |
| | | return "cn=secret keys," + getAdministrationSuffixDN(); |
| | | } |
| | | |
| | | /** |
| | | * Tells whether the provided server is registered in the registry. |
| | | * @param server the server. |
| | | * @param registry the registry. |
| | | * @return <CODE>true</CODE> if the server is registered in the registry |
| | | * and <CODE>false</CODE> otherwise. |
| | | */ |
| | | public static boolean isRegistered( |
| | | ServerDescriptor server, |
| | | Set<Map<ADSContext.ServerProperty, Object>> registry) |
| | | { |
| | | boolean isRegistered = false; |
| | | for (Map<ADSContext.ServerProperty, Object> s : registry) |
| | | { |
| | | ServerDescriptor servInRegistry = ServerDescriptor.createStandalone(s); |
| | | if (servInRegistry.getId().equals(server.getId())) |
| | | { |
| | | isRegistered = true; |
| | | break; |
| | | } |
| | | } |
| | | return isRegistered; |
| | | } |
| | | |
| | | /** |
| | | Register instance key-pair public-key certificate provided in |
| | |
| | | getting the instance public key certificate ID. |
| | | */ |
| | | private void registerInstanceKeyCertificate( |
| | | Map<ServerProperty, Object> serverProperties, |
| | | LdapName serverEntryDn) |
| | | Map<ServerProperty, Object> serverProperties, |
| | | LdapName serverEntryDn) |
| | | throws ADSContextException { |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | helper.registerInstanceKeyCertificate(dirContext, serverProperties, |
| | |
| | | the instance key entry belongs. |
| | | @param serverEntryDn The server's ADS entry DN. |
| | | @throws NamingException In case some JNDI operation fails. |
| | | */ |
| | | private void unregisterInstanceKeyCertificate( |
| | | Map<ServerProperty, Object> serverProperties, |
| | | LdapName serverEntryDn) |
| | | throws ADSContextException { |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | helper.unregisterInstanceKeyCertificate(dirContext, serverProperties, |
| | | serverEntryDn); |
| | | } |
| | | */ |
| | | private void unregisterInstanceKeyCertificate( |
| | | Map<ServerProperty, Object> serverProperties, |
| | | LdapName serverEntryDn) |
| | | throws ADSContextException { |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | helper.unregisterInstanceKeyCertificate(dirContext, serverProperties, |
| | | serverEntryDn); |
| | | } |
| | | |
| | | /** |
| | | Return the set of valid (i.e., not tagged as compromised) instance key-pair |
| | |
| | | @see org.opends.server.crypto.CryptoManagerImpl#getTrustedCertificates |
| | | */ |
| | | public Map<String,byte[]> getTrustedCertificates() |
| | | throws ADSContextException |
| | | throws ADSContextException |
| | | { |
| | | final Map<String, byte[]> certificateMap = new HashMap<String, byte[]>(); |
| | | final String baseDNStr = getInstanceKeysContainerDN(); |
| | |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | final LdapName baseDN = new LdapName(baseDNStr); |
| | | final String FILTER_OC_INSTANCE_KEY |
| | | = new StringBuilder("(objectclass=") |
| | | .append(helper.getOcCryptoInstanceKey()) |
| | | .append(")").toString(); |
| | | = new StringBuilder("(objectclass=") |
| | | .append(helper.getOcCryptoInstanceKey()) |
| | | .append(")").toString(); |
| | | final String FILTER_NOT_COMPROMISED = new StringBuilder("(!(") |
| | | .append(helper.getAttrCryptoKeyCompromisedTime()) |
| | | .append("=*))").toString(); |
| | | .append(helper.getAttrCryptoKeyCompromisedTime()) |
| | | .append("=*))").toString(); |
| | | final String searchFilter = new StringBuilder("(&") |
| | | .append(FILTER_OC_INSTANCE_KEY) |
| | | .append(FILTER_NOT_COMPROMISED) |
| | | .append(")").toString(); |
| | | .append(FILTER_OC_INSTANCE_KEY) |
| | | .append(FILTER_NOT_COMPROMISED) |
| | | .append(")").toString(); |
| | | final SearchControls searchControls = new SearchControls(); |
| | | searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | | final String attrIDs[]= { |
| | | ADSContext.ServerProperty.INSTANCE_KEY_ID.getAttributeName(), |
| | | ADSContext.ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE |
| | | .getAttributeName() + ";binary"}; |
| | | ADSContext.ServerProperty.INSTANCE_KEY_ID.getAttributeName(), |
| | | ADSContext.ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE |
| | | .getAttributeName() + ";binary"}; |
| | | searchControls.setReturningAttributes(attrIDs); |
| | | NamingEnumeration<SearchResult> keyEntries |
| | | = dirContext.search(baseDN, searchFilter, searchControls); |
| | | = dirContext.search(baseDN, searchFilter, searchControls); |
| | | while (keyEntries.hasMore()) { |
| | | final SearchResult entry = keyEntries.next(); |
| | | final Attributes attrs = entry.getAttributes(); |
| | |
| | | } |
| | | catch (NamingException x) { |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return certificateMap; |
| | | } |