View Javadoc
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.messages;
21  
22  
23  import java.nio.ByteBuffer;
24  
25  import org.apache.directory.api.asn1.EncoderException;
26  import org.apache.directory.api.asn1.ber.tlv.TLV;
27  import org.apache.directory.shared.kerberos.KerberosConstants;
28  import org.apache.directory.shared.kerberos.KerberosMessageType;
29  import org.apache.directory.shared.kerberos.KerberosTime;
30  import org.apache.directory.shared.kerberos.components.KdcRep;
31  import org.apache.directory.shared.kerberos.components.PrincipalName;
32  import org.apache.directory.shared.kerberos.flags.TicketFlags;
33  
34  
35  /**
36   * AS-REQ message. It's just a KDC-REP message with a message type set to 11.
37   *  It will store the object described by the ASN.1 grammar :
38   * <pre>
39   * AS-REP          ::= [APPLICATION 11] &lt;KDC-RE&gt;P
40   * </pre>
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  public class AsRep extends KdcRep
44  {
45      // Storage for computed lengths
46      private int kdcRepLength;
47      private int asRepLength;
48  
49  
50      /**
51       * Creates a new instance of AS-REP.
52       */
53      public AsRep()
54      {
55          super( KerberosMessageType.AS_REP );
56      }
57  
58  
59      /**
60       * Returns the end {@link KerberosTime}.
61       *
62       * @return The end {@link KerberosTime}.
63       */
64      public KerberosTime getEndTime()
65      {
66          return encKdcRepPart.getEndTime();
67      }
68  
69  
70      /**
71       * Returns the {@link TicketFlags}.
72       *
73       * @return The {@link TicketFlags}.
74       */
75      public TicketFlags getFlags()
76      {
77          return encKdcRepPart.getFlags();
78      }
79  
80  
81      /**
82       * Returns the nonce.
83       *
84       * @return The nonce.
85       */
86      public int getNonce()
87      {
88          return encKdcRepPart.getNonce();
89      }
90  
91  
92      /**
93       * Returns the renew till {@link KerberosTime}.
94       *
95       * @return The renew till {@link KerberosTime}.
96       */
97      public KerberosTime getRenewTill()
98      {
99          return encKdcRepPart.getRenewTill();
100     }
101 
102 
103     /**
104      * Returns the start {@link KerberosTime}.
105      *
106      * @return The start {@link KerberosTime}.
107      */
108     public KerberosTime getStartTime()
109     {
110         return encKdcRepPart.getStartTime();
111     }
112 
113 
114     /**
115      * Returns the server {@link PrincipalName}.
116      *
117      * @return The server {@link PrincipalName}.
118      */
119     public PrincipalName getSName()
120     {
121         return encKdcRepPart.getSName();
122     }
123 
124 
125     /**
126      * Compute the AS-REP length
127      * <pre>
128      * AS-REP :
129      * 
130      * 0x6B L1 AS-REP message
131      *  |
132      *  +--&gt;  0x30 L2 KDC-REP sequence
133      * </pre>
134      */
135     @Override
136     public int computeLength()
137     {
138         kdcRepLength = super.computeLength();
139         asRepLength = 1 + TLV.getNbBytes( kdcRepLength ) + kdcRepLength;
140 
141         return asRepLength;
142     }
143 
144 
145     /**
146      * Encode the AS-REP component
147      * 
148      * @param buffer The buffer containing the encoded result
149      * @return The encoded component
150      * @throws org.apache.directory.api.asn1.EncoderException If the encoding failed
151      */
152     @Override
153     public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
154     {
155         if ( buffer == null )
156         {
157             buffer = ByteBuffer.allocate( computeLength() );
158         }
159 
160         // The AS-REP SEQ Tag
161         buffer.put( ( byte ) KerberosConstants.AS_REP_TAG );
162         buffer.put( TLV.getBytes( kdcRepLength ) );
163 
164         // The KDC-REP --------------------------------------------------------
165         super.encode( buffer );
166 
167         return buffer;
168     }
169 }