You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2015/07/14 07:23:55 UTC

svn commit: r1690863 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/api/ core-api/src/test/java/org/apache/directory/server/core/api/ core-shared/src/main/java/org/apache/directory/server/core/shared/ intercepto...

Author: kayyagari
Date: Tue Jul 14 05:23:54 2015
New Revision: 1690863

URL: http://svn.apache.org/r1690863
Log:
o fixed the checkPwdReset() method by removing the wrong negation (DIRSERVER-2082)
o added a flag to DefaultCoreSession to detect if the session requires a password reset
o updated a test to check these changes

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/CoreSession.java
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java
    directory/apacheds/trunk/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java
    directory/apacheds/trunk/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ppolicy/PasswordPolicyIT.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/CoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/CoreSession.java?rev=1690863&r1=1690862&r2=1690863&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/CoreSession.java (original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/CoreSession.java Tue Jul 14 05:23:54 2015
@@ -783,4 +783,21 @@ public interface CoreSession
      * @throws LdapException If the operation failed
      */
     void unbind( UnbindRequest unbindRequest ) throws LdapException;
+    
+    
+    /**
+     * @return true if the password must be changed
+     */
+    boolean isPwdMustChange();
+
+    
+    /**
+     * Sets if the passwords must be changed. If set to true then this session is
+     * only allowed to perform modify password, bind, unbind, abandon and StartTLS
+     * extended operation only as specified in section #8.1.2.2 of the password policy
+     * <a href="http://tools.ietf.org/id/draft-behera-ldap-password-policy-10.txt">spec</a> 
+     * 
+     * @param pwdMustChange
+     */
+    void setPwdMustChange( boolean pwdMustChange );
 }

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java?rev=1690863&r1=1690862&r2=1690863&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java (original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/api/MockCoreSession.java Tue Jul 14 05:23:54 2015
@@ -96,6 +96,8 @@ public class MockCoreSession implements
     /** A reference to the ObjectClass AT */
     protected AttributeType OBJECT_CLASS_AT;
 
+    /** flag to indicate if the password must be changed */
+    private boolean pwdMustChange;
 
     public MockCoreSession( LdapPrincipal principal, DirectoryService directoryService )
     {
@@ -962,4 +964,23 @@ public class MockCoreSession implements
     {
         this.directoryService = directoryService;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isPwdMustChange() 
+    {
+        return pwdMustChange;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setPwdMustChange( boolean pwdMustChange ) 
+    {
+        this.pwdMustChange = pwdMustChange;
+    }
+
 }

Modified: directory/apacheds/trunk/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java?rev=1690863&r1=1690862&r2=1690863&view=diff
==============================================================================
--- directory/apacheds/trunk/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java (original)
+++ directory/apacheds/trunk/core-shared/src/main/java/org/apache/directory/server/core/shared/DefaultCoreSession.java Tue Jul 14 05:23:54 2015
@@ -123,6 +123,8 @@ public class DefaultCoreSession implemen
     /** The associated IoSession */
     private IoSession ioSession;
 
+    /** flag to indicate if the password must be changed */
+    private boolean pwdMustChange;
 
     /**
      * Creates a new instance of a DefaultCoreSession
@@ -1349,4 +1351,21 @@ public class DefaultCoreSession implemen
         return new SortedEntryCursor( btree, recMan, file );
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isPwdMustChange() 
+    {
+        return pwdMustChange;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setPwdMustChange( boolean pwdMustChange ) 
+    {
+        this.pwdMustChange = pwdMustChange;
+    }
 }

Modified: directory/apacheds/trunk/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java?rev=1690863&r1=1690862&r2=1690863&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java Tue Jul 14 05:23:54 2015
@@ -126,8 +126,6 @@ public class AuthenticationInterceptor e
 
     private CoreSession adminSession;
 
-    private Set<String> pwdResetSet = new HashSet<String>();
-
     // pwdpolicy state attribute types
     private AttributeType AT_PWD_RESET;
 
@@ -759,7 +757,7 @@ public class AuthenticationInterceptor e
                 if ( isPwdMustReset( userEntry ) )
                 {
                     pwdRespCtrl.getResponse().setPasswordPolicyError( PasswordPolicyErrorEnum.CHANGE_AFTER_RESET );
-                    pwdResetSet.add( bindDn.getNormName() );
+                    bindContext.getSession().setPwdMustChange( true );
                 }
 
                 bindContext.addResponseControl( pwdRespCtrl );
@@ -909,9 +907,11 @@ public class AuthenticationInterceptor e
 
         pwdModDetails = getPwdModDetails( modifyContext, policyConfig );
 
+        CoreSession userSession = modifyContext.getSession();
+        
         if ( pwdModDetails.isPwdModPresent() )
         {
-            if ( pwdResetSet.contains( userDn.getNormName() ) && !pwdModDetails.isDelete() )
+            if ( userSession.isPwdMustChange() && !pwdModDetails.isDelete() )
             {
                 if ( pwdModDetails.isOtherModExists() )
                 {
@@ -965,7 +965,7 @@ public class AuthenticationInterceptor e
 
             Entry entry = modifyContext.getEntry();
 
-            boolean removeFromPwdResetSet = false;
+            boolean removePwdReset = false;
 
             List<Modification> mods = new ArrayList<Modification>();
 
@@ -1103,7 +1103,7 @@ public class AuthenticationInterceptor e
                     else
                     {
                         pwdMustChangeMod = new DefaultModification( REMOVE_ATTRIBUTE, pwdMustChangeAt );
-                        removeFromPwdResetSet = true;
+                        removePwdReset = true;
                     }
 
                     mods.add( pwdMustChangeMod );
@@ -1164,9 +1164,9 @@ public class AuthenticationInterceptor e
 
             directoryService.getPartitionNexus().modify( internalModifyCtx );
 
-            if ( removeFromPwdResetSet || pwdModDetails.isDelete() )
+            if ( removePwdReset || pwdModDetails.isDelete() )
             {
-                pwdResetSet.remove( userDn.getNormName() );
+                userSession.setPwdMustChange( false );
             }
         }
         else
@@ -1250,14 +1250,6 @@ public class AuthenticationInterceptor e
     public void unbind( UnbindOperationContext unbindContext ) throws LdapException
     {
         next( unbindContext );
-
-        // remove the Dn from the password reset Set
-        // we do not perform a check to see if the reset flag in the associated ppolicy is enabled
-        // cause that requires fetching the ppolicy first, which requires a lookup for user entry
-        if ( !directoryService.isPwdPolicyEnabled() )
-        {
-            pwdResetSet.remove( unbindContext.getDn().getNormName() );
-        }
     }
 
 
@@ -1463,8 +1455,10 @@ public class AuthenticationInterceptor e
             return false;
         }
 
+        CoreSession userSession = operationContext.getSession();
+        
         // see sections 7.8 and 7.2 of the ppolicy draft
-        if ( policyConfig.isPwdMustChange() && pwdResetSet.contains( userEntry.getDn().getNormName() ) )
+        if ( policyConfig.isPwdMustChange() && userSession.isPwdMustChange() )
         {
             return false;
         }
@@ -1555,13 +1549,11 @@ public class AuthenticationInterceptor e
      */
     private void checkPwdReset( OperationContext opContext ) throws LdapException
     {
-        if ( !directoryService.isPwdPolicyEnabled() )
+        if ( directoryService.isPwdPolicyEnabled() )
         {
             CoreSession session = opContext.getSession();
 
-            Dn userDn = session.getAuthenticatedPrincipal().getDn();
-
-            if ( pwdResetSet.contains( userDn.getNormName() ) )
+            if ( session.isPwdMustChange() )
             {
                 boolean isPPolicyReqCtrlPresent = opContext
                     .hasRequestControl( PasswordPolicy.OID );

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ppolicy/PasswordPolicyIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ppolicy/PasswordPolicyIT.java?rev=1690863&r1=1690862&r2=1690863&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ppolicy/PasswordPolicyIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/ppolicy/PasswordPolicyIT.java Tue Jul 14 05:23:54 2015
@@ -1426,6 +1426,11 @@ public class PasswordPolicyIT extends Ab
        assertEquals( PasswordPolicyErrorEnum.CHANGE_AFTER_RESET, 
            getPwdRespCtrl( bindResponse ).getResponse().getPasswordPolicyError() );
 
+       // in this case all other operations must be disallowed
+       // see section #8.1.2.2.  Password must be changed now
+       Entry mustbeNull = userConnection.lookup( "ou=system" );
+       assertNull(mustbeNull);
+       
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( userDn );
        modifyRequest.replace( "userPassword", "123456" );