1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
25 import org.apache.directory.api.asn1.ber.grammar.Grammar;
26 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
27 import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
28 import org.apache.directory.api.asn1.ber.tlv.BerValue;
29 import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
30 import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
31 import org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyResponseImpl;
32 import org.apache.directory.api.util.Strings;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class PasswordModifyResponseGrammar extends AbstractGrammar<PasswordModifyResponseContainer>
51 {
52
53
54 private static final Logger LOG = LoggerFactory.getLogger( PasswordModifyResponseGrammar.class );
55
56
57 static final boolean IS_DEBUG = LOG.isDebugEnabled();
58
59
60 private static Grammar<PasswordModifyResponseContainer> instance = new PasswordModifyResponseGrammar();
61
62
63 @SuppressWarnings("unchecked")
64 public PasswordModifyResponseGrammar()
65 {
66 setName( PasswordModifyResponseGrammar.class.getName() );
67
68
69 super.transitions = new GrammarTransition[PasswordModifyResponseStatesEnum.LAST_PASSWORD_MODIFY_RESPONSE_STATE
70 .ordinal()][256];
71
72
73
74
75
76
77
78
79
80 super.transitions[PasswordModifyResponseStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
81 new GrammarTransition<PasswordModifyResponseContainer>(
82 PasswordModifyResponseStatesEnum.START_STATE,
83 PasswordModifyResponseStatesEnum.PASSWORD_MODIFY_RESPONSE_SEQUENCE_STATE,
84 UniversalTag.SEQUENCE.getValue(), new GrammarAction<PasswordModifyResponseContainer>(
85 "Init PasswordModifyResponse" )
86 {
87 public void action( PasswordModifyResponseContainer container )
88 {
89 PasswordModifyResponseDecorator passwordModifyResponse = new PasswordModifyResponseDecorator(
90 LdapApiServiceFactory.getSingleton(), new PasswordModifyResponseImpl() );
91 container.setPasswordModifyResponse( passwordModifyResponse );
92
93
94 container.setGrammarEndAllowed( true );
95 }
96 } );
97
98
99
100
101
102
103
104
105
106
107 super.transitions[PasswordModifyResponseStatesEnum.PASSWORD_MODIFY_RESPONSE_SEQUENCE_STATE.ordinal()][PasswordModifyResponseConstants.GEN_PASSWORD_TAG] =
108 new GrammarTransition<PasswordModifyResponseContainer>(
109 PasswordModifyResponseStatesEnum.PASSWORD_MODIFY_RESPONSE_SEQUENCE_STATE,
110 PasswordModifyResponseStatesEnum.GEN_PASSWORD_STATE,
111 PasswordModifyResponseConstants.GEN_PASSWORD_TAG,
112 new GrammarAction<PasswordModifyResponseContainer>( "Set PasswordModifyResponse user identity" )
113 {
114 public void action( PasswordModifyResponseContainer container ) throws DecoderException
115 {
116 BerValue value = container.getCurrentTLV().getValue();
117
118 byte[] genPassword = value.getData();
119
120 if ( IS_DEBUG )
121 {
122 LOG.debug( "GenPassword = " + Strings.dumpBytes( genPassword ) );
123 }
124
125 if ( genPassword == null )
126 {
127 genPassword = Strings.EMPTY_BYTES;
128 }
129
130 ( ( PasswordModifyResponseDecorator ) container.getPwdModifyResponse() )
131 .setGenPassword( genPassword );
132
133
134 container.setGrammarEndAllowed( true );
135 }
136 } );
137 }
138
139
140
141
142
143
144
145 public static Grammar<PasswordModifyResponseContainer> getInstance()
146 {
147 return instance;
148 }
149 }