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.lastReq;
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.lastReq.actions.LastReqInit;
30  import org.apache.directory.shared.kerberos.codec.lastReq.actions.StoreLrType;
31  import org.apache.directory.shared.kerberos.codec.lastReq.actions.StoreLrValue;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  
36  /**
37   * This class implements the LastReq structure. All the actions are declared
38   * in this class. As it is a singleton, these declaration are only done once. If
39   * an action is to be added or modified, this is where the work is to be done !
40   *
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  public final class LastReqGrammar extends AbstractGrammar<LastReqContainer>
44  {
45      /** The logger */
46      static final Logger LOG = LoggerFactory.getLogger( LastReqGrammar.class );
47  
48      /** A speedup for logger */
49      static final boolean IS_DEBUG = LOG.isDebugEnabled();
50  
51      /** The instance of grammar. LastReqGrammar is a singleton */
52      private static Grammar<LastReqContainer> instance = new LastReqGrammar();
53  
54  
55      /**
56       * Creates a new LastReqGrammar object.
57       */
58      @SuppressWarnings("unchecked")
59      private LastReqGrammar()
60      {
61          setName( LastReqGrammar.class.getName() );
62  
63          // Create the transitions table
64          super.transitions = new GrammarTransition[LastReqStatesEnum.LAST_LAST_REQ_STATE.ordinal()][256];
65  
66          // ============================================================================================
67          // LastReq
68          // ============================================================================================
69          // --------------------------------------------------------------------------------------------
70          // Transition from LastReq init to LastReq SEQ OF
71          // --------------------------------------------------------------------------------------------
72          // LastReq   ::= SEQUENCE OF
73          super.transitions[LastReqStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74              new GrammarTransition<LastReqContainer>(
75                  LastReqStatesEnum.START_STATE,
76                  LastReqStatesEnum.LAST_REQ_SEQ_STATE,
77                  UniversalTag.SEQUENCE,
78                  new LastReqInit() );
79  
80          // --------------------------------------------------------------------------------------------
81          // Transition from LastReq SEQ OF to LastReq SEQ OF SEQ
82          // --------------------------------------------------------------------------------------------
83          // LastReq   ::= SEQUENCE OF SEQUENCE {
84          super.transitions[LastReqStatesEnum.LAST_REQ_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
85              new GrammarTransition<LastReqContainer>(
86                  LastReqStatesEnum.LAST_REQ_SEQ_STATE,
87                  LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE,
88                  UniversalTag.SEQUENCE,
89                  new CheckNotNullLength<LastReqContainer>() );
90  
91          // --------------------------------------------------------------------------------------------
92          // Transition from LastReq SEQ OF SEQ to lr-type tag
93          // --------------------------------------------------------------------------------------------
94          // LastReq   ::= SEQUENCE OF SEQUENCE {
95          //         lr-type         [0]
96          super.transitions[LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE.ordinal()][KerberosConstants.LAST_REQ_LR_TYPE_TAG] =
97              new GrammarTransition<LastReqContainer>(
98                  LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE,
99                  LastReqStatesEnum.LAST_REQ_LR_TYPE_TAG_STATE,
100                 KerberosConstants.LAST_REQ_LR_TYPE_TAG,
101                 new CheckNotNullLength<LastReqContainer>() );
102 
103         // --------------------------------------------------------------------------------------------
104         // Transition from lr-type tag to lr-type value
105         // --------------------------------------------------------------------------------------------
106         // LastReq   ::= SEQUENCE OF SEQUENCE {
107         //         lr-type         [0]  Int32,
108         super.transitions[LastReqStatesEnum.LAST_REQ_LR_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
109             new GrammarTransition<LastReqContainer>(
110                 LastReqStatesEnum.LAST_REQ_LR_TYPE_TAG_STATE,
111                 LastReqStatesEnum.LAST_REQ_LR_TYPE_STATE,
112                 UniversalTag.INTEGER,
113                 new StoreLrType() );
114 
115         // --------------------------------------------------------------------------------------------
116         // Transition from lr-type value lr-value tag
117         // --------------------------------------------------------------------------------------------
118         // LastReq   ::= SEQUENCE OF SEQUENCE {
119         //         ...
120         //         lr-value        [1]
121         super.transitions[LastReqStatesEnum.LAST_REQ_LR_TYPE_STATE.ordinal()][KerberosConstants.LAST_REQ_LR_VALUE_TAG] =
122             new GrammarTransition<LastReqContainer>(
123                 LastReqStatesEnum.LAST_REQ_LR_TYPE_STATE,
124                 LastReqStatesEnum.LAST_REQ_LR_VALUE_TAG_STATE,
125                 KerberosConstants.LAST_REQ_LR_VALUE_TAG,
126                 new CheckNotNullLength<LastReqContainer>() );
127 
128         // --------------------------------------------------------------------------------------------
129         // Transition from lr-value tag to lr-value value
130         // --------------------------------------------------------------------------------------------
131         // LastReq   ::= SEQUENCE OF SEQUENCE {
132         //         ...
133         //         lr-value        [1] KerberosTime
134         super.transitions[LastReqStatesEnum.LAST_REQ_LR_VALUE_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME
135             .getValue()] =
136             new GrammarTransition<LastReqContainer>(
137                 LastReqStatesEnum.LAST_REQ_LR_VALUE_TAG_STATE,
138                 LastReqStatesEnum.LAST_REQ_LR_VALUE_STATE,
139                 UniversalTag.GENERALIZED_TIME,
140                 new StoreLrValue() );
141 
142         // --------------------------------------------------------------------------------------------
143         // Transition from lr-value value to SEQ OF SEQ
144         // --------------------------------------------------------------------------------------------
145         // LastReq   ::= SEQUENCE OF SEQUENCE {
146         //         ...
147         //         lr-value        [1] KerberosTime
148         // }
149         super.transitions[LastReqStatesEnum.LAST_REQ_LR_VALUE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
150             new GrammarTransition<LastReqContainer>(
151                 LastReqStatesEnum.LAST_REQ_LR_VALUE_STATE,
152                 LastReqStatesEnum.LAST_REQ_SEQ_SEQ_STATE,
153                 UniversalTag.SEQUENCE,
154                 new CheckNotNullLength<LastReqContainer>() );
155     }
156 
157 
158     /**
159      * Get the instance of this grammar
160      *
161      * @return An instance on the LastReq Grammar
162      */
163     public static Grammar<LastReqContainer> getInstance()
164     {
165         return instance;
166     }
167 }