View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.shared.kerberos.codec.apReq;
21  
22  
23  import org.apache.directory.api.asn1.actions.CheckNotNullLength;
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.GrammarTransition;
27  import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
28  import org.apache.directory.shared.kerberos.KerberosConstants;
29  import org.apache.directory.shared.kerberos.codec.apReq.actions.ApReqInit;
30  import org.apache.directory.shared.kerberos.codec.apReq.actions.CheckMsgType;
31  import org.apache.directory.shared.kerberos.codec.apReq.actions.StoreApOptions;
32  import org.apache.directory.shared.kerberos.codec.apReq.actions.StoreAuthenticator;
33  import org.apache.directory.shared.kerberos.codec.apReq.actions.StorePvno;
34  import org.apache.directory.shared.kerberos.codec.apReq.actions.StoreTicket;
35  import org.slf4j.Logger;
36  import org.slf4j.LoggerFactory;
37  
38  
39  /**
40   * This class implements the AP-REQ structure. All the actions are declared
41   * in this class. As it is a singleton, these declaration are only done once. If
42   * an action is to be added or modified, this is where the work is to be done !
43   *
44   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45   */
46  public final class ApReqGrammar extends AbstractGrammar<ApReqContainer>
47  {
48      /** The logger */
49      static final Logger LOG = LoggerFactory.getLogger( ApReqGrammar.class );
50  
51      /** A speedup for logger */
52      static final boolean IS_DEBUG = LOG.isDebugEnabled();
53  
54      /** The instance of grammar. ApReqGrammar is a singleton */
55      private static Grammar<ApReqContainer> instance = new ApReqGrammar();
56  
57  
58      /**
59       * Creates a new ApReqGrammar object.
60       */
61      @SuppressWarnings("unchecked")
62      private ApReqGrammar()
63      {
64          setName( ApReqGrammar.class.getName() );
65  
66          // Create the transitions table
67          super.transitions = new GrammarTransition[ApReqStatesEnum.LAST_AP_REQ_STATE.ordinal()][256];
68  
69          // ============================================================================================
70          // AP-REQ
71          // ============================================================================================
72          // --------------------------------------------------------------------------------------------
73          // Transition from AP-REQ init to AP-REQ tag
74          // --------------------------------------------------------------------------------------------
75          // AP-REQ          ::= [APPLICATION 14]
76          super.transitions[ApReqStatesEnum.START_STATE.ordinal()][KerberosConstants.AP_REQ_TAG] =
77              new GrammarTransition<ApReqContainer>(
78                  ApReqStatesEnum.START_STATE,
79                  ApReqStatesEnum.AP_REQ_STATE,
80                  KerberosConstants.AP_REQ_TAG,
81                  new ApReqInit() );
82  
83          // --------------------------------------------------------------------------------------------
84          // Transition from AP-REQ tag to AP-REQ SEQ {
85          // --------------------------------------------------------------------------------------------
86          // AP-REQ          ::= [APPLICATION 14] SEQUENCE
87          super.transitions[ApReqStatesEnum.AP_REQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
88              new GrammarTransition<ApReqContainer>(
89                  ApReqStatesEnum.AP_REQ_STATE,
90                  ApReqStatesEnum.AP_REQ_SEQ_STATE,
91                  UniversalTag.SEQUENCE,
92                  new CheckNotNullLength<ApReqContainer>() );
93  
94          // --------------------------------------------------------------------------------------------
95          // Transition from AP-REQ SEQ to PVNO tag
96          // --------------------------------------------------------------------------------------------
97          // AP-REQ          ::= [APPLICATION 14] SEQUENCE
98          //         pvno            [0]
99          super.transitions[ApReqStatesEnum.AP_REQ_SEQ_STATE.ordinal()][KerberosConstants.AP_REQ_PVNO_TAG] =
100             new GrammarTransition<ApReqContainer>(
101                 ApReqStatesEnum.AP_REQ_SEQ_STATE,
102                 ApReqStatesEnum.AP_REQ_PVNO_TAG_STATE,
103                 KerberosConstants.AP_REQ_PVNO_TAG,
104                 new CheckNotNullLength<ApReqContainer>() );
105 
106         // --------------------------------------------------------------------------------------------
107         // Transition from PVNO tag to PVNO value
108         // --------------------------------------------------------------------------------------------
109         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
110         //         pvno            [0] INTEGER (5),
111         super.transitions[ApReqStatesEnum.AP_REQ_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
112             new GrammarTransition<ApReqContainer>(
113                 ApReqStatesEnum.AP_REQ_PVNO_TAG_STATE,
114                 ApReqStatesEnum.AP_REQ_PVNO_STATE,
115                 UniversalTag.INTEGER,
116                 new StorePvno() );
117 
118         // --------------------------------------------------------------------------------------------
119         // Transition from PVNO value to msg-type tag
120         // --------------------------------------------------------------------------------------------
121         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
122         //         ...
123         //         msg-type        [1]
124         super.transitions[ApReqStatesEnum.AP_REQ_PVNO_STATE.ordinal()][KerberosConstants.AP_REQ_MSG_TYPE_TAG] =
125             new GrammarTransition<ApReqContainer>(
126                 ApReqStatesEnum.AP_REQ_PVNO_STATE,
127                 ApReqStatesEnum.AP_REQ_MSG_TYPE_TAG_STATE,
128                 KerberosConstants.AP_REQ_MSG_TYPE_TAG,
129                 new CheckNotNullLength<ApReqContainer>() );
130 
131         // --------------------------------------------------------------------------------------------
132         // Transition from msg-type tag to msg-type value
133         // --------------------------------------------------------------------------------------------
134         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
135         //         ...
136         //         msg-type        [1] INTEGER (14),
137         super.transitions[ApReqStatesEnum.AP_REQ_MSG_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
138             new GrammarTransition<ApReqContainer>(
139                 ApReqStatesEnum.AP_REQ_MSG_TYPE_TAG_STATE,
140                 ApReqStatesEnum.AP_REQ_MSG_TYPE_STATE,
141                 UniversalTag.INTEGER,
142                 new CheckMsgType() );
143 
144         // --------------------------------------------------------------------------------------------
145         // Transition from msg-type value to ap-options tag
146         // --------------------------------------------------------------------------------------------
147         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
148         //         ...
149         //         ap-options      [2]
150         super.transitions[ApReqStatesEnum.AP_REQ_MSG_TYPE_STATE.ordinal()][KerberosConstants.AP_REQ_AP_OPTIONS_TAG] =
151             new GrammarTransition<ApReqContainer>(
152                 ApReqStatesEnum.AP_REQ_MSG_TYPE_STATE,
153                 ApReqStatesEnum.AP_REQ_AP_OPTIONS_TAG_STATE,
154                 KerberosConstants.AP_REQ_AP_OPTIONS_TAG,
155                 new CheckNotNullLength<ApReqContainer>() );
156 
157         // --------------------------------------------------------------------------------------------
158         // Transition from ap-options tag to ap-options value
159         // --------------------------------------------------------------------------------------------
160         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
161         //         ...
162         //         ap-options      [2] APOptions,
163         super.transitions[ApReqStatesEnum.AP_REQ_AP_OPTIONS_TAG_STATE.ordinal()][UniversalTag.BIT_STRING.getValue()] =
164             new GrammarTransition<ApReqContainer>(
165                 ApReqStatesEnum.AP_REQ_AP_OPTIONS_TAG_STATE,
166                 ApReqStatesEnum.AP_REQ_AP_OPTIONS_STATE,
167                 UniversalTag.BIT_STRING,
168                 new StoreApOptions() );
169 
170         // --------------------------------------------------------------------------------------------
171         // Transition from ap-options value to ticket
172         // --------------------------------------------------------------------------------------------
173         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
174         //         ...
175         //         ticket          [3] Ticket,
176         super.transitions[ApReqStatesEnum.AP_REQ_AP_OPTIONS_STATE.ordinal()][KerberosConstants.AP_REQ_TICKET_TAG] =
177             new GrammarTransition<ApReqContainer>(
178                 ApReqStatesEnum.AP_REQ_AP_OPTIONS_STATE,
179                 ApReqStatesEnum.AP_REQ_TICKET_STATE,
180                 KerberosConstants.AP_REQ_TICKET_TAG,
181                 new StoreTicket() );
182 
183         // --------------------------------------------------------------------------------------------
184         // Transition from ticket to authenticator
185         // --------------------------------------------------------------------------------------------
186         // AP-REQ          ::= [APPLICATION 14] SEQUENCE
187         //         ...
188         //         authenticator   [4] <EncryptedData> -- Authenticator
189         // }
190         super.transitions[ApReqStatesEnum.AP_REQ_TICKET_STATE.ordinal()][KerberosConstants.AP_REQ_AUTHENTICATOR_TAG] =
191             new GrammarTransition<ApReqContainer>(
192                 ApReqStatesEnum.AP_REQ_TICKET_STATE,
193                 ApReqStatesEnum.LAST_AP_REQ_STATE,
194                 KerberosConstants.AP_REQ_AUTHENTICATOR_TAG,
195                 new StoreAuthenticator() );
196     }
197 
198 
199     /**
200      * Get the instance of this grammar
201      *
202      * @return An instance on the AP-REQ Grammar
203      */
204     public static Grammar<ApReqContainer> getInstance()
205     {
206         return instance;
207     }
208 }