directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1038054 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
Date Tue, 23 Nov 2010 11:11:47 GMT
Author: elecharny
Date: Tue Nov 23 11:11:47 2010
New Revision: 1038054

URL: http://svn.apache.org/viewvc?rev=1038054&view=rev
Log:
Also fixed the encoder

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java?rev=1038054&r1=1038053&r2=1038054&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
Tue Nov 23 11:11:47 2010
@@ -64,14 +64,21 @@ public class PasswordPolicyResponseContr
     @Override
     public int computeLength()
     {
-        if ( ( timeBeforeExpiration >= 0 ) && ( graceAuthNsRemaining >= 0 )
)
+        if ( timeBeforeExpiration >= 0 )
         {
             timeBeforeExpirationTagLength = TLV.getNbBytes( timeBeforeExpiration );
             warningLength = 1 + TLV.getNbBytes( timeBeforeExpirationTagLength ) + timeBeforeExpirationTagLength;
-
+        }
+        
+        
+        if ( graceAuthNsRemaining >= 0 )
+        {
             graceAuthNsRemainingTagLength = TLV.getNbBytes( graceAuthNsRemaining );
-            warningLength += 1 + TLV.getNbBytes( graceAuthNsRemainingTagLength ) + graceAuthNsRemainingTagLength;
-            
+            warningLength = 1 + TLV.getNbBytes( graceAuthNsRemainingTagLength ) + graceAuthNsRemainingTagLength;
+        }
+
+        if ( warningLength != 0 )
+        {
             ppolicySeqLength = 1 + TLV.getNbBytes( warningLength ) + warningLength;
         }
 
@@ -106,9 +113,7 @@ public class PasswordPolicyResponseContr
 
         if ( ( timeBeforeExpiration < 0 ) && ( graceAuthNsRemaining < 0 ) &&
( ppolicyError == null ) )
         {
-            // Encode the empty Sequence tag
-            buffer.put( UniversalTag.SEQUENCE.getValue() );
-            buffer.put( (byte)0 );
+            return buffer;
         }
         else
         {
@@ -116,19 +121,24 @@ public class PasswordPolicyResponseContr
             buffer.put( UniversalTag.SEQUENCE.getValue() );
             buffer.put( TLV.getBytes( ppolicySeqLength ) );
 
-            if ( ( timeBeforeExpiration >= 0 ) && ( graceAuthNsRemaining >=
0 ) )
+            if ( warningLength > 0 )
             {
                 // Encode the Warning tag
                 buffer.put( (byte)PasswordPolicyResponseControlTags.PPOLICY_WARNING_TAG.getValue()
);
                 buffer.put( TLV.getBytes( warningLength ) );
-                
-                buffer.put( ( byte ) PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG.getValue()
);
-                buffer.put( TLV.getBytes( timeBeforeExpirationTagLength ) );
-                buffer.put( Value.getBytes( timeBeforeExpiration ) );
-    
-                buffer.put( ( byte ) PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG.getValue()
);
-                buffer.put( TLV.getBytes( graceAuthNsRemainingTagLength ) );
-                buffer.put( Value.getBytes( graceAuthNsRemaining ) );
+
+                if ( timeBeforeExpiration >= 0 )
+                {
+                    buffer.put( ( byte ) PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG.getValue()
);
+                    buffer.put( TLV.getBytes( timeBeforeExpirationTagLength ) );
+                    buffer.put( Value.getBytes( timeBeforeExpiration ) );
+                }
+                else if ( graceAuthNsRemaining >= 0 )
+                {
+                    buffer.put( ( byte ) PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG.getValue()
);
+                    buffer.put( TLV.getBytes( graceAuthNsRemainingTagLength ) );
+                    buffer.put( Value.getBytes( graceAuthNsRemaining ) );
+                }
             }
     
             if ( ppolicyError != null )
@@ -191,8 +201,7 @@ public class PasswordPolicyResponseContr
         {
             sb.append( "   timeBeforeExpiration          : '" ).append( timeBeforeExpiration
).append( '\n' );
         }
-        
-        if ( graceAuthNsRemaining >= 0 )
+        else if ( graceAuthNsRemaining >= 0 )
         {
             sb.append( "   graceAuthNsRemaining          : '" ).append( graceAuthNsRemaining
).append( '\n' );
         }



Mime
View raw message