| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2007-2009 Sun Microsystems, Inc. |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | package org.opends.admin.ads; |
| | |
| | | } |
| | | |
| | | // Unregister the server in server groups |
| | | NamingEnumeration<SearchResult> ne = null; |
| | | try |
| | | { |
| | | NamingEnumeration<SearchResult> ne; |
| | | SearchControls sc = new SearchControls(); |
| | | |
| | | String serverID = getServerID(serverProperties); |
| | |
| | | BasicAttribute newAttr = new BasicAttribute(memberAttrName); |
| | | NamingEnumeration<? extends Attribute> attrs = |
| | | sr.getAttributes().getAll(); |
| | | while (attrs.hasMore()) |
| | | try |
| | | { |
| | | Attribute attr = attrs.next(); |
| | | String attrID = attr.getID(); |
| | | |
| | | if (attrID.equalsIgnoreCase(memberAttrName)) |
| | | while (attrs.hasMore()) |
| | | { |
| | | NamingEnumeration<?> ae = attr.getAll(); |
| | | while (ae.hasMore()) |
| | | Attribute attr = attrs.next(); |
| | | String attrID = attr.getID(); |
| | | |
| | | if (attrID.equalsIgnoreCase(memberAttrName)) |
| | | { |
| | | String value = (String)ae.next(); |
| | | if (!value.equalsIgnoreCase("cn="+serverID)) |
| | | NamingEnumeration<?> ae = attr.getAll(); |
| | | try |
| | | { |
| | | newAttr.add(value); |
| | | while (ae.hasMore()) |
| | | { |
| | | String value = (String)ae.next(); |
| | | if (!value.equalsIgnoreCase("cn="+serverID)) |
| | | { |
| | | newAttr.add(value); |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ae); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(attrs); |
| | | } |
| | | BasicAttributes newAttrs = new BasicAttributes(); |
| | | newAttrs.put(newAttr); |
| | | if (newAttr.size() > 0) |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ne); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | + getServerGroupContainerDN()); |
| | | |
| | | Set<String> result = new HashSet<String>() ; |
| | | NamingEnumeration<SearchResult> srs = null; |
| | | NamingEnumeration<? extends Attribute> ne = null; |
| | | try |
| | | { |
| | | SearchControls sc = new SearchControls(); |
| | | sc.setSearchScope(SearchControls.OBJECT_SCOPE); |
| | | NamingEnumeration<SearchResult> srs = getDirContext().search(dn, |
| | | "(objectclass=*)", sc); |
| | | srs = getDirContext().search(dn, "(objectclass=*)", sc); |
| | | |
| | | if (!srs.hasMore()) |
| | | { |
| | | return result; |
| | | } |
| | | Attributes attrs = srs.next().getAttributes(); |
| | | NamingEnumeration<? extends Attribute> ne = attrs.getAll(); |
| | | ne = attrs.getAll(); |
| | | while (ne.hasMore()) |
| | | { |
| | | Attribute attr = (Attribute)ne.next(); |
| | |
| | | |
| | | // We have the members list |
| | | NamingEnumeration<?> ae = attr.getAll(); |
| | | while (ae.hasMore()) |
| | | try |
| | | { |
| | | result.add((String)ae.next()); |
| | | while (ae.hasMore()) |
| | | { |
| | | result.add((String)ae.next()); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ae); |
| | | } |
| | | break; |
| | | } |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(srs); |
| | | handleCloseNamingEnumeration(ne); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns a set containing the servers that are registered in the |
| | |
| | | { |
| | | Set<Map<ServerProperty,Object>> result = |
| | | new HashSet<Map<ServerProperty,Object>>(); |
| | | NamingEnumeration<SearchResult> ne = null; |
| | | try |
| | | { |
| | | NamingEnumeration<SearchResult> ne; |
| | | SearchControls sc = new SearchControls(); |
| | | |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | |
| | | Object keyId = properties.get(ServerProperty.INSTANCE_KEY_ID); |
| | | if (keyId != null) |
| | | { |
| | | NamingEnumeration<SearchResult> ne2 = null; |
| | | try |
| | | { |
| | | SearchControls sc1 = new SearchControls(); |
| | |
| | | final String attrIDs[] = { "ds-cfg-public-key-certificate;binary" }; |
| | | sc1.setReturningAttributes(attrIDs); |
| | | |
| | | NamingEnumeration<SearchResult> ne2 = dirContext.search( |
| | | getInstanceKeysContainerDN(), |
| | | ne2 = dirContext.search(getInstanceKeysContainerDN(), |
| | | "(ds-cfg-key-id="+keyId+")", sc); |
| | | if (ne2.hasMore()) |
| | | { |
| | |
| | | { |
| | | LOG.log(Level.WARNING, "Could not find public key for "+properties); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ne2); |
| | | } |
| | | } |
| | | result.add(properties); |
| | | } |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ne); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | |
| | | { |
| | | Set<Map<ServerGroupProperty, Object>> result = |
| | | new HashSet<Map<ServerGroupProperty, Object>>(); |
| | | NamingEnumeration<SearchResult> ne = null; |
| | | try |
| | | { |
| | | NamingEnumeration<SearchResult> ne; |
| | | SearchControls sc = new SearchControls(); |
| | | |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ne); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | |
| | | { |
| | | Set<Map<AdministratorProperty, Object>> result = |
| | | new HashSet<Map<AdministratorProperty, Object>>(); |
| | | NamingEnumeration<SearchResult> ne = null; |
| | | try { |
| | | NamingEnumeration<SearchResult> ne; |
| | | SearchControls sc = new SearchControls(); |
| | | |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ne); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | |
| | | |
| | | boolean updatePassword = adminProperties |
| | | .containsKey(AdministratorProperty.PASSWORD); |
| | | |
| | | NamingEnumeration<?> currentPrivileges = null; |
| | | try |
| | | { |
| | | // Entry renaming |
| | |
| | | |
| | | // if modification includes 'privilege', we have to get first the |
| | | // current privileges list. |
| | | NamingEnumeration<?> currentPrivileges = null; |
| | | if (adminProperties.containsKey(AdministratorProperty.PRIVILEGE)) |
| | | { |
| | | SearchControls sc = new SearchControls(); |
| | |
| | | .getAll(); |
| | | } |
| | | |
| | | |
| | | // Replace properties, if needed. |
| | | if (adminProperties.size() > 1) |
| | | { |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(currentPrivileges); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | Set<String> set = new HashSet<String>(); |
| | | NamingEnumeration<?> ae = attr.getAll(); |
| | | while (ae.hasMore()) |
| | | try |
| | | { |
| | | set.add((String)ae.next()); |
| | | while (ae.hasMore()) |
| | | { |
| | | set.add((String)ae.next()); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | ae.close(); |
| | | } |
| | | value = set; |
| | | } |
| | |
| | | { |
| | | Set<String> set = new HashSet<String>(); |
| | | NamingEnumeration<?> ae = attr.getAll(); |
| | | while (ae.hasMore()) |
| | | try |
| | | { |
| | | set.add((String)ae.next()); |
| | | while (ae.hasMore()) |
| | | { |
| | | set.add((String)ae.next()); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | ae.close(); |
| | | } |
| | | value = set; |
| | | } |
| | |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | nameObj = nameFromDN(rdn); |
| | | String dn = nameObj + "," + getAdministratorContainerDN(); |
| | | result.put(AdministratorProperty.ADMINISTRATOR_DN, dn); |
| | | |
| | | NamingEnumeration<? extends Attribute> ne = null; |
| | | try |
| | | { |
| | | NamingEnumeration<? extends Attribute> ne = attrs.getAll(); |
| | | ne = attrs.getAll(); |
| | | while (ne.hasMore()) { |
| | | Attribute attr = ne.next(); |
| | | String attrID = attr.getID(); |
| | |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, x); |
| | | } |
| | | finally |
| | | { |
| | | handleCloseNamingEnumeration(ne); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | |
| | | searchControls.setReturningAttributes(attrIDs); |
| | | NamingEnumeration<SearchResult> keyEntries |
| | | = dirContext.search(baseDN, searchFilter, searchControls); |
| | | while (keyEntries.hasMore()) { |
| | | final SearchResult entry = keyEntries.next(); |
| | | final Attributes attrs = entry.getAttributes(); |
| | | final Attribute keyIDAttr = attrs.get(attrIDs[0]); |
| | | final Attribute keyCertAttr = attrs.get(attrIDs[1]); |
| | | if (null == keyIDAttr || null == keyCertAttr) continue; // schema viol. |
| | | certificateMap.put((String)keyIDAttr.get(), (byte[])keyCertAttr.get()); |
| | | try |
| | | { |
| | | while (keyEntries.hasMore()) { |
| | | final SearchResult entry = keyEntries.next(); |
| | | final Attributes attrs = entry.getAttributes(); |
| | | final Attribute keyIDAttr = attrs.get(attrIDs[0]); |
| | | final Attribute keyCertAttr = attrs.get(attrIDs[1]); |
| | | if (null == keyIDAttr || null == keyCertAttr) |
| | | { |
| | | continue;// schema viol. |
| | | } |
| | | certificateMap.put((String)keyIDAttr.get(), |
| | | (byte[])keyCertAttr.get()); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | keyEntries.close(); |
| | | } |
| | | } |
| | | catch (NamingException x) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void handleCloseNamingEnumeration(NamingEnumeration<?> ne) |
| | | throws ADSContextException |
| | | { |
| | | if (ne != null) |
| | | { |
| | | try |
| | | { |
| | | ne.close(); |
| | | } |
| | | catch (NamingException ex) |
| | | { |
| | | throw new ADSContextException( |
| | | ADSContextException.ErrorType.ERROR_UNEXPECTED, ex); |
| | | } |
| | | } |
| | | } |
| | | } |