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.krbPriv; 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.krbPriv.actions.CheckMsgType; 030import org.apache.directory.shared.kerberos.codec.krbPriv.actions.KrbPrivInit; 031import org.apache.directory.shared.kerberos.codec.krbPriv.actions.StoreEncPart; 032import org.apache.directory.shared.kerberos.codec.krbPriv.actions.StorePvno; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036 037/** 038 * This class implements the KRB-PRIV 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 KrbPrivGrammar extends AbstractGrammar<KrbPrivContainer> 045{ 046 /** The logger */ 047 static final Logger LOG = LoggerFactory.getLogger( KrbPrivGrammar.class ); 048 049 /** A speedup for logger */ 050 static final boolean IS_DEBUG = LOG.isDebugEnabled(); 051 052 /** The instance of grammar. KrbPrivGrammar is a singleton */ 053 private static Grammar<KrbPrivContainer> instance = new KrbPrivGrammar(); 054 055 056 /** 057 * Creates a new KrbPrivGrammar object. 058 */ 059 @SuppressWarnings("unchecked") 060 private KrbPrivGrammar() 061 { 062 setName( KrbPrivGrammar.class.getName() ); 063 064 // Create the transitions table 065 super.transitions = new GrammarTransition[KrbPrivStatesEnum.LAST_KRB_PRIV_STATE.ordinal()][256]; 066 067 // ============================================================================================ 068 // KRB_PRIV 069 // ============================================================================================ 070 // -------------------------------------------------------------------------------------------- 071 // Transition from KrbPriv init to KrbPriv tag 072 // -------------------------------------------------------------------------------------------- 073 // KRB_PRIV ::= [APPLICATION 21] 074 super.transitions[KrbPrivStatesEnum.START_STATE.ordinal()][KerberosConstants.KRB_PRIV_TAG] = 075 new GrammarTransition<KrbPrivContainer>( 076 KrbPrivStatesEnum.START_STATE, 077 KrbPrivStatesEnum.KRB_PRIV_TAG_STATE, 078 KerberosConstants.KRB_PRIV_TAG, 079 new KrbPrivInit() ); 080 081 // -------------------------------------------------------------------------------------------- 082 // Transition from KrbPriv tag to KrbPriv SEQ 083 // -------------------------------------------------------------------------------------------- 084 // KRB_PRIV ::= [APPLICATION 21] SEQUENCE { 085 super.transitions[KrbPrivStatesEnum.KRB_PRIV_TAG_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = 086 new GrammarTransition<KrbPrivContainer>( 087 KrbPrivStatesEnum.KRB_PRIV_TAG_STATE, 088 KrbPrivStatesEnum.KRB_PRIV_SEQ_STATE, 089 UniversalTag.SEQUENCE, 090 new CheckNotNullLength<KrbPrivContainer>() ); 091 092 // -------------------------------------------------------------------------------------------- 093 // Transition from KrbPriv SEQ to pvno tag 094 // -------------------------------------------------------------------------------------------- 095 // KRB_PRIV ::= SEQUENCE { 096 // pvno [0] 097 super.transitions[KrbPrivStatesEnum.KRB_PRIV_SEQ_STATE.ordinal()][KerberosConstants.KRB_PRIV_PVNO_TAG] = 098 new GrammarTransition<KrbPrivContainer>( 099 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}