directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lucasthei...@apache.org
Subject svn commit: r1613675 - in /directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template: AbstractPasswordPolicyResponder.java ModelFactoryImpl.java PasswordPolicyResponderImpl.java PasswordWarningImpl.java
Date Sat, 26 Jul 2014 16:38:27 GMT
Author: lucastheisen
Date: Sat Jul 26 16:38:27 2014
New Revision: 1613675

URL: http://svn.apache.org/r1613675
Log:
changed visibility to prevent leakage of implementation details, provided AbstractPasswordPolicyResponder

Added:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
  (with props)
Modified:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactoryImpl.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponderImpl.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarningImpl.java

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java?rev=1613675&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
Sat Jul 26 16:38:27 2014
@@ -0,0 +1,139 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.ldap.client.template;
+
+
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy;
+import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.message.Control;
+import org.apache.directory.api.ldap.model.message.Response;
+import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.api.ldap.model.message.ResultResponse;
+import org.apache.directory.ldap.client.template.exception.PasswordException;
+
+
+/**
+ * A base, abstract, implementation of <code>PasswordPolicyResponder</code>.
 
+ * Extend this class and override {@link #success(PasswordPolicy)}, 
+ * {@link #fail(ResultResponse, PasswordPolicy, ResultCodeEnum)}, or
+ * {@link #exception(LdapException)}.  If that does not offer enough
+ * flexibility, you must implement PasswordPolicyResponder yourself.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+abstract public class AbstractPasswordPolicyResponder implements PasswordPolicyResponder
+{
+    private final PasswordPolicyDecorator passwordPolicyRequestControl;
+
+
+    protected AbstractPasswordPolicyResponder( LdapApiService ldapApiService )
+    {
+        this.passwordPolicyRequestControl = new PasswordPolicyDecorator(
+            ldapApiService );
+    }
+    
+    
+    /**
+     * Translates an <code>LdapException</code> to a 
+     * <code>PasswordException</code> to be thrown when 
+     * {@link #process(PasswordPolicyOperation)} fails.
+     * 
+     * @param e
+     * @return
+     */
+    protected PasswordException exception( LdapException e )
+    {
+        return new PasswordException().setLdapException( e );
+    }
+    
+    
+    /**
+     * Returns an exception to be thrown in the case of a non SUCCESS 
+     * <code>resultCode</code>.
+     * 
+     * @param resultResponse
+     * @param passwordPolicy
+     * @param resultCode
+     * @return
+     */
+    protected PasswordException fail( ResultResponse resultResponse, 
+            PasswordPolicy passwordPolicy, ResultCodeEnum resultCode )
+    {
+        PasswordException exception = new PasswordException();
+        exception.setResultCode( resultCode );
+        if ( passwordPolicy != null
+            && passwordPolicy.getResponse() != null
+            && passwordPolicy.getResponse().getPasswordPolicyError() != null )
+        {
+            exception.setPasswordPolicyError( passwordPolicy.getResponse().getPasswordPolicyError()
);
+        }
+        return exception;
+    }
+
+
+    private PasswordPolicy getPasswordPolicy( Response response )
+    {
+        Control control = response.getControls().get( passwordPolicyRequestControl.getOid()
);
+        return control == null
+            ? null
+            : ( ( PasswordPolicyDecorator ) control ).getDecorated();
+    }
+
+
+    @Override
+    final public PasswordWarning process( PasswordPolicyOperation operation )
+        throws PasswordException
+    {
+        try
+        {
+            ResultResponse response = operation.process();
+            PasswordPolicy passwordPolicy = getPasswordPolicy( response );
+            ResultCodeEnum resultCode = response.getLdapResult().getResultCode();
+            if ( resultCode == ResultCodeEnum.SUCCESS )
+            {
+                return success( passwordPolicy );
+            }
+            else
+            {
+                throw fail( response, passwordPolicy, resultCode );
+            }
+        }
+        catch ( LdapException e )
+        {
+            throw new PasswordException().setLdapException( e );
+        }
+    }
+    
+    /**
+     * Returns a <code>PasswordWarning</code>, or <code>null</code>
if no 
+     * warnings were present in the supplied <code>passwordPolicy</code>.
+     * 
+     * @param passwordPolicy
+     * @return
+     */
+    protected PasswordWarning success( PasswordPolicy passwordPolicy ) 
+    {
+        return passwordPolicy == null
+                ? null
+                : PasswordWarningImpl.newWarning( passwordPolicy );
+    }
+}

