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.messages; 021 022 023import java.nio.ByteBuffer; 024 025import org.apache.directory.api.asn1.EncoderException; 026import org.apache.directory.api.asn1.ber.tlv.TLV; 027import org.apache.directory.shared.kerberos.KerberosConstants; 028import org.apache.directory.shared.kerberos.KerberosMessageType; 029import org.apache.directory.shared.kerberos.KerberosTime; 030import org.apache.directory.shared.kerberos.components.KdcRep; 031import org.apache.directory.shared.kerberos.components.PrincipalName; 032import org.apache.directory.shared.kerberos.flags.TicketFlags; 033 034 035/** 036 * TGS-REP message. It's just a KDC-REP message with a message type set to 13. 037 * It will store the object described by the ASN.1 grammar : 038 * <pre> 039 * TGS-REP ::= [APPLICATION 13] <KDC-REP> 040 * </pre> 041 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 042 */ 043public class TgsRep extends KdcRep 044{ 045 // Storage for computed lengths 046 private int kdcRepLength; 047 048 049 /** 050 * Creates a new instance of TGS-REP. 051 */ 052 public TgsRep() 053 { 054 super( KerberosMessageType.TGS_REP ); 055 } 056 057 058 /** 059 * Returns the end {@link KerberosTime}. 060 * 061 * @return The end {@link KerberosTime}. 062 */ 063 public KerberosTime getEndTime() 064 { 065 return encKdcRepPart.getEndTime(); 066 } 067 068 069 /** 070 * Returns the {@link TicketFlags}. 071 * 072 * @return The {@link TicketFlags}. 073 */ 074 public TicketFlags getFlags() 075 { 076 return encKdcRepPart.getFlags(); 077 } 078 079 080 /** 081 * Returns the nonce. 082 * 083 * @return The nonce. 084 */ 085 public int getNonce() 086 { 087 return encKdcRepPart.getNonce(); 088 } 089 090 091 /** 092 * Returns the renew till {@link KerberosTime}. 093 * 094 * @return The renew till {@link KerberosTime}. 095 */ 096 public KerberosTime getRenewTill() 097 { 098 return encKdcRepPart.getRenewTill(); 099 } 100 101 102 /** 103 * Returns the start {@link KerberosTime}. 104 * 105 * @return The start {@link KerberosTime}. 106 */ 107 public KerberosTime getStartTime() 108 { 109 return encKdcRepPart.getStartTime(); 110 } 111 112 113 /** 114 * Returns the server {@link PrincipalName}. 115 * 116 * @return The server {@link PrincipalName}. 117 */ 118 public PrincipalName getSName() 119 { 120 return encKdcRepPart.getSName(); 121 } 122 123 124 /** 125 * Compute the TGS-REP length 126 * <pre> 127 * TGS-REP : 128 * 129 * 0x6D L1 TGS-REP message 130 * | 131 * +--> 0x30 L2 KDC-REP sequence 132 * </pre> 133 */ 134 @Override 135 public int computeLength() 136 { 137 kdcRepLength = super.computeLength(); 138 139 return 1 + TLV.getNbBytes( kdcRepLength ) + kdcRepLength; 140 } 141 142 143 /** 144 * Encode the TGS-REP component 145 * 146 * @param buffer The buffer containing the encoded result 147 * @return The encoded component 148 * @throws EncoderException If the encoding failed 149 */ 150 @Override 151 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException 152 { 153 if ( buffer == null ) 154 { 155 buffer = ByteBuffer.allocate( computeLength() ); 156 } 157 158 // The TGS-REP SEQ Tag 159 buffer.put( ( byte ) KerberosConstants.TGS_REP_TAG ); 160 buffer.put( TLV.getBytes( kdcRepLength ) ); 161 162 // The KDC-REP -------------------------------------------------------- 163 super.encode( buffer ); 164 165 return buffer; 166 } 167}