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