directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject [directory-fortress-core] branch FC-238 updated: Relax control no longer works with 2.0 ldap api
Date Wed, 23 Jun 2021 19:48:56 GMT
This is an automated email from the ASF dual-hosted git repository.

smckinney pushed a commit to branch FC-238
in repository https://gitbox.apache.org/repos/asf/directory-fortress-core.git


The following commit(s) were added to refs/heads/FC-238 by this push:
     new faf737e  Relax control no longer works with 2.0 ldap api
faf737e is described below

commit faf737e60f64f65c1bcaf8f90e9e4a2ebe36d1e6
Author: Shawn McKinney <smckinney@symas.com>
AuthorDate: Wed Jun 23 14:48:51 2021 -0500

    Relax control no longer works with 2.0 ldap api
---
 .../fortress/core/ldap/LdapDataProvider.java       |  4 +-
 .../fortress/core/ldap/RelaxControlDecorator.java  | 34 +++++++++++
 .../fortress/core/ldap/RelaxControlFactory.java    | 70 ++++++++++++++++++++++
 .../directory/fortress/core/PolicyMgrConsole.java  | 25 ++++++++
 .../fortress/core/ProcessMenuCommand.java          | 47 +--------------
 5 files changed, 133 insertions(+), 47 deletions(-)

diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java b/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java
index d48517b..4ce8d9f 100644
--- a/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java
@@ -275,7 +275,7 @@ public abstract class LdapDataProvider
         // TODO: FIXME #2
         if ( setRelaxControl )
         {
-            //addRequest.addControl( new RelaxControlImpl() );
+            addRequest.addControl( new RelaxControlImpl() );
         }
         AddResponse response = connection.add( addRequest );
         ResultCodeEnum.processResponse(response);
@@ -353,7 +353,7 @@ public abstract class LdapDataProvider
         // TODO: FIXME #2
         if ( setRelaxControl )
         {
-            //modRequest.addControl( new RelaxControlImpl() );
+            modRequest.addControl( new RelaxControlImpl() );
         }
         modRequest.setName( new Dn( dn ) );
         ModifyResponse response = connection.modify( modRequest );
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlDecorator.java
b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlDecorator.java
new file mode 100644
index 0000000..70ef78f
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlDecorator.java
@@ -0,0 +1,34 @@
+package org.apache.directory.fortress.core.ldap;
+
+
+import org.apache.directory.api.asn1.Asn1Object;
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.ldap.codec.api.ControlDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+
+import java.nio.ByteBuffer;
+
+
+public class RelaxControlDecorator extends ControlDecorator<RelaxControl> implements
RelaxControl
+{
+    public RelaxControlDecorator(LdapApiService codec, RelaxControl control)
+    {
+        super(codec, control);
+    }
+
+    public int computeLength()
+    {
+        return 0;
+    }
+
+    public Asn1Object decode(byte[] controlBytes) throws DecoderException
+    {
+        return this;
+    }
+
+    public ByteBuffer encode(ByteBuffer buffer) throws EncoderException
+    {
+        return buffer;
+    }
+}
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java
b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java
new file mode 100644
index 0000000..a241393
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java
@@ -0,0 +1,70 @@
+package org.apache.directory.fortress.core.ldap;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.CodecControl;
+import org.apache.directory.api.ldap.codec.api.ControlContainer;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.Control;
+
+
+/**
+ * A codec {@link ControlFactory} implementation for {@link RelaxControl} controls.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class RelaxControlFactory implements ControlFactory<RelaxControl>
+{
+    /** The LDAP codec responsible for encoding and decoding Cascade Controls */
+    private LdapApiService codec;
+
+
+    /**
+     * Creates a new instance of TransactionSpecificationFactory.
+     *
+     * @param codec The LDAP codec
+     */
+    public RelaxControlFactory( LdapApiService codec )
+    {
+        this.codec = codec;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getOid()
+    {
+        return RelaxControl.OID;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public CodecControl<RelaxControl> newControl()
+    {
+        return new RelaxControlDecorator( codec, new RelaxControlImpl() );
+    }
+
+
+    public void encodeValue(Asn1Buffer var1, Control var2)
+    {
+
+    }
+
+    public void decodeValue(ControlContainer var1, Control var2, byte[] var3) throws DecoderException
+    {
+
+    }
+
+    public void decodeValue(Control var1, byte[] var2) throws DecoderException
+    {
+
+    }
+
+}
diff --git a/src/test/java/org/apache/directory/fortress/core/PolicyMgrConsole.java b/src/test/java/org/apache/directory/fortress/core/PolicyMgrConsole.java
index 48786a0..f31f8f7 100755
--- a/src/test/java/org/apache/directory/fortress/core/PolicyMgrConsole.java
+++ b/src/test/java/org/apache/directory/fortress/core/PolicyMgrConsole.java
@@ -22,6 +22,8 @@ package org.apache.directory.fortress.core;
 
 import org.apache.directory.fortress.core.model.PwPolicy;
 import org.apache.directory.fortress.core.impl.TestUtils;
+import org.apache.directory.fortress.core.model.Session;
+import org.apache.directory.fortress.core.model.User;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -163,4 +165,27 @@ class PolicyMgrConsole
         }
         ReaderUtil.readChar();
     }
