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.paEncTsEnc;
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.paEncTsEnc.actions.PaEncTsEncInit;
30  import org.apache.directory.shared.kerberos.codec.paEncTsEnc.actions.StorePaTimestamp;
31  import org.apache.directory.shared.kerberos.codec.paEncTsEnc.actions.StorePaUsec;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  
36  /**
37   * This class implements the PaEncTsEnc 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 PaEncTsEncGrammar extends AbstractGrammar<PaEncTsEncContainer>
44  {
45      /** The logger */
46      static final Logger LOG = LoggerFactory.getLogger( PaEncTsEncGrammar.class );
47  
48      /** A speedup for logger */
49      static final boolean IS_DEBUG = LOG.isDebugEnabled();
50  
51      /** The instance of grammar. PaEncTsEncGrammar is a singleton */
52      private static Grammar<PaEncTsEncContainer> instance = new PaEncTsEncGrammar();
53  
54  
55      /**
56       * Creates a new PaEncTsEncrGrammar object.
57       */
58      @SuppressWarnings("unchecked")
59      private PaEncTsEncGrammar()
60      {
61          setName( PaEncTsEncGrammar.class.getName() );
62  
63          // Create the transitions table
64          super.transitions = new GrammarTransition[PaEncTsEncStatesEnum.LAST_PA_ENC_TS_ENC_STATE.ordinal()][256];
65  
66          // ============================================================================================
67          // PaEncTsEnc
68          // ============================================================================================
69          // --------------------------------------------------------------------------------------------
70          // Transition from PaEncTsEnc init to PaEncTsEnc SEQ
71          // --------------------------------------------------------------------------------------------
72          // PA-ENC-TS-ENC           ::= SEQUENCE {
73          super.transitions[PaEncTsEncStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74              new GrammarTransition<PaEncTsEncContainer>(
75                  PaEncTsEncStatesEnum.START_STATE,
76                  PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE,
77                  UniversalTag.SEQUENCE,
78                  new PaEncTsEncInit() );
79  
80          // --------------------------------------------------------------------------------------------
81          // Transition from PaEncTsEnc SEQ to patimestamp tag
82          // --------------------------------------------------------------------------------------------
83          // PA-ENC-TS-ENC           ::= SEQUENCE {
84          //         patimestamp     [0]
85          super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE.ordinal()][KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG] =
86              new GrammarTransition<PaEncTsEncContainer>(
87                  PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE,
88                  PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE,
89                  KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG,
90                  new CheckNotNullLength<PaEncTsEncContainer>() );
91  
92          // --------------------------------------------------------------------------------------------
93          // Transition from patimestamp tag to patimestamp  value
94          // --------------------------------------------------------------------------------------------
95          // PA-ENC-TS-ENC           ::= SEQUENCE {
96          //         patimestamp     [0] KerberosTime -- client's time --,
97          super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME
98              .getValue()] =
99              new GrammarTransition<PaEncTsEncContainer>(
100                 PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE,
101                 PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE,
102                 UniversalTag.GENERALIZED_TIME,
103                 new StorePaTimestamp() );
104 
105         // --------------------------------------------------------------------------------------------
106         // Transition from patimestamp value to pausec tag
107         // --------------------------------------------------------------------------------------------
108         // PA-ENC-TS-ENC           ::= SEQUENCE {
109         //         ...
110         //         pausec          [1]
111         super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE.ordinal()][KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG] =
112             new GrammarTransition<PaEncTsEncContainer>(
113                 PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE,
114                 PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE,
115                 KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG,
116                 new CheckNotNullLength<PaEncTsEncContainer>() );
117 
118         // --------------------------------------------------------------------------------------------
119         // Transition from pausec tag to pausec value
120         // --------------------------------------------------------------------------------------------
121         // PA-ENC-TS-ENC           ::= SEQUENCE {
122         //         ...
123         //         pausec          [1] Microseconds OPTIONAL
124         // }
125         super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE.ordinal()][UniversalTag.INTEGER
126             .getValue()] =
127             new GrammarTransition<PaEncTsEncContainer>(
128                 PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE,
129                 PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_STATE,
130                 UniversalTag.INTEGER,
131                 new StorePaUsec() );
132     }
133 
134 
135     /**
136      * Get the instance of this grammar
137      *
138      * @return An instance on the PA-ENC-TS-ENC Grammar
139      */
140     public static Grammar<PaEncTsEncContainer> getInstance()
141     {
142         return instance;
143     }
144 }