directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1205531 - /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LdapLdapsServersPage.java
Date Wed, 23 Nov 2011 18:34:00 GMT
Author: pamarcelot
Date: Wed Nov 23 18:34:00 2011
New Revision: 1205531

URL: http://svn.apache.org/viewvc?rev=1205531&view=rev
Log:
Added some code to sync the order of the interceptors when adding or removing the hashing
method interceptor (interceptors below the hashing method interceptor need to get their order
incremented or decremented).

Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LdapLdapsServersPage.java

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LdapLdapsServersPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LdapLdapsServersPage.java?rev=1205531&r1=1205530&r2=1205531&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LdapLdapsServersPage.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LdapLdapsServersPage.java
Wed Nov 23 18:34:00 2011
@@ -354,7 +354,7 @@ public class LdapLdapsServersPage extend
         // Enable LDAP Server Checkbox
         enableLdapCheckbox = toolkit.createButton( composite, "Enable LDAP Server", SWT.CHECK
);
         enableLdapCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false,
gridLayout.numColumns, 1 ) );
-        
+
         // LDAP Server Port Text
         toolkit.createLabel( composite, TABULATION );
         toolkit.createLabel( composite, "Port:" );
@@ -364,7 +364,7 @@ public class LdapLdapsServersPage extend
         // Enable LDAPS Server Checkbox
         enableLdapsCheckbox = toolkit.createButton( composite, "Enable LDAPS Server", SWT.CHECK
);
         enableLdapsCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false,
gridLayout.numColumns, 1 ) );
-        
+
         // LDAPS Server Port Text
         toolkit.createLabel( composite, TABULATION );
         toolkit.createLabel( composite, "Port:" );
@@ -1333,11 +1333,30 @@ public class LdapLdapsServersPage extend
             LdapSecurityConstants hashingMethod = ( LdapSecurityConstants ) selection.getFirstElement();
             if ( hashingMethod != null )
             {
+                // Creating the hashing method interceptor
                 InterceptorBean hashingMethodInterceptor = createHashingMethodInterceptor(
hashingMethod );
 
-                DirectoryServiceBean directoryServiceBean = getDirectoryServiceBean();
+                // Getting the order of the authentication interceptor
+                int authenticationInterceptorOrder = getAuthenticationInterceptorOrder();
+
+                // Assigning the order of the hashing method interceptor
+                // It's order is: authenticationInterceptorOrder + 1
+                hashingMethodInterceptor.setInterceptorOrder( authenticationInterceptorOrder
+ 1 );
+
+                // Getting the interceptors list
+                List<InterceptorBean> interceptors = getDirectoryServiceBean().getInterceptors();
+
+                // Updating the order of the interceptors after the authentication interceptor
+                for ( InterceptorBean interceptor : interceptors )
+                {
+                    if ( interceptor.getInterceptorOrder() > authenticationInterceptorOrder
)
+                    {
+                        interceptor.setInterceptorOrder( interceptor.getInterceptorOrder()
+ 1 );
+                    }
+                }
 
-                directoryServiceBean.getInterceptors().add( hashingMethodInterceptor );
+                // Adding the hashing interceptor to the list                
+                interceptors.add( hashingMethodInterceptor );
             }
         }
     }
@@ -1348,11 +1367,53 @@ public class LdapLdapsServersPage extend
      */
     private void deleteHashingMethodInterceptor()
     {
+        // Getting the hashing method interceptor
         InterceptorBean hashingMethodInterceptor = getHashingMethodInterceptor();
-        DirectoryServiceBean directoryServiceBean = getDirectoryServiceBean();
 
-        directoryServiceBean.getInterceptors().remove( hashingMethodInterceptor );
-        // TODO Do something better for the removal (edit other interceptors orderid)
+        if ( hashingMethodInterceptor != null )
+        {
+            // Getting the order of the hashing method interceptor
+            int hashingMethodInterceptorOrder = hashingMethodInterceptor.getInterceptorOrder();
+
+            // Getting the interceptors list
+            List<InterceptorBean> interceptors = getDirectoryServiceBean().getInterceptors();
+
+            // Updating the order of the interceptors after the hashing method interceptor
+            for ( InterceptorBean interceptor : interceptors )
+            {
+                if ( interceptor.getInterceptorOrder() > hashingMethodInterceptorOrder
)
+                {
+                    interceptor.setInterceptorOrder( interceptor.getInterceptorOrder() -
1 );
+                }
+            }
+
+            // Removing the hashing interceptor to the list                
+            interceptors.remove( hashingMethodInterceptor );
+        }
     }
 
+
+    /**
+     * Gets the authentication interceptor order.
+     *
+     * @return the authentication interceptor order
+     */
+    private int getAuthenticationInterceptorOrder()
+    {
+        // Getting the list of interceptors
+        List<InterceptorBean> interceptors = getDirectoryServiceBean().getInterceptors();
+        for ( InterceptorBean interceptor : interceptors )
+        {
+            // Looking for the authentication interceptor
+            if ( "org.apache.directory.server.core.authn.AuthenticationInterceptor".equalsIgnoreCase(
interceptor
+                .getInterceptorClassName() ) )
+            {
+                // We found the authentication interceptor
+                return interceptor.getInterceptorOrder();
+            }
+        }
+
+        // No authentication interceptor was found
+        return 0;
+    }
 }



Mime
View raw message