+
+
+    void assignPolicy()
+    {
+        try
+        {
+            ReaderUtil.clearScreen();
+            System.out.println("Enter userId");
+            String userId = ReaderUtil.readLn();
+            System.out.println("Enter password policy name or NULL to skip");
+            String plcyNm = ReaderUtil.readLn();
+            pm.updateUserPolicy( userId, plcyNm );
+            System.out.println("userId [" + userId + "]");
+            System.out.println("policy name [" + plcyNm + "]");
+            System.out.println("has been updated");
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("assignPolicy caught SecurityException rc=" + e.getErrorId() + ", msg="
+ e.getMessage(), e);
+        }
+        ReaderUtil.readChar();
+    }
 }
diff --git a/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java b/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
index 8a6c378..bb85eaf 100755
--- a/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
+++ b/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
@@ -902,51 +902,7 @@ class ProcessMenuCommand
                         policyConsole.add();
                         break;
                     case '2':
-                        //policyConsole.updatePolicy();
-                        break;
-                    case '3':
-                        //policyConsole.deletePolicy();
-                        break;
-                    case '4':
-                        //policyConsole.readPolicy();
-                        break;
-                    case '5':
-                        //policyConsole.findPolicies();
-                        break;
-                    case '6':
-                        //policyConsole.updateUserPolicy();
-                        break;
-                    case '7':
-                        //policyConsole.deleteUserPasswordPolicy();
-                        break;
-                    case '8':
-                        //policyConsole.readOperationalAttributes();
-                        break;
-                    case '9':
-                        //policyConsole.resetUserPassword();
-                        break;
-                    case '0':
-                        //adminConsole.unlockAccount();
-                        break;
-                    case 'a':
-                    case 'A':
-                        //policyConsole.lockUserAccount();
-                        break;
-                    case 'b':
-                    case 'B':
-                        //policyConsole.clearResetFlag();
-                        break;
-                    case 'c':
-                    case 'C':
-                        //policyConsole.checkPasswordPolicy();
-                        break;
-                    case 'd':
-                    case 'D':
-                        //policyConsole.getLockedUsers();
-                        break;
-                    case 'e':
-                    case 'E':
-                        //policyConsole.isLockedUser();
+                        policyConsole.assignPolicy();
                         break;
                     case 'q':
                     case 'Q':
@@ -972,6 +928,7 @@ class ProcessMenuCommand
         ReaderUtil.clearScreen();
         System.out.println( "CHOOSE PASSWORD POLICY FUNCTION:" );
         System.out.println( "1. Create Password Policy" );
+        System.out.println( "2. Assign Password Policy to User" );
         System.out.println( "Enter q or Q to return to previous menu" );
     }
 

Mime
View raw message