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 2010/11/11 07:24:47 UTC
svn commit: r1033822 - in /directory/shared/trunk/ldap/src:
main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/
test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/
Author: kayyagari
Date: Thu Nov 11 06:24:46 2010
New Revision: 1033822
URL: http://svn.apache.org/viewvc?rev=1033822&view=rev
Log:
o fixed the encoding of ppolicy response control
o added a test
Modified:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControl.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlGrammar.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlStates.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.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=1033822&r1=1033821&r2=1033822&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 Thu Nov 11 06:24:46 2010
@@ -48,9 +48,11 @@ public class PasswordPolicyResponseContr
/** number representing the password policy error */
private PasswordPolicyErrorEnum ppolicyError;
- private int controlLen = 0;
-
+ private int valueLen = 0;
+ private transient int timeBeforeExpirationTagLen;
+ private transient int graceAuthNsRemainingTagLen;
+
public PasswordPolicyResponseControl()
{
super( PasswordPolicyRequestControl.CONTROL_OID );
@@ -62,19 +64,24 @@ public class PasswordPolicyResponseContr
{
if ( timeBeforeExpiration >= 0 )
{
- controlLen = 1 + ( 2 * TLV.getNbBytes( timeBeforeExpiration ) );
+ int timeBefExpLen = Value.getNbBytes( timeBeforeExpiration );
+ timeBeforeExpirationTagLen = 1 + TLV.getNbBytes( timeBefExpLen ) + timeBefExpLen;
+ valueLen = 1 + TLV.getNbBytes( timeBeforeExpirationTagLen ) + timeBeforeExpirationTagLen;
}
else if ( graceAuthNsRemaining >= 0 )
{
- controlLen = 1 + ( 2 * TLV.getNbBytes( graceAuthNsRemaining ) );
+ int graceAuthRemLen = Value.getNbBytes( graceAuthNsRemaining );
+ graceAuthNsRemainingTagLen = 1 + TLV.getNbBytes( graceAuthRemLen ) + graceAuthRemLen;
+ valueLen = 1 + TLV.getNbBytes( graceAuthNsRemainingTagLen ) + graceAuthNsRemainingTagLen;
}
if ( ppolicyError != null )
{
- controlLen += 1 + ( 2 * TLV.getNbBytes( ppolicyError.getValue() ) );
+ int ppolicyErrLen = Value.getNbBytes( ppolicyError.getValue() );
+ valueLen += 1 + TLV.getNbBytes( ppolicyErrLen ) + ppolicyErrLen;
}
- return super.computeLength( controlLen );
+ return super.computeLength( valueLen );
}
@@ -89,7 +96,7 @@ public class PasswordPolicyResponseContr
// Encode the Control envelop
super.encode( buffer );
- if( controlLen > 0 )
+ if( valueLen > 0 )
{
// Encode the OCTET_STRING tag
buffer.put( UniversalTag.OCTET_STRING.getValue() );
@@ -99,20 +106,20 @@ public class PasswordPolicyResponseContr
if ( timeBeforeExpiration >= 0 )
{
buffer.put( ( byte ) PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG.getValue() );
- buffer.put( TLV.getBytes( TLV.getNbBytes( timeBeforeExpiration ) ) );
- buffer.put( Value.getBytes( timeBeforeExpiration ) );
+ buffer.put( TLV.getBytes( timeBeforeExpirationTagLen ) );
+ Value.encode( buffer, timeBeforeExpiration );
}
else if ( graceAuthNsRemaining >= 0 )
{
buffer.put( ( byte ) PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG.getValue() );
- buffer.put( TLV.getBytes( TLV.getNbBytes( graceAuthNsRemaining ) ) );
- buffer.put( Value.getBytes( graceAuthNsRemaining ) );
+ buffer.put( TLV.getBytes( graceAuthNsRemainingTagLen ) );
+ Value.encode( buffer, graceAuthNsRemaining );
}
if ( ppolicyError != null )
{
buffer.put( UniversalTag.ENUMERATED.getValue() );
- buffer.put( TLV.getBytes( TLV.getNbBytes( ppolicyError.getValue() ) ) );
+ buffer.put( ( byte ) 0x01 );
buffer.put( Value.getBytes( ppolicyError.getValue() ) );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlGrammar.java?rev=1033822&r1=1033821&r2=1033822&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlGrammar.java Thu Nov 11 06:24:46 2010
@@ -39,6 +39,22 @@ import org.slf4j.LoggerFactory;
/**
* Grammar for decoding PasswordPolicyResponseControl.
*
+ * PasswordPolicyResponseValue ::= SEQUENCE {
+ * warning [0] CHOICE {
+ * timeBeforeExpiration [0] INTEGER (0 .. maxInt),
+ * graceAuthNsRemaining [1] INTEGER (0 .. maxInt) } OPTIONAL,
+ *
+ * error [1] ENUMERATED {
+ * passwordExpired (0),
+ * accountLocked (1),
+ * changeAfterReset (2),
+ * passwordModNotAllowed (3),
+ * mustSupplyOldPassword (4),
+ * insufficientPasswordQuality (5),
+ * passwordTooShort (6),
+ * passwordTooYoung (7),
+ * passwordInHistory (8) } OPTIONAL }
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PasswordPolicyResponseControlGrammar extends AbstractGrammar
@@ -58,10 +74,13 @@ public class PasswordPolicyResponseContr
setName( PasswordPolicyResponseControlGrammar.class.getName() );
super.transitions = new GrammarTransition[PasswordPolicyResponseControlStates.END_STATE.ordinal()][256];
-
+
+ // PasswordPolicyResponseValue ::= SEQUENCE {
+ // ...
super.transitions[PasswordPolicyResponseControlStates.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
- PasswordPolicyResponseControlStates.START_STATE, PasswordPolicyResponseControlStates.START_STATE, UniversalTag.SEQUENCE.getValue(),
- new GrammarAction( "Initialization" )
+ PasswordPolicyResponseControlStates.START_STATE, PasswordPolicyResponseControlStates.SEQ_STATE,
+ UniversalTag.SEQUENCE.getValue(),
+ new GrammarAction( "Initializating PasswordPolicyResponseControl" )
{
public void action( Asn1Container container ) throws DecoderException
{
@@ -72,10 +91,25 @@ public class PasswordPolicyResponseContr
}
} );
- super.transitions[PasswordPolicyResponseControlStates.START_STATE.ordinal()][PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG
- .getValue()] = new GrammarTransition( PasswordPolicyResponseControlStates.START_STATE,
- PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE,
- PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG.getValue(), new GrammarAction(
+ // PasswordPolicyResponseValue ::= SEQUENCE {
+ // warning [0] CHOICE {
+ // timeBeforeExpiration [0]
+ super.transitions[PasswordPolicyResponseControlStates.SEQ_STATE.ordinal()][PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG
+ .getValue()] = new GrammarTransition( PasswordPolicyResponseControlStates.SEQ_STATE,
+ PasswordPolicyResponseControlStates.PPOLICY_TIME_BEFORE_EXPIRATION_TAG_STATE,
+ PasswordPolicyResponseControlTags.TIME_BEFORE_EXPIRATION_TAG.getValue(), new GrammarAction( "read the ppolicy time before expiration warning tag" )
+ {
+ public void action( Asn1Container container ) throws DecoderException
+ {
+
+ }
+ } );
+
+ // timeBeforeExpiration [0] INTEGER (0 .. maxInt)
+ super.transitions[PasswordPolicyResponseControlStates.PPOLICY_TIME_BEFORE_EXPIRATION_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
+ = new GrammarTransition( PasswordPolicyResponseControlStates.PPOLICY_TIME_BEFORE_EXPIRATION_TAG_STATE,
+ PasswordPolicyResponseControlStates.PPOLICY_TIME_BEFORE_EXPIRATION_STATE,
+ UniversalTag.INTEGER.getValue(), new GrammarAction(
"set time before expiration value" )
{
public void action( Asn1Container container ) throws DecoderException
@@ -85,12 +119,12 @@ public class PasswordPolicyResponseContr
try
{
int timeBeforeExp = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
-
- if( IS_DEBUG )
+
+ if ( IS_DEBUG )
{
LOG.debug( "timeBeforeExpiration {}", timeBeforeExp );
}
-
+
ppolicyRespContainer.getPasswordPolicyResponseControl().setTimeBeforeExpiration( timeBeforeExp );
}
catch ( IntegerDecoderException e )
@@ -104,24 +138,25 @@ public class PasswordPolicyResponseContr
}
} );
- super.transitions[PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] = new GrammarTransition(
- PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE, PasswordPolicyResponseControlStates.END_STATE,
- UniversalTag.ENUMERATED.getValue(), new GrammarAction( "set ppolicy error value" )
- {
- public void action( Asn1Container container ) throws DecoderException
- {
- PasswordPolicyResponseControlContainer ppolicyRespContainer = ( PasswordPolicyResponseControlContainer ) container;
-
- setPasswordPolicyError( ppolicyRespContainer );
-
- ppolicyRespContainer.setGrammarEndAllowed( true );
- }
- } );
-
- super.transitions[PasswordPolicyResponseControlStates.START_STATE.ordinal()][PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG
- .getValue()] = new GrammarTransition( PasswordPolicyResponseControlStates.START_STATE,
- PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE,
- PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG.getValue(), new GrammarAction(
+ // PasswordPolicyResponseValue ::= SEQUENCE {
+ // warning [0] CHOICE {
+ // graceAuthNsRemaining [1]
+ super.transitions[PasswordPolicyResponseControlStates.SEQ_STATE.ordinal()][PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG
+ .getValue()] = new GrammarTransition( PasswordPolicyResponseControlStates.SEQ_STATE,
+ PasswordPolicyResponseControlStates.PPOLICY_GRACE_AUTHNS_REMAINING_TAG_STATE,
+ PasswordPolicyResponseControlTags.GRACE_AUTHNS_REMAINING_TAG.getValue(), new GrammarAction( "read the ppolicy grace auth warning tag" )
+ {
+ public void action( Asn1Container container ) throws DecoderException
+ {
+
+ }
+ } );
+
+ // graceAuthNsRemaining [1] INTEGER (0 .. maxInt)
+ super.transitions[PasswordPolicyResponseControlStates.PPOLICY_GRACE_AUTHNS_REMAINING_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()]
+ = new GrammarTransition( PasswordPolicyResponseControlStates.PPOLICY_GRACE_AUTHNS_REMAINING_TAG_STATE,
+ PasswordPolicyResponseControlStates.PPOLICY_GRACE_AUTHNS_REMAINING_STATE,
+ UniversalTag.INTEGER.getValue(), new GrammarAction(
"set number of grace authentications remaining" )
{
public void action( Asn1Container container ) throws DecoderException
@@ -131,12 +166,12 @@ public class PasswordPolicyResponseContr
try
{
int graceAuthNum = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
-
- if( IS_DEBUG )
+
+ if ( IS_DEBUG )
{
LOG.debug( "graceAuthNsRemaining {}", graceAuthNum );
}
-
+
ppolicyRespContainer.getPasswordPolicyResponseControl().setGraceAuthNsRemaining( graceAuthNum );
}
catch ( IntegerDecoderException e )
@@ -150,14 +185,59 @@ public class PasswordPolicyResponseContr
}
} );
- super.transitions[PasswordPolicyResponseControlStates.START_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] = new GrammarTransition(
- PasswordPolicyResponseControlStates.START_STATE, PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE,
+
+ // transition to the ppolic error after the PPOLICY_TIME_BEFORE_EXPIRATION_STATE
+ // PasswordPolicyResponseValue ::= SEQUENCE {
+ // warning [0] CHOICE {
+ // timeBeforeExpiration [0] INTEGER (0 .. maxInt),
+ //
+ // error [1] ENUMERATED {
+ super.transitions[PasswordPolicyResponseControlStates.PPOLICY_TIME_BEFORE_EXPIRATION_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] = new GrammarTransition(
+ PasswordPolicyResponseControlStates.PPOLICY_TIME_BEFORE_EXPIRATION_STATE, PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE,
+ UniversalTag.ENUMERATED.getValue(), new GrammarAction( "set ppolicy error value after reading the timeBeforeExpiration value" )
+ {
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ PasswordPolicyResponseControlContainer ppolicyRespContainer = ( PasswordPolicyResponseControlContainer ) container;
+
+ setPasswordPolicyError( ppolicyRespContainer );
+
+ ppolicyRespContainer.setGrammarEndAllowed( true );
+ }
+ } );
+
+
+ // transition to the ppolic error after the PPOLICY_GRACE_AUTHNS_REMAINING_STATE
+ // PasswordPolicyResponseValue ::= SEQUENCE {
+ // warning [0] CHOICE {
+ // ...
+ // graceAuthNsRemaining [1] INTEGER (0 .. maxInt) } OPTIONAL,
+ //
+ // error [1] ENUMERATED {
+ super.transitions[PasswordPolicyResponseControlStates.PPOLICY_GRACE_AUTHNS_REMAINING_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] = new GrammarTransition(
+ PasswordPolicyResponseControlStates.PPOLICY_GRACE_AUTHNS_REMAINING_STATE, PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE,
+ UniversalTag.ENUMERATED.getValue(), new GrammarAction( "set ppolicy error value after reading the graceAuthNsRemaining value" )
+ {
+ public void action( Asn1Container container ) throws DecoderException
+ {
+ PasswordPolicyResponseControlContainer ppolicyRespContainer = ( PasswordPolicyResponseControlContainer ) container;
+
+ setPasswordPolicyError( ppolicyRespContainer );
+
+ ppolicyRespContainer.setGrammarEndAllowed( true );
+ }
+ } );
+
+ // PasswordPolicyResponseValue ::= SEQUENCE {
+ // error [1] ENUMERATED {
+ super.transitions[PasswordPolicyResponseControlStates.SEQ_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] = new GrammarTransition(
+ PasswordPolicyResponseControlStates.PPOLICY_ERROR_STATE, PasswordPolicyResponseControlStates.END_STATE,
UniversalTag.ENUMERATED.getValue(), new GrammarAction( "set ppolicy error value" )
{
public void action( Asn1Container container ) throws DecoderException
{
PasswordPolicyResponseControlContainer ppolicyRespContainer = ( PasswordPolicyResponseControlContainer ) container;
-
+
setPasswordPolicyError( ppolicyRespContainer );
ppolicyRespContainer.setGrammarEndAllowed( true );
@@ -172,7 +252,8 @@ public class PasswordPolicyResponseContr
* @param ppolicyRespContainer the container holding PasswordPolicyResponceControl
* @throws DecoderException
*/
- private void setPasswordPolicyError( PasswordPolicyResponseControlContainer ppolicyRespContainer ) throws DecoderException
+ private void setPasswordPolicyError( PasswordPolicyResponseControlContainer ppolicyRespContainer )
+ throws DecoderException
{
Value value = ppolicyRespContainer.getCurrentTLV().getValue();
try
@@ -180,12 +261,12 @@ public class PasswordPolicyResponseContr
int errorNum = IntegerDecoder.parse( value,
PasswordPolicyErrorEnum.PASSWORD_EXPIRED.getValue(),
PasswordPolicyErrorEnum.PASSWORD_IN_HISTORY.getValue() );
-
- if( IS_DEBUG )
+
+ if ( IS_DEBUG )
{
LOG.debug( "password policy error {}", errorNum );
}
-
+
ppolicyRespContainer.getPasswordPolicyResponseControl().setPasswordPolicyError(
PasswordPolicyErrorEnum.get( errorNum ) );
}
@@ -198,6 +279,7 @@ public class PasswordPolicyResponseContr
}
+
public static Grammar getInstance()
{
return INSTANCE;
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlStates.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlStates.java?rev=1033822&r1=1033821&r2=1033822&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlStates.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlStates.java Thu Nov 11 06:24:46 2010
@@ -33,13 +33,16 @@ import org.apache.directory.shared.asn1.
public enum PasswordPolicyResponseControlStates implements States
{
- /** The ending state for every grammars */
- GRAMMAR_END,
-
START_STATE,
+
+ SEQ_STATE,
+ PPOLICY_TIME_BEFORE_EXPIRATION_TAG_STATE,
+
PPOLICY_TIME_BEFORE_EXPIRATION_STATE,
+ PPOLICY_GRACE_AUTHNS_REMAINING_TAG_STATE,
+
PPOLICY_GRACE_AUTHNS_REMAINING_STATE,
PPOLICY_ERROR_STATE,
@@ -73,7 +76,7 @@ public enum PasswordPolicyResponseContro
*/
public String getState( int state )
{
- return ( ( state == GRAMMAR_END.ordinal() ) ? "PASSWORD_POLICY_RESPONSE_CONTROL_GRAMMAR" : name() );
+ return ( ( state == END_STATE.ordinal() ) ? "PASSWORD_POLICY_RESPONSE_CONTROL_GRAMMAR" : name() );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java?rev=1033822&r1=1033821&r2=1033822&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTags.java Thu Nov 11 06:24:46 2010
@@ -27,7 +27,7 @@ package org.apache.directory.shared.ldap
*/
public enum PasswordPolicyResponseControlTags
{
- TIME_BEFORE_EXPIRATION_TAG(0x0080), GRACE_AUTHNS_REMAINING_TAG(0x0081);
+ TIME_BEFORE_EXPIRATION_TAG(0xA0), GRACE_AUTHNS_REMAINING_TAG(0xA1);
/** Internal value for each tag */
private int value;
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java?rev=1033822&r1=1033821&r2=1033822&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/ppolicy/PasswordPolicyResponseControlTest.java Thu Nov 11 06:24:46 2010
@@ -43,13 +43,14 @@ public class PasswordPolicyResponseContr
public void testDecodeRespWithExpiryWarningAndError() throws Exception
{
Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 8 );
+ ByteBuffer bb = ByteBuffer.allocate( 0xA );
bb.put( new byte[]
{
- 0x30, 0x06,
- (byte)0x80, 1, 1, //
- 0x0A, 0x01, 1
+ 0x30, 0x08,
+ (byte)0xA0, 0x03, // timeBeforeExpiration
+ 0x02, 0x01, 0x01,
+ 0x0A, 0x01, 0x01 // ppolicyError
} );
bb.flip();
@@ -63,17 +64,18 @@ public class PasswordPolicyResponseContr
assertEquals( 1, control.getTimeBeforeExpiration() );
assertEquals( 1, control.getPasswordPolicyError().getValue() );
- ByteBuffer buffer = ByteBuffer.allocate( 0x25 );
+ ByteBuffer buffer = ByteBuffer.allocate( 0x27 );
buffer.put( new byte[]
{
- 0x30, 0x23,
+ 0x30, 0x25,
0x04, 0x19,
'1','.', '3', '.', '6', '.', '1', '.', '4',
'.', '1', '.', '4', '2', '.', '2', '.', '2',
'7', '.', '8', '.', '5', '.', '1',
- 0x04, 0x06,
- (byte)0x80, 1, 0x01, //
- 0x0A, 0x01, 0x01
+ 0x04, 0x08,
+ (byte)0xA0, 0x03, // timeBeforeExpiration
+ 0x02, 0x01, 0x01,
+ 0x0A, 0x01, 0x01 // error
} );
buffer.flip();
@@ -86,13 +88,14 @@ public class PasswordPolicyResponseContr
public void testDecodeRespWithGraceAuthWarningAndError() throws Exception
{
Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 8 );
+ ByteBuffer bb = ByteBuffer.allocate( 0xA );
bb.put( new byte[]
{
- 0x30, 0x06,
- (byte)0x81, 1, 1, //
- 0x0A, 0x01, 1
+ 0x30, 0x08,
+ (byte)0xA1, 0x03, // graceAuthNsRemaining
+ 0x02, 0x01, 0x01, //
+ 0x0A, 0x01, 1 // error
} );
bb.flip();
@@ -106,17 +109,18 @@ public class PasswordPolicyResponseContr
assertEquals( 1, control.getGraceAuthNsRemaining() );
assertEquals( 1, control.getPasswordPolicyError().getValue() );
- ByteBuffer buffer = ByteBuffer.allocate( 0x25 );
+ ByteBuffer buffer = ByteBuffer.allocate( 0x27 );
buffer.put( new byte[]
{
- 0x30, 0x23,
+ 0x30, 0x25,
0x04, 0x19,
'1','.', '3', '.', '6', '.', '1', '.', '4',
'.', '1', '.', '4', '2', '.', '2', '.', '2',
'7', '.', '8', '.', '5', '.', '1',
- 0x04, 0x06,
- (byte)0x81, 1, 0x01, //
- 0x0A, 0x01, 0x01
+ 0x04, 0x08,
+ (byte)0xA1, 0x03, // graceAuthNsRemaining
+ 0x02, 0x01, 0x01, //
+ 0x0A, 0x01, 1 // error
} );
buffer.flip();
@@ -126,15 +130,16 @@ public class PasswordPolicyResponseContr
@Test
- public void testDecodeRespWithExpiryWarningOnly() throws Exception
+ public void testDecodeRespWithTimeBeforeExpiryWarningOnly() throws Exception
{
Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
- ByteBuffer bb = ByteBuffer.allocate( 5 );
+ ByteBuffer bb = ByteBuffer.allocate( 7 );
bb.put( new byte[]
{
- 0x30, 0x03,
- (byte)0x81, 1, 1 //
+ 0x30, 0x05,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01 // timeBeforeExpiration
} );
bb.flip();
@@ -145,25 +150,68 @@ public class PasswordPolicyResponseContr
decoder.decode( bb, container );
PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
- assertEquals( 1, control.getGraceAuthNsRemaining() );
+ assertEquals( 1, control.getTimeBeforeExpiration() );
- ByteBuffer buffer = ByteBuffer.allocate( 0x22 );
+ ByteBuffer buffer = ByteBuffer.allocate( 0x24 );
buffer.put( new byte[]
{
- 0x30, 0x20,
+ 0x30, 0x22,
0x04, 0x19,
'1','.', '3', '.', '6', '.', '1', '.', '4',
'.', '1', '.', '4', '2', '.', '2', '.', '2',
'7', '.', '8', '.', '5', '.', '1',
- 0x04, 0x03,
- (byte)0x81, 1, 0x01
+ 0x04, 0x05,
+ (byte)0xA0, 0x03,
+ 0x02, 0x01, 0x01 // timeBeforeExpiration
} );
buffer.flip();
ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
}
+
+
+ @Test
+ public void testDecodeRespWithGraceAuthWarningOnly() throws Exception
+ {
+ Asn1Decoder decoder = new PasswordPolicyResponseControlDecoder();
+ ByteBuffer bb = ByteBuffer.allocate( 7 );
+
+ bb.put( new byte[]
+ {
+ 0x30, 0x05,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x01 // graceAuthNsRemaining
+ } );
+
+ bb.flip();
+ PasswordPolicyResponseControlContainer container = new PasswordPolicyResponseControlContainer();
+ container.setPasswordPolicyResponseControl( new PasswordPolicyResponseControl() );
+
+ decoder.decode( bb, container );
+
+ PasswordPolicyResponseControl control = container.getPasswordPolicyResponseControl();
+ assertEquals( 1, control.getGraceAuthNsRemaining() );
+
+ ByteBuffer buffer = ByteBuffer.allocate( 0x24 );
+ buffer.put( new byte[]
+ {
+ 0x30, 0x22,
+ 0x04, 0x19,
+ '1','.', '3', '.', '6', '.', '1', '.', '4',
+ '.', '1', '.', '4', '2', '.', '2', '.', '2',
+ '7', '.', '8', '.', '5', '.', '1',
+ 0x04, 0x05,
+ (byte)0xA1, 0x03,
+ 0x02, 0x01, 0x01 // graceAuthNsRemaining
+ } );
+ buffer.flip();
+
+ ByteBuffer encoded = control.encode( ByteBuffer.allocate( control.computeLength() ) );
+ assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+ }
+
@Test
public void testDecodeRespWithErrorOnly() throws Exception
@@ -174,7 +222,7 @@ public class PasswordPolicyResponseContr
bb.put( new byte[]
{
0x30, 0x03,
- 0x0A, 1, 1 //
+ 0x0A, 1, 1 // error
} );
bb.flip();
@@ -196,7 +244,7 @@ public class PasswordPolicyResponseContr
'.', '1', '.', '4', '2', '.', '2', '.', '2',
'7', '.', '8', '.', '5', '.', '1',
0x04, 0x03,
- 0x0A, 1, 0x01
+ 0x0A, 1, 0x01 // error
} );
buffer.flip();