summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFraser Tweedale <ftweedal@redhat.com>2015-11-30 14:01:38 +1100
committerFraser Tweedale <ftweedal@redhat.com>2016-01-21 12:10:54 +1100
commit6371ea5cd0abf64ab755b8d7b410c879f5051936 (patch)
treef3b3fda0518ba40cabb6020d695f6aacfeab2907
parent6ed6230c9bed4e2619467b7f9f422a52b07295b8 (diff)
downloadpki-6371ea5cd0abf64ab755b8d7b410c879f5051936.tar.gz
pki-6371ea5cd0abf64ab755b8d7b410c879f5051936.tar.xz
pki-6371ea5cd0abf64ab755b8d7b410c879f5051936.zip
Add LDAPPostReadControl class
The LDAPPostReadControl can be used to read an entry after perfoming an add, modify or modrdn, giving atomic access to operational attributes. Part of: https://fedorahosted.org/pki/ticket/1700
-rw-r--r--base/util/src/com/netscape/cmsutil/ldap/LDAPPostReadControl.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/base/util/src/com/netscape/cmsutil/ldap/LDAPPostReadControl.java b/base/util/src/com/netscape/cmsutil/ldap/LDAPPostReadControl.java
new file mode 100644
index 000000000..569d665db
--- /dev/null
+++ b/base/util/src/com/netscape/cmsutil/ldap/LDAPPostReadControl.java
@@ -0,0 +1,106 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2015 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.cmsutil.ldap;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import netscape.ldap.LDAPAttribute;
+import netscape.ldap.LDAPAttributeSet;
+import netscape.ldap.LDAPControl;
+import netscape.ldap.LDAPEntry;
+import netscape.ldap.LDAPException;
+import netscape.ldap.ber.stream.BERElement;
+import netscape.ldap.ber.stream.BEROctetString;
+import netscape.ldap.ber.stream.BERSequence;
+import netscape.ldap.ber.stream.BERTag;
+import netscape.ldap.client.JDAPBERTagDecoder;
+
+public class LDAPPostReadControl extends LDAPControl {
+
+ private static final long serialVersionUID = -3988578305868188089L;
+
+ public final static String OID_POSTREAD = "1.3.6.1.1.13.2";
+
+ private LDAPEntry entry = null;
+
+ static {
+ try {
+ register(OID_POSTREAD, LDAPPostReadControl.class);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Response control constructor.
+ *
+ * This is called automatically by response processing code,
+ * should not need to be called by user.
+ */
+ public LDAPPostReadControl(String oid, boolean critical, byte[] value)
+ throws LDAPException, IOException {
+ super(OID_POSTREAD, critical, value);
+ if (!oid.equals(OID_POSTREAD)) {
+ throw new LDAPException(
+ "oid must be LDAPPostReadControl.OID_POSTREAD",
+ LDAPException.PARAM_ERROR);
+ }
+
+ ByteArrayInputStream in = new ByteArrayInputStream(value);
+ int[] numRead = new int[1];
+ BERTag tag = (BERTag)
+ BERElement.getElement(new JDAPBERTagDecoder(), in, numRead);
+ BERSequence seq = (BERSequence)tag.getValue();
+
+ BEROctetString name = (BEROctetString)seq.elementAt(0);
+ byte buf[] = name.getValue();
+ String dn = null;
+ if (buf != null)
+ dn = new String(buf, "UTF8");
+
+ BERSequence attrs = (BERSequence)seq.elementAt(1);
+ LDAPAttributeSet attrSet = new LDAPAttributeSet();
+ for (int i = 0; i < attrs.size(); i++) {
+ attrSet.add(new LDAPAttribute(attrs.elementAt(i)));
+ }
+
+ entry = new LDAPEntry(dn, attrSet);
+ }
+
+ /**
+ * Request control constructor.
+ */
+ public LDAPPostReadControl(boolean critical, String[] attrs) {
+ super(OID_POSTREAD, critical, null);
+ BERSequence ber_attrs = new BERSequence();
+ for (int i = 0; i < attrs.length; i++) {
+ ber_attrs.addElement(new BEROctetString(attrs[i]));
+ }
+ m_value = flattenBER(ber_attrs);
+ }
+
+ /**
+ * Get the entry from the control.
+ *
+ * Returns null if constructed as a request control.
+ */
+ public LDAPEntry getEntry() {
+ return entry;
+ }
+};