| | |
| | | } |
| | | |
| | | /** The context used to retrieve information. */ |
| | | private final InitialLdapContext dirContext; |
| | | private final ConnectionWrapper connectionWrapper; |
| | | |
| | | /** |
| | |
| | | public ADSContext(ConnectionWrapper connectionWrapper) |
| | | { |
| | | this.connectionWrapper = connectionWrapper; |
| | | this.dirContext = connectionWrapper.getLdapContext(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public InitialLdapContext getDirContext() |
| | | { |
| | | return dirContext; |
| | | return connectionWrapper.getLdapContext(); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | createContainerEntry(getServerContainerDN()); |
| | | } |
| | | dirContext.createSubcontext(dn, attrs).close(); |
| | | connectionWrapper.getLdapContext().createSubcontext(dn, attrs).close(); |
| | | if (serverProperties.containsKey(ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) |
| | | { |
| | | registerInstanceKeyCertificate(serverProperties, dn); |
| | |
| | | Map<ServerProperty, Object> newServerProps = new HashMap<>(serverProperties); |
| | | newServerProps.put(ServerProperty.ID, newServerId); |
| | | LdapName newDn = makeDNFromServerProperties(newServerProps); |
| | | dirContext.rename(dn, newDn); |
| | | connectionWrapper.getLdapContext().rename(dn, newDn); |
| | | dn = newDn; |
| | | serverProperties.put(ServerProperty.ID, newServerId); |
| | | } |
| | | BasicAttributes attrs = makeAttrsFromServerProperties(serverProperties, false); |
| | | dirContext.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, attrs); |
| | | connectionWrapper.getLdapContext().modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, attrs); |
| | | if (serverProperties.containsKey(ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE)) |
| | | { |
| | | registerInstanceKeyCertificate(serverProperties, dn); |
| | |
| | | } |
| | | } |
| | | |
| | | dirContext.destroySubcontext(dn); |
| | | connectionWrapper.getLdapContext().destroySubcontext(dn); |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | |
| | | String memberAttrName = ServerGroupProperty.MEMBERS.getAttributeName(); |
| | | String filter = "(" + memberAttrName + "=cn=" + serverID + ")"; |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | | ne = dirContext.search(getServerGroupContainerDN(), filter, sc); |
| | | ne = connectionWrapper.getLdapContext().search(getServerGroupContainerDN(), filter, sc); |
| | | while (ne.hasMore()) |
| | | { |
| | | SearchResult sr = ne.next(); |
| | |
| | | newAttrs.put(newAttr); |
| | | if (newAttr.size() > 0) |
| | | { |
| | | dirContext.modifyAttributes(groupDn, DirContext.REPLACE_ATTRIBUTE, newAttrs); |
| | | connectionWrapper.getLdapContext().modifyAttributes(groupDn, DirContext.REPLACE_ATTRIBUTE, newAttrs); |
| | | } |
| | | else |
| | | { |
| | | dirContext.modifyAttributes(groupDn, DirContext.REMOVE_ATTRIBUTE, newAttrs); |
| | | connectionWrapper.getLdapContext().modifyAttributes(groupDn, DirContext.REMOVE_ATTRIBUTE, newAttrs); |
| | | } |
| | | } |
| | | } |
| | |
| | | SearchControls sc = new SearchControls(); |
| | | |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | | ne = dirContext.search(getServerContainerDN(), "(objectclass=*)", sc); |
| | | ne = connectionWrapper.getLdapContext().search(getServerContainerDN(), "(objectclass=*)", sc); |
| | | while (ne.hasMore()) |
| | | { |
| | | SearchResult sr = ne.next(); |
| | |
| | | final String attrIDs[] = { "ds-cfg-public-key-certificate;binary" }; |
| | | sc1.setReturningAttributes(attrIDs); |
| | | |
| | | ne2 = dirContext.search(getInstanceKeysContainerDN(), "(ds-cfg-key-id=" + keyId + ")", sc); |
| | | ne2 = connectionWrapper.getLdapContext().search( |
| | | getInstanceKeysContainerDN(), "(ds-cfg-key-id=" + keyId + ")", sc); |
| | | boolean found = false; |
| | | while (ne2.hasMore()) |
| | | { |
| | |
| | | attrs.put(oc); |
| | | try |
| | | { |
| | | DirContext ctx = dirContext.createSubcontext(dn, attrs); |
| | | DirContext ctx = connectionWrapper.getLdapContext().createSubcontext(dn, attrs); |
| | | ctx.close(); |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | |
| | | { |
| | | // Rename to entry |
| | | LdapName newDN = nameFromDN("cn=" + Rdn.escapeValue(newGroupId) + "," + getServerGroupContainerDN()); |
| | | dirContext.rename(dn, newDN); |
| | | connectionWrapper.getLdapContext().rename(dn, newDN); |
| | | dn = newDN; |
| | | } |
| | | |
| | |
| | | |
| | | BasicAttributes attrs = makeAttrsFromServerGroupProperties(serverGroupProperties); |
| | | // attribute modification |
| | | dirContext.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, attrs); |
| | | connectionWrapper.getLdapContext().modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, attrs); |
| | | } |
| | | catch (NameNotFoundException x) |
| | | { |
| | |
| | | { |
| | | SearchControls sc = new SearchControls(); |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | | ne = dirContext.search(getServerGroupContainerDN(), "(objectclass=*)", sc); |
| | | ne = connectionWrapper.getLdapContext().search(getServerGroupContainerDN(), "(objectclass=*)", sc); |
| | | while (ne.hasMore()) |
| | | { |
| | | SearchResult sr = ne.next(); |
| | |
| | | sc.setSearchScope(SearchControls.ONELEVEL_SCOPE); |
| | | String[] attList = { "cn", "userpassword", "ds-privilege-name", "description" }; |
| | | sc.setReturningAttributes(attList); |
| | | ne = dirContext.search(getAdministratorContainerDN(), "(objectclass=*)", sc); |
| | | ne = connectionWrapper.getLdapContext().search(getAdministratorContainerDN(), "(objectclass=*)", sc); |
| | | while (ne.hasMore()) |
| | | { |
| | | SearchResult sr = ne.next(); |
| | |
| | | try |
| | | { |
| | | Control[] controls = new Control[] { new SubtreeDeleteControl() }; |
| | | LdapContext tmpContext = dirContext.newInstance(controls); |
| | | LdapContext tmpContext = connectionWrapper.getLdapContext().newInstance(controls); |
| | | try |
| | | { |
| | | for (String dn : dns) |
| | |
| | | |
| | | try |
| | | { |
| | | DirContext ctx = dirContext.createSubcontext(dnCentralAdmin, attrs); |
| | | DirContext ctx = connectionWrapper.getLdapContext().createSubcontext(dnCentralAdmin, attrs); |
| | | ctx.close(); |
| | | } |
| | | catch (NameAlreadyBoundException x) |
| | |
| | | |
| | | try |
| | | { |
| | | dirContext.destroySubcontext(dnCentralAdmin); |
| | | connectionWrapper.getLdapContext().destroySubcontext(dnCentralAdmin); |
| | | } |
| | | catch (NameNotFoundException | NotContextException x) |
| | | { |
| | |
| | | throws ADSContextException |
| | | { |
| | | ADSContextHelper helper = new ADSContextHelper(); |
| | | helper.registerInstanceKeyCertificate(dirContext, serverProperties, serverEntryDn); |
| | | helper.registerInstanceKeyCertificate(connectionWrapper, serverProperties, serverEntryDn); |
| | | } |
| | | |
| | | /** |
| | |
| | | { 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); |
| | | NamingEnumeration<SearchResult> keyEntries = |
| | | connectionWrapper.getLdapContext().search(baseDN, searchFilter, searchControls); |
| | | try |
| | | { |
| | | while (keyEntries.hasMore()) |