Propchange: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/AbstractPasswordPolicyResponder.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactoryImpl.java?rev=1613675&r1=1613674&r2=1613675&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactoryImpl.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/ModelFactoryImpl.java
Sat Jul 26 16:38:27 2014
@@ -44,7 +44,7 @@ import org.apache.directory.ldap.client.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class ModelFactoryImpl implements ModelFactory
+class ModelFactoryImpl implements ModelFactory
 {
     @Override
     public AddRequest newAddRequest( Entry entry )

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponderImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponderImpl.java?rev=1613675&r1=1613674&r2=1613675&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponderImpl.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordPolicyResponderImpl.java
Sat Jul 26 16:38:27 2014
@@ -21,14 +21,6 @@ package org.apache.directory.ldap.client
 
 
 import org.apache.directory.api.ldap.codec.api.LdapApiService;
-import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy;
-import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyDecorator;
-import org.apache.directory.api.ldap.model.exception.LdapException;
-import org.apache.directory.api.ldap.model.message.Control;
-import org.apache.directory.api.ldap.model.message.Response;
-import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
-import org.apache.directory.api.ldap.model.message.ResultResponse;
-import org.apache.directory.ldap.client.template.exception.PasswordException;
 
 
 /**
@@ -36,61 +28,11 @@ import org.apache.directory.ldap.client.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class PasswordPolicyResponderImpl implements PasswordPolicyResponder
+final class PasswordPolicyResponderImpl extends AbstractPasswordPolicyResponder 
+    implements PasswordPolicyResponder
 {
-    private final PasswordPolicyDecorator passwordPolicyRequestControl;
-
-
-    public PasswordPolicyResponderImpl( LdapApiService ldapApiService )
-    {
-        this.passwordPolicyRequestControl = new PasswordPolicyDecorator(
-            ldapApiService );
-    }
-
-
-    private PasswordPolicy getPasswordPolicy( Response response )
+    PasswordPolicyResponderImpl( LdapApiService ldapApiService )
     {
-        Control control = response.getControls().get( passwordPolicyRequestControl.getOid()
);
-        return control == null
-            ? null
-            : ( ( PasswordPolicyDecorator ) control ).getDecorated();
-    }
-
-
-    @Override
-    public PasswordWarning process( PasswordPolicyOperation operation )
-        throws PasswordException
-    {
-        try
-        {
-            ResultResponse response = operation.process();
-            PasswordPolicy passwordPolicy = getPasswordPolicy( response );
-
-            ResultCodeEnum resultCode = response.getLdapResult().getResultCode();
-            if ( resultCode == ResultCodeEnum.SUCCESS )
-            {
-                if ( passwordPolicy != null )
-                {
-                    return PasswordWarningImpl.newWarning( passwordPolicy );
-                }
-                return null;
-            }
-            else
-            {
-                PasswordException exception = new PasswordException();
-                exception.setResultCode( resultCode );
-                if ( passwordPolicy != null
-                    && passwordPolicy.getResponse() != null
-                    && passwordPolicy.getResponse().getPasswordPolicyError() != null
)
-                {
-                    exception.setPasswordPolicyError( passwordPolicy.getResponse().getPasswordPolicyError()
);
-                }
-                throw exception;
-            }
-        }
-        catch ( LdapException e )
-        {
-            throw new PasswordException().setLdapException( e );
-        }
+        super( ldapApiService );
     }
 }

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarningImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarningImpl.java?rev=1613675&r1=1613674&r2=1613675&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarningImpl.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/PasswordWarningImpl.java
Sat Jul 26 16:38:27 2014
@@ -45,7 +45,7 @@ class PasswordWarningImpl implements Pas
     }
 
 
-    public static PasswordWarning newWarning( PasswordPolicy policy )
+    static PasswordWarning newWarning( PasswordPolicy policy )
     {
         PasswordPolicyResponse response = policy.getResponse();
         if ( response != null )



Mime
View raw message