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.adAndOr;
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.adAndOr.actions.AdAndOrInit;
30  import org.apache.directory.shared.kerberos.codec.adAndOr.actions.StoreConditionCount;
31  import org.apache.directory.shared.kerberos.codec.adAndOr.actions.StoreElements;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  
36  /**
37   * This class implements the AdAndOr 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 AdAndOrGrammar extends AbstractGrammar<AdAndOrContainer>
44  {
45      /** The logger */
46      static final Logger LOG = LoggerFactory.getLogger( AdAndOrGrammar.class );
47  
48      /** A speedup for logger */
49      static final boolean IS_DEBUG = LOG.isDebugEnabled();
50  
51      /** The instance of grammar. AdAndOrGrammar is a singleton */
52      private static Grammar<AdAndOrContainer> instance = new AdAndOrGrammar();
53  
54  
55      /**
56       * Creates a new AdAndOrGrammar object.
57       */
58      @SuppressWarnings("unchecked")
59      private AdAndOrGrammar()
60      {
61          setName( AdAndOrGrammar.class.getName() );
62  
63          // Create the transitions table
64          super.transitions = new GrammarTransition[AdAndOrStatesEnum.LAST_AD_AND_OR_STATE.ordinal()][256];
65  
66          // ============================================================================================
67          // AdAndOr
68          // ============================================================================================
69          // --------------------------------------------------------------------------------------------
70          // Transition from AdAndOr init to AdAndOr SEQ
71          // --------------------------------------------------------------------------------------------
72          // AD-AND-OR               ::= SEQUENCE {
73          super.transitions[AdAndOrStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74              new GrammarTransition<AdAndOrContainer>(
75                  AdAndOrStatesEnum.START_STATE,
76                  AdAndOrStatesEnum.AD_AND_OR_STATE,
77                  UniversalTag.SEQUENCE,
78                  new AdAndOrInit() );
79  
80          // --------------------------------------------------------------------------------------------
81          // Transition from AdAndOr SEQ to condition-count tag
82          // --------------------------------------------------------------------------------------------
83          // AD-AND-OR               ::= SEQUENCE {
84          //         condition-count [0]
85          super.transitions[AdAndOrStatesEnum.AD_AND_OR_STATE.ordinal()][KerberosConstants.AD_AND_OR_CONDITION_COUNT_TAG] =
86              new GrammarTransition<AdAndOrContainer>(
87                  AdAndOrStatesEnum.AD_AND_OR_STATE,
88                  AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_TAG_STATE,
89                  KerberosConstants.AD_AND_OR_CONDITION_COUNT_TAG,
90                  new CheckNotNullLength<AdAndOrContainer>() );
91  
92          // --------------------------------------------------------------------------------------------
93          // Transition from condition-count tag to condition-count value
94          // --------------------------------------------------------------------------------------------
95          // AD-AND-OR               ::= SEQUENCE {
96          //         condition-count [0] Int32,
97          super.transitions[AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_TAG_STATE.ordinal()][UniversalTag.INTEGER
98              .getValue()] =
99              new GrammarTransition<AdAndOrContainer>(
100                 AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_TAG_STATE,
101                 AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_STATE,
102                 UniversalTag.INTEGER,
103                 new StoreConditionCount() );
104 
105         // --------------------------------------------------------------------------------------------
106         // Transition from condition-countvalue to elements
107         // --------------------------------------------------------------------------------------------
108         // AD-AND-OR               ::= SEQUENCE {
109         //         ...
110         //         elements        [1] AuthorizationData
111         // }
112         super.transitions[AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_STATE.ordinal()][KerberosConstants.AD_AND_OR_ELEMENTS_TAG] =
113             new GrammarTransition<AdAndOrContainer>(
114                 AdAndOrStatesEnum.AD_AND_OR_CONDITION_COUNT_STATE,
115                 AdAndOrStatesEnum.AD_AND_OR_ELEMENTS_TAG_STATE,
116                 KerberosConstants.AD_AND_OR_ELEMENTS_TAG,
117                 new StoreElements() );
118     }
119 
120 
121     /**
122      * Get the instance of this grammar
123      *
124      * @return An instance on the AD-AND-OR Grammar
125      */
126     public static Grammar<AdAndOrContainer> getInstance()
127     {
128         return instance;
129     }
130 }