001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.shared.kerberos.codec.kdcReq; 021 022 023import org.apache.directory.api.asn1.actions.CheckNotNullLength; 024import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar; 025import org.apache.directory.api.asn1.ber.grammar.Grammar; 026import org.apache.directory.api.asn1.ber.grammar.GrammarTransition; 027import org.apache.directory.api.asn1.ber.tlv.UniversalTag; 028import org.apache.directory.shared.kerberos.KerberosConstants; 029import org.apache.directory.shared.kerberos.codec.kdcReq.actions.AddPaData; 030import org.apache.directory.shared.kerberos.codec.kdcReq.actions.CheckMsgType; 031import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StoreKdcReqBody; 032import org.apache.directory.shared.kerberos.codec.kdcReq.actions.StorePvno; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036 037/** 038 * This class implements the KdcReq structure. All the actions are declared 039 * in this class. As it is a singleton, these declaration are only done once. If 040 * an action is to be added or modified, this is where the work is to be done ! 041 * 042 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 043 */ 044public final class KdcReqGrammar extends AbstractGrammar<KdcReqContainer> 045{ 046 /** The logger */ 047 static final Logger LOG = LoggerFactory.getLogger( KdcReqGrammar.class ); 048 049 /** A speedup for logger */ 050 static final boolean IS_DEBUG = LOG.isDebugEnabled(); 051 052 /** The instance of grammar. KdcReqGrammar is a singleton */ 053 private static Grammar<KdcReqContainer> instance = new KdcReqGrammar(); 054 055 056 /** 057 * Creates a new KdcReqGrammar object. 058 */ 059 @SuppressWarnings("unchecked") 060 private KdcReqGrammar() 061 { 062 setName( KdcReqGrammar.class.getName() ); 063 064 // Create the transitions table 065 super.transitions = new GrammarTransition[KdcReqStatesEnum.LAST_KDC_REQ_STATE.ordinal()][256]; 066 067 // ============================================================================================ 068 // KdcReq 069 // ============================================================================================ 070 // -------------------------------------------------------------------------------------------- 071 // Transition from KdcReq init to KdcReq SEQ 072 // -------------------------------------------------------------------------------------------- 073 // KDC-REQ ::= SEQUENCE { 074 super.transitions[KdcReqStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 075 new GrammarTransition<KdcReqContainer>( 076 KdcReqStatesEnum.START_STATE, 077 KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE, 078 UniversalTag.SEQUENCE, 079 new CheckNotNullLength<KdcReqContainer>() ); 080 081 // -------------------------------------------------------------------------------------------- 082 // Transition from KdcReq SEQ to pvno tag 083 // -------------------------------------------------------------------------------------------- 084 // KDC-REQ ::= SEQUENCE { 085 // pvno [1] 086 super.transitions[KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE.ordinal()][KerberosConstants.KDC_REQ_PVNO_TAG] = 087 new GrammarTransition<KdcReqContainer>( 088 KdcReqStatesEnum.KDC_REQ_PVNO_TAG_STATE, 089 KdcReqStatesEnum.KDC_REQ_PVNO_STATE, 090 KerberosConstants.KDC_REQ_PVNO_TAG, 091 new CheckNotNullLength<KdcReqContainer>() ); 092 093 // -------------------------------------------------------------------------------------------- 094 // Transition from pvno tag to pvno value 095 // -------------------------------------------------------------------------------------------- 096 // KDC-REQ ::= SEQUENCE { 097 // pvno [1] INTEGER (5) , 098 super.transitions[KdcReqStatesEnum.KDC_REQ_PVNO_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = 099 new GrammarTransition<KdcReqContainer>( 100 KdcReqStatesEnum.KDC_REQ_PVNO_STATE, 101 KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE, 102 UniversalTag.INTEGER, 103 new StorePvno() ); 104 105 // -------------------------------------------------------------------------------------------- 106 // Transition from pvno value to msg-type tag 107 // -------------------------------------------------------------------------------------------- 108 // KDC-REQ ::= SEQUENCE { 109 // ... 110 // msg-type [2] 111 super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE.ordinal()][KerberosConstants.KDC_REQ_MSG_TYPE_TAG] = 112 new GrammarTransition<KdcReqContainer>( 113 KdcReqStatesEnum.KDC_REQ_MSG_TYPE_TAG_STATE, 114 KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, 115 KerberosConstants.KDC_REQ_MSG_TYPE_TAG, 116 new CheckNotNullLength<KdcReqContainer>() ); 117 118 // -------------------------------------------------------------------------------------------- 119 // Transition from msg-type tag to msg-type value 120 // -------------------------------------------------------------------------------------------- 121 // KDC-REQ ::= SEQUENCE { 122 // ... 123 // msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --), 124 super.transitions[KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = 125 new GrammarTransition<KdcReqContainer>( 126 KdcReqStatesEnum.KDC_REQ_MSG_TYPE_STATE, 127 KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE, 128 UniversalTag.INTEGER, 129 new CheckMsgType() ); 130 131 // -------------------------------------------------------------------------------------------- 132 // Transition from msg-type value to padata tag 133 // -------------------------------------------------------------------------------------------- 134 // KDC-REQ ::= SEQUENCE { 135 // ... 136 // padata [3] 137 super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE.ordinal()][KerberosConstants.KDC_REQ_PA_DATA_TAG] = 138 new GrammarTransition<KdcReqContainer>( 139 KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE, 140 KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE, 141 KerberosConstants.KDC_REQ_PA_DATA_TAG, 142 new CheckNotNullLength<KdcReqContainer>() ); 143 144 // -------------------------------------------------------------------------------------------- 145 // Transition from msg-type value to KDC-REQ-BODY tag (pa-data is missing) 146 // -------------------------------------------------------------------------------------------- 147 // KDC-REQ ::= SEQUENCE { 148 // ... 149 // req-body [4] 150 super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG] = 151 new GrammarTransition<KdcReqContainer>( 152 KdcReqStatesEnum.KDC_REQ_PA_DATA_OR_REQ_BODY_STATE, 153 KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE, 154 KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG, 155 new StoreKdcReqBody() ); 156 157 // -------------------------------------------------------------------------------------------- 158 // Transition from padata tag to pa-data SEQ 159 // -------------------------------------------------------------------------------------------- 160 // KDC-REQ ::= SEQUENCE { 161 // ... 162 // padata [3] SEQUENCE OF 163 super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 164 new GrammarTransition<KdcReqContainer>( 165 KdcReqStatesEnum.KDC_REQ_PA_DATA_TAG_STATE, 166 KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, 167 UniversalTag.SEQUENCE, 168 new CheckNotNullLength<KdcReqContainer>() ); 169 170 // -------------------------------------------------------------------------------------------- 171 // Transition from pa-data SEQ to pa-data 172 // -------------------------------------------------------------------------------------------- 173 // KDC-REQ ::= SEQUENCE { 174 // ... 175 // padata [3] SEQUENCE OF <PA-DATA> 176 super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 177 new GrammarTransition<KdcReqContainer>( 178 KdcReqStatesEnum.KDC_REQ_PA_DATA_SEQ_STATE, 179 KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE, 180 UniversalTag.SEQUENCE, 181 new AddPaData() ); 182 183 // -------------------------------------------------------------------------------------------- 184 // Transition from pa-data to pa-data 185 // -------------------------------------------------------------------------------------------- 186 // KDC-REQ ::= SEQUENCE { 187 // ... 188 // padata [3] SEQUENCE OF <PA-DATA> 189 super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 190 new GrammarTransition<KdcReqContainer>( 191 KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE, 192 KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE, 193 UniversalTag.SEQUENCE, 194 new AddPaData() ); 195 196 // -------------------------------------------------------------------------------------------- 197 // Transition from pa-data to KDC-REQ-BODY tag 198 // -------------------------------------------------------------------------------------------- 199 // KDC-REQ ::= SEQUENCE { 200 // ... 201 // req-body [4] 202 super.transitions[KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE.ordinal()][KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG] = 203 new GrammarTransition<KdcReqContainer>( 204 KdcReqStatesEnum.KDC_REQ_PA_DATA_STATE, 205 KdcReqStatesEnum.KDC_REQ_KDC_REQ_BODY_STATE, 206 KerberosConstants.KDC_REQ_KDC_REQ_BODY_TAG, 207 new StoreKdcReqBody() ); 208 } 209 210 211 /** 212 * Get the instance of this grammar 213 * 214 * @return An instance on the KDC-REQ Grammar 215 */ 216 public static Grammar<KdcReqContainer> getInstance() 217 { 218 return instance; 219 } 220}