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     */
020    package org.apache.directory.server.kerberos.shared.messages;
021    
022    
023    import javax.security.auth.kerberos.KerberosPrincipal;
024    
025    import org.apache.directory.server.kerberos.shared.KerberosMessageType;
026    import org.apache.directory.server.kerberos.shared.messages.components.EncKdcRepPart;
027    import org.apache.directory.server.kerberos.shared.messages.components.Ticket;
028    import org.apache.directory.server.kerberos.shared.messages.value.EncryptedData;
029    import org.apache.directory.server.kerberos.shared.messages.value.EncryptionKey;
030    import org.apache.directory.server.kerberos.shared.messages.value.HostAddresses;
031    import org.apache.directory.server.kerberos.shared.messages.value.KerberosTime;
032    import org.apache.directory.server.kerberos.shared.messages.value.LastRequest;
033    import org.apache.directory.server.kerberos.shared.messages.value.PaData;
034    import org.apache.directory.server.kerberos.shared.messages.value.flags.TicketFlags;
035    
036    
037    /**
038     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
039     * @version $Rev: 591019 $, $Date: 2007-11-01 15:16:34 +0100 (Thu, 01 Nov 2007) $
040     */
041    public class KdcReply extends KerberosMessage implements Encodable
042    {
043        private PaData[] paData; //optional
044        private KerberosPrincipal clientPrincipal;
045        private Ticket ticket;
046    
047        private EncKdcRepPart encKDCRepPart = new EncKdcRepPart();
048        private EncryptedData encPart;
049    
050    
051        /**
052         * Creates a new instance of KdcReply.
053         *
054         * @param msgType
055         */
056        public KdcReply( KerberosMessageType msgType )
057        {
058            super( msgType );
059        }
060    
061    
062        /**
063         * Creates a new instance of KdcReply.
064         *
065         * @param paData
066         * @param clientPrincipal
067         * @param ticket
068         * @param encPart
069         * @param msgType
070         */
071        public KdcReply( PaData[] paData, KerberosPrincipal clientPrincipal, Ticket ticket,
072            EncryptedData encPart, KerberosMessageType msgType )
073        {
074            this( msgType );
075            this.paData = paData;
076            this.clientPrincipal = clientPrincipal;
077            this.ticket = ticket;
078            this.encPart = encPart;
079        }
080    
081    
082        /**
083         * Returns the client {@link KerberosPrincipal}.
084         *
085         * @return The client {@link KerberosPrincipal}.
086         */
087        public KerberosPrincipal getClientPrincipal()
088        {
089            return clientPrincipal;
090        }
091    
092    
093        /**
094         * Returns the client realm.
095         *
096         * @return The client realm.
097         */
098        public String getClientRealm()
099        {
100            return clientPrincipal.getRealm();
101        }
102    
103    
104        /**
105         * Returns the {@link EncryptedData}.
106         *
107         * @return The {@link EncryptedData}.
108         */
109        public EncryptedData getEncPart()
110        {
111            return encPart;
112        }
113    
114    
115        /**
116         * Returns an array of {@link PaData}s.
117         *
118         * @return The array of {@link PaData}s.
119         */
120        public PaData[] getPaData()
121        {
122            return paData;
123        }
124    
125    
126        /**
127         * Returns the {@link Ticket}.
128         *
129         * @return The {@link Ticket}.
130         */
131        public Ticket getTicket()
132        {
133            return ticket;
134        }
135    
136    
137        /**
138         * Sets the client {@link KerberosPrincipal}.
139         *
140         * @param clientPrincipal
141         */
142        public void setClientPrincipal( KerberosPrincipal clientPrincipal )
143        {
144            this.clientPrincipal = clientPrincipal;
145        }
146    
147    
148        /**
149         * Sets the {@link EncKdcRepPart}.
150         *
151         * @param repPart
152         */
153        public void setEncKDCRepPart( EncKdcRepPart repPart )
154        {
155            encKDCRepPart = repPart;
156        }
157    
158    
159        /**
160         * Sets the {@link EncryptedData}.
161         *
162         * @param part
163         */
164        public void setEncPart( EncryptedData part )
165        {
166            encPart = part;
167        }
168    
169    
170        /**
171         * Sets the array of {@link PaData}s.
172         *
173         * @param data
174         */
175        public void setPaData( PaData[] data )
176        {
177            paData = data;
178        }
179    
180    
181        /**
182         * Sets the {@link Ticket}.
183         *
184         * @param ticket
185         */
186        public void setTicket( Ticket ticket )
187        {
188            this.ticket = ticket;
189        }
190    
191    
192        // EncKdcRepPart delegate getters
193    
194        /**
195         * Returns the auth {@link KerberosTime}.
196         *
197         * @return The auth {@link KerberosTime}.
198         */
199        public KerberosTime getAuthTime()
200        {
201            return encKDCRepPart.getAuthTime();
202        }
203    
204    
205        /**
206         * Returns the client {@link HostAddresses}.
207         *
208         * @return The client {@link HostAddresses}.
209         */
210        public HostAddresses getClientAddresses()
211        {
212            return encKDCRepPart.getClientAddresses();
213        }
214    
215    
216        /**
217         * Return the end {@link KerberosTime}.
218         *
219         * @return The end {@link KerberosTime}.
220         */
221        public KerberosTime getEndTime()
222        {
223            return encKDCRepPart.getEndTime();
224        }
225    
226    
227        /**
228         * Returns the {@link TicketFlags}.
229         *
230         * @return The {@link TicketFlags}.
231         */
232        public TicketFlags getFlags()
233        {
234            return encKDCRepPart.getFlags();
235        }
236    
237    
238        /**
239         * Returns the {@link EncryptionKey}.
240         *
241         * @return The {@link EncryptionKey}.
242         */
243        public EncryptionKey getKey()
244        {
245            return encKDCRepPart.getKey();
246        }
247    
248    
249        /**
250         * Returns the key expiration {@link KerberosTime}.
251         *
252         * @return The key expiration {@link KerberosTime}.
253         */
254        public KerberosTime getKeyExpiration()
255        {
256            return encKDCRepPart.getKeyExpiration();
257        }
258    
259    
260        /**
261         * Returns the {@link LastRequest}.
262         *
263         * @return The {@link LastRequest}.
264         */
265        public LastRequest getLastRequest()
266        {
267            return encKDCRepPart.getLastRequest();
268        }
269    
270    
271        /**
272         * Returns the nonce.
273         *
274         * @return The nonce.
275         */
276        public int getNonce()
277        {
278            return encKDCRepPart.getNonce();
279        }
280    
281    
282        /**
283         * Returns the renew till {@link KerberosTime}.
284         *
285         * @return The renew till {@link KerberosTime}.
286         */
287        public KerberosTime getRenewTill()
288        {
289            return encKDCRepPart.getRenewTill();
290        }
291    
292    
293        /**
294         * Returns the server {@link KerberosPrincipal}.
295         *
296         * @return The server {@link KerberosPrincipal}.
297         */
298        public KerberosPrincipal getServerPrincipal()
299        {
300            return encKDCRepPart.getServerPrincipal();
301        }
302    
303    
304        /**
305         * Return the server realm.
306         *
307         * @return The server realm.
308         */
309        public String getServerRealm()
310        {
311            return encKDCRepPart.getServerRealm();
312        }
313    
314    
315        /**
316         * Returns the start {@link KerberosTime}.
317         *
318         * @return The start {@link KerberosTime}.
319         */
320        public KerberosTime getStartTime()
321        {
322            return encKDCRepPart.getStartTime();
323        }
324    
325    
326        // EncKdcRepPart delegate setters
327    
328        /**
329         * Sets the auth {@link KerberosTime}.
330         *
331         * @param time
332         */
333        public void setAuthTime( KerberosTime time )
334        {
335            encKDCRepPart.setAuthTime( time );
336        }
337    
338    
339        /**
340         * Sets the client {@link HostAddresses}.
341         *
342         * @param addresses
343         */
344        public void setClientAddresses( HostAddresses addresses )
345        {
346            encKDCRepPart.setClientAddresses( addresses );
347        }
348    
349    
350        /**
351         * Sets the end {@link KerberosTime}.
352         *
353         * @param time
354         */
355        public void setEndTime( KerberosTime time )
356        {
357            encKDCRepPart.setEndTime( time );
358        }
359    
360    
361        /**
362         * Sets the {@link TicketFlags}.
363         *
364         * @param flags
365         */
366        public void setFlags( TicketFlags flags )
367        {
368            encKDCRepPart.setFlags( flags );
369        }
370    
371    
372        /**
373         * Sets the {@link EncryptionKey}.
374         *
375         * @param key
376         */
377        public void setKey( EncryptionKey key )
378        {
379            encKDCRepPart.setKey( key );
380        }
381    
382    
383        /**
384         * Sets the key expiration {@link KerberosTime}.
385         *
386         * @param expiration
387         */
388        public void setKeyExpiration( KerberosTime expiration )
389        {
390            encKDCRepPart.setKeyExpiration( expiration );
391        }
392    
393    
394        /**
395         * Sets the {@link LastRequest}.
396         *
397         * @param request
398         */
399        public void setLastRequest( LastRequest request )
400        {
401            encKDCRepPart.setLastRequest( request );
402        }
403    
404    
405        /**
406         * Sets the nonce.
407         *
408         * @param nonce
409         */
410        public void setNonce( int nonce )
411        {
412            encKDCRepPart.setNonce( nonce );
413        }
414    
415    
416        /**
417         * Sets the renew till {@link KerberosTime}.
418         *
419         * @param till
420         */
421        public void setRenewTill( KerberosTime till )
422        {
423            encKDCRepPart.setRenewTill( till );
424        }
425    
426    
427        /**
428         * Sets the server {@link KerberosPrincipal}.
429         *
430         * @param principal
431         */
432        public void setServerPrincipal( KerberosPrincipal principal )
433        {
434            encKDCRepPart.setServerPrincipal( principal );
435        }
436    
437    
438        /**
439         * Sets the start {@link KerberosTime}.
440         *
441         * @param time
442         */
443        public void setStartTime( KerberosTime time )
444        {
445            encKDCRepPart.setStartTime( time );
446        }
447    }