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.server.kerberos.kdc;
21  
22  
23  import java.net.InetAddress;
24  
25  import org.apache.directory.server.kerberos.KerberosConfig;
26  import org.apache.directory.server.kerberos.shared.crypto.encryption.CipherTextHandler;
27  import org.apache.directory.server.kerberos.shared.replay.ReplayCache;
28  import org.apache.directory.server.kerberos.shared.store.PrincipalStore;
29  import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
30  import org.apache.directory.shared.kerberos.components.KdcReq;
31  import org.apache.directory.shared.kerberos.messages.KerberosMessage;
32  
33  
34  /**
35   * The context used to store the collected and computed data while processing a 
36   * kerberos message.
37   * 
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public abstract class KdcContext
41  {
42      private static final long serialVersionUID = 6490030984626825108L;
43  
44      /** The KDC server configuration */
45      private KerberosConfig config;
46      private PrincipalStore store;
47  
48      /** The request being processed */
49      private KdcReq request;
50  
51      /** The kerberos response */
52      private KerberosMessage reply;
53  
54      /** The client IP address */
55      private InetAddress clientAddress;
56      private CipherTextHandler cipherTextHandler;
57  
58      /** The encryption type */
59      private EncryptionType encryptionType;
60  
61      /** the replay cache */
62      private ReplayCache replayCache;
63  
64      /**
65       * @return Returns the config.
66       */
67      public KerberosConfig getConfig()
68      {
69          return config;
70      }
71  
72  
73      /**
74       * @param config The config to set.
75       */
76      public void setConfig( KerberosConfig config )
77      {
78          this.config = config;
79      }
80  
81  
82      /**
83       * @return Returns the store.
84       */
85      public PrincipalStore getStore()
86      {
87          return store;
88      }
89  
90  
91      /**
92       * @param store The store to set.
93       */
94      public void setStore( PrincipalStore store )
95      {
96          this.store = store;
97      }
98  
99  
100     /**
101      * @return Returns the request.
102      */
103     public KdcReq getRequest()
104     {
105         return request;
106     }
107 
108 
109     /**
110      * @param request The request to set.
111      */
112     public void setRequest( KdcReq request )
113     {
114         this.request = request;
115     }
116 
117 
118     /**
119      * @return Returns the reply.
120      */
121     public KerberosMessage getReply()
122     {
123         return reply;
124     }
125 
126 
127     /**
128      * @param reply The reply to set.
129      */
130     public void setReply( KerberosMessage reply )
131     {
132         this.reply = reply;
133     }
134 
135 
136     /**
137      * @return Returns the clientAddress.
138      */
139     public InetAddress getClientAddress()
140     {
141         return clientAddress;
142     }
143 
144 
145     /**
146      * @param clientAddress The clientAddress to set.
147      */
148     public void setClientAddress( InetAddress clientAddress )
149     {
150         this.clientAddress = clientAddress;
151     }
152 
153 
154     /**
155      * @return Returns the {@link CipherTextHandler}.
156      */
157     public CipherTextHandler getCipherTextHandler()
158     {
159         return cipherTextHandler;
160     }
161 
162 
163     /**
164      * @param cipherTextHandler The {@link CipherTextHandler} to set.
165      */
166     public void setCipherTextHandler( CipherTextHandler cipherTextHandler )
167     {
168         this.cipherTextHandler = cipherTextHandler;
169     }
170 
171 
172     /**
173      * Returns the encryption type to use for this session.
174      *
175      * @return The encryption type.
176      */
177     public EncryptionType getEncryptionType()
178     {
179         return encryptionType;
180     }
181 
182 
183     /**
184      * Sets the encryption type to use for this session.
185      *
186      * @param encryptionType The encryption type to set.
187      */
188     public void setEncryptionType( EncryptionType encryptionType )
189     {
190         this.encryptionType = encryptionType;
191     }
192 
193 
194     /**
195      * @see Object#toString()
196      */
197     public String toString()
198     {
199         StringBuilder sb = new StringBuilder();
200 
201         sb.append( "Req : " ).append( request.toString( "    " ) );
202         sb.append( "Client address : " ).append( clientAddress );
203 
204         if ( encryptionType != null )
205         {
206             sb.append( '\n' );
207             sb.append( "EncryptionType : " ).append( encryptionType );
208         }
209 
210         return sb.toString();
211     }
212     
213     
214     /**
215      * sets the replay cache
216      *
217      * @param replayCache The Replay cache instance
218      */
219     public void setReplayCache( ReplayCache replayCache )
220     {
221         this.replayCache = replayCache;
222     }
223 
224 
225     /**
226      * @return the replay cache
227      */
228     public ReplayCache getReplayCache()
229     {
230         return replayCache;
231     }
232 }