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.tgsReq;
021
022
023import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
024import org.apache.directory.api.asn1.ber.grammar.Grammar;
025import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
026import org.apache.directory.shared.kerberos.KerberosConstants;
027import org.apache.directory.shared.kerberos.codec.tgsReq.actions.StoreKdcReq;
028import org.slf4j.Logger;
029import org.slf4j.LoggerFactory;
030
031
032/**
033 * This class implements the TGS-REQ structure. All the actions are declared
034 * in this class. As it is a singleton, these declaration are only done once. If
035 * an action is to be added or modified, this is where the work is to be done !
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 */
039public final class TgsReqGrammar extends AbstractGrammar<TgsReqContainer>
040{
041    /** The logger */
042    static final Logger LOG = LoggerFactory.getLogger( TgsReqGrammar.class );
043
044    /** A speedup for logger */
045    static final boolean IS_DEBUG = LOG.isDebugEnabled();
046
047    /** The instance of grammar. TgsReqGrammar is a singleton */
048    private static Grammar<TgsReqContainer> instance = new TgsReqGrammar();
049
050
051    /**
052     * Creates a new TgsReqGrammar object.
053     */
054    @SuppressWarnings("unchecked")
055    private TgsReqGrammar()
056    {
057        setName( TgsReqGrammar.class.getName() );
058
059        // Create the transitions table
060        super.transitions = new GrammarTransition[TgsReqStatesEnum.LAST_TGS_REQ_STATE.ordinal()][256];
061
062        // ============================================================================================
063        // TS-REQ
064        // ============================================================================================
065        // --------------------------------------------------------------------------------------------
066        // Transition from TS-REQ init to KDC-REQ
067        // --------------------------------------------------------------------------------------------
068        // TGS-REQ          ::= [APPLICATION 12] KDC-REQ
069        super.transitions[TgsReqStatesEnum.START_STATE.ordinal()][KerberosConstants.TGS_REQ_TAG] =
070            new GrammarTransition<TgsReqContainer>(
071                TgsReqStatesEnum.START_STATE,
072                TgsReqStatesEnum.TGS_REQ_STATE,
073                KerberosConstants.TGS_REQ_TAG,
074                new StoreKdcReq() );
075    }
076
077
078    /**
079     * Get the instance of this grammar
080     *
081     * @return An instance on the AS-REQ Grammar
082     */
083    public static Grammar<TgsReqContainer> getInstance()
084    {
085        return instance;
086    }
087}