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.apReq; 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.apReq.actions.ApReqInit; 030import org.apache.directory.shared.kerberos.codec.apReq.actions.CheckMsgType; 031import org.apache.directory.shared.kerberos.codec.apReq.actions.StoreApOptions; 032import org.apache.directory.shared.kerberos.codec.apReq.actions.StoreAuthenticator; 033import org.apache.directory.shared.kerberos.codec.apReq.actions.StorePvno; 034import org.apache.directory.shared.kerberos.codec.apReq.actions.StoreTicket; 035import org.slf4j.Logger; 036import org.slf4j.LoggerFactory; 037 038 039/** 040 * This class implements the AP-REQ structure. All the actions are declared 041 * in this class. As it is a singleton, these declaration are only done once. If 042 * an action is to be added or modified, this is where the work is to be done ! 043 * 044 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 045 */ 046public final class ApReqGrammar extends AbstractGrammar<ApReqContainer> 047{ 048 /** The logger */ 049 static final Logger LOG = LoggerFactory.getLogger( ApReqGrammar.class ); 050 051 /** A speedup for logger */ 052 static final boolean IS_DEBUG = LOG.isDebugEnabled(); 053 054 /** The instance of grammar. ApReqGrammar is a singleton */ 055 private static Grammar<ApReqContainer> instance = new ApReqGrammar(); 056 057 058 /** 059 * Creates a new ApReqGrammar object. 060 */ 061 @SuppressWarnings("unchecked") 062 private ApReqGrammar() 063 { 064 setName( ApReqGrammar.class.getName() ); 065 066 // Create the transitions table 067 super.transitions = new GrammarTransition[ApReqStatesEnum.LAST_AP_REQ_STATE.ordinal()][256]; 068 069 // ============================================================================================ 070 // AP-REQ 071 // ============================================================================================ 072 // -------------------------------------------------------------------------------------------- 073 // Transition from AP-REQ init to AP-REQ tag 074 // -------------------------------------------------------------------------------------------- 075 // AP-REQ ::= [APPLICATION 14] 076 super.transitions[ApReqStatesEnum.START_STATE.ordinal()][KerberosConstants.AP_REQ_TAG] = 077 new GrammarTransition<ApReqContainer>( 078 ApReqStatesEnum.START_STATE, 079 ApReqStatesEnum.AP_REQ_STATE, 080 KerberosConstants.AP_REQ_TAG, 081 new ApReqInit() ); 082 083 // -------------------------------------------------------------------------------------------- 084 // Transition from AP-REQ tag to AP-REQ SEQ { 085 // -------------------------------------------------------------------------------------------- 086 // AP-REQ ::= [APPLICATION 14] SEQUENCE 087 super.transitions[ApReqStatesEnum.AP_REQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 088 new GrammarTransition<ApReqContainer>( 089 ApReqStatesEnum.AP_REQ_STATE, 090 ApReqStatesEnum.AP_REQ_SEQ_STATE, 091 UniversalTag.SEQUENCE, 092 new CheckNotNullLength<ApReqContainer>() ); 093 094 // -------------------------------------------------------------------------------------------- 095 // Transition from AP-REQ SEQ to PVNO tag 096 // -------------------------------------------------------------------------------------------- 097 // AP-REQ ::= [APPLICATION 14] SEQUENCE 098 // pvno [0] 099 super.transitions[ApReqStatesEnum.AP_REQ_SEQ_STATE.ordinal()][KerberosConstants.AP_REQ_PVNO_TAG] = 100 new GrammarTransition<ApReqContainer>( 101 ApReqStatesEnum.AP_REQ_SEQ_STATE, 102 ApReqStatesEnum.AP_REQ_PVNO_TAG_STATE, 103 KerberosConstants.AP_REQ_PVNO_TAG, 104 new CheckNotNullLength<ApReqContainer>() ); 105 106 // -------------------------------------------------------------------------------------------- 107 // Transition from PVNO tag to PVNO value 108 // -------------------------------------------------------------------------------------------- 109 // AP-REQ ::= [APPLICATION 14] SEQUENCE 110 // pvno [0] INTEGER (5), 111 super.transitions[ApReqStatesEnum.AP_REQ_PVNO_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = 112 new GrammarTransition<ApReqContainer>( 113 ApReqStatesEnum.AP_REQ_PVNO_TAG_STATE, 114 ApReqStatesEnum.AP_REQ_PVNO_STATE, 115 UniversalTag.INTEGER, 116 new StorePvno() ); 117 118 // -------------------------------------------------------------------------------------------- 119 // Transition from PVNO value to msg-type tag 120 // -------------------------------------------------------------------------------------------- 121 // AP-REQ ::= [APPLICATION 14] SEQUENCE 122 // ... 123 // msg-type [1] 124 super.transitions[ApReqStatesEnum.AP_REQ_PVNO_STATE.ordinal()][KerberosConstants.AP_REQ_MSG_TYPE_TAG] = 125 new GrammarTransition<ApReqContainer>( 126 ApReqStatesEnum.AP_REQ_PVNO_STATE, 127 ApReqStatesEnum.AP_REQ_MSG_TYPE_TAG_STATE, 128 KerberosConstants.AP_REQ_MSG_TYPE_TAG, 129 new CheckNotNullLength<ApReqContainer>() ); 130 131 // -------------------------------------------------------------------------------------------- 132 // Transition from msg-type tag to msg-type value 133 // -------------------------------------------------------------------------------------------- 134 // AP-REQ ::= [APPLICATION 14] SEQUENCE 135 // ... 136 // msg-type [1] INTEGER (14), 137 super.transitions[ApReqStatesEnum.AP_REQ_MSG_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] = 138 new GrammarTransition<ApReqContainer>( 139 ApReqStatesEnum.AP_REQ_MSG_TYPE_TAG_STATE, 140 ApReqStatesEnum.AP_REQ_MSG_TYPE_STATE, 141 UniversalTag.INTEGER, 142 new CheckMsgType() ); 143 144 // -------------------------------------------------------------------------------------------- 145 // Transition from msg-type value to ap-options tag 146 // -------------------------------------------------------------------------------------------- 147 // AP-REQ ::= [APPLICATION 14] SEQUENCE 148 // ... 149 // ap-options [2] 150 super.transitions[ApReqStatesEnum.AP_REQ_MSG_TYPE_STATE.ordinal()][KerberosConstants.AP_REQ_AP_OPTIONS_TAG] = 151 new GrammarTransition<ApReqContainer>( 152 ApReqStatesEnum.AP_REQ_MSG_TYPE_STATE, 153 ApReqStatesEnum.AP_REQ_AP_OPTIONS_TAG_STATE, 154 KerberosConstants.AP_REQ_AP_OPTIONS_TAG, 155 new CheckNotNullLength<ApReqContainer>() ); 156 157 // -------------------------------------------------------------------------------------------- 158 // Transition from ap-options tag to ap-options value 159 // -------------------------------------------------------------------------------------------- 160 // AP-REQ ::= [APPLICATION 14] SEQUENCE 161 // ... 162 // ap-options [2] APOptions, 163 super.transitions[ApReqStatesEnum.AP_REQ_AP_OPTIONS_TAG_STATE.ordinal()][UniversalTag.BIT_STRING.getValue()] = 164 new GrammarTransition<ApReqContainer>( 165 ApReqStatesEnum.AP_REQ_AP_OPTIONS_TAG_STATE, 166 ApReqStatesEnum.AP_REQ_AP_OPTIONS_STATE, 167 UniversalTag.BIT_STRING, 168 new StoreApOptions() ); 169 170 // -------------------------------------------------------------------------------------------- 171 // Transition from ap-options value to ticket 172 // -------------------------------------------------------------------------------------------- 173 // AP-REQ ::= [APPLICATION 14] SEQUENCE 174 // ... 175 // ticket [3] Ticket, 176 super.transitions[ApReqStatesEnum.AP_REQ_AP_OPTIONS_STATE.ordinal()][KerberosConstants.AP_REQ_TICKET_TAG] = 177 new GrammarTransition<ApReqContainer>( 178 ApReqStatesEnum.AP_REQ_AP_OPTIONS_STATE, 179 ApReqStatesEnum.AP_REQ_TICKET_STATE, 180 KerberosConstants.AP_REQ_TICKET_TAG, 181 new StoreTicket() ); 182 183 // -------------------------------------------------------------------------------------------- 184 // Transition from ticket to authenticator 185 // -------------------------------------------------------------------------------------------- 186 // AP-REQ ::= [APPLICATION 14] SEQUENCE 187 // ... 188 // authenticator [4] <EncryptedData> -- Authenticator 189 // } 190 super.transitions[ApReqStatesEnum.AP_REQ_TICKET_STATE.ordinal()][KerberosConstants.AP_REQ_AUTHENTICATOR_TAG] = 191 new GrammarTransition<ApReqContainer>( 192 ApReqStatesEnum.AP_REQ_TICKET_STATE, 193 ApReqStatesEnum.LAST_AP_REQ_STATE, 194 KerberosConstants.AP_REQ_AUTHENTICATOR_TAG, 195 new StoreAuthenticator() ); 196 } 197 198 199 /** 200 * Get the instance of this grammar 201 * 202 * @return An instance on the AP-REQ Grammar 203 */ 204 public static Grammar<ApReqContainer> getInstance() 205 { 206 return instance; 207 } 208}