1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.kerberos.client;
21
22
23 import java.net.InetAddress;
24 import java.net.UnknownHostException;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Set;
28
29 import org.apache.directory.shared.kerberos.codec.options.KdcOptions;
30 import org.apache.directory.shared.kerberos.codec.types.EncryptionType;
31 import org.apache.directory.shared.kerberos.components.HostAddress;
32
33
34 public class TgtRequest
35 {
36 private String clientPrincipal;
37 private String password;
38 private String realm;
39 private String serverPrincipal;
40
41 private long startTime;
42
43 private long expiryTime;
44
45 private long renewTill;
46
47 private List<HostAddress> hostAddresses = new ArrayList<HostAddress>();
48
49 private KdcOptions options = new KdcOptions();
50
51 private boolean preAuthEnabled = false;
52
53
54 private Set<EncryptionType> eTypes;
55
56 public TgtRequest()
57 {
58 startTime = System.currentTimeMillis();
59 expiryTime = startTime + ( 8 * 60 * 60 * 1000 );
60 }
61
62
63 public void addHost( String hostNameOrIpAddress ) throws UnknownHostException
64 {
65 InetAddress address = InetAddress.getByName( hostNameOrIpAddress );
66 hostAddresses.add( new HostAddress( address ) );
67 }
68
69
70 public String getPassword()
71 {
72 return password;
73 }
74
75
76 public void setPassword( String password )
77 {
78 this.password = password;
79 }
80
81
82 public String getClientPrincipal()
83 {
84 return clientPrincipal;
85 }
86
87
88 public void setClientPrincipal( String clientPrincipal )
89 {
90 this.clientPrincipal = clientPrincipal;
91 realm = KdcClientUtil.extractRealm( clientPrincipal );
92 }
93
94
95 public String getRealm()
96 {
97 return realm;
98 }
99
100
101 public String getServerPrincipal()
102 {
103 return serverPrincipal;
104 }
105
106
107 public void setServerPrincipal( String serverPrincipal )
108 {
109 this.serverPrincipal = serverPrincipal;
110 }
111
112
113 public long getStartTime()
114 {
115 return startTime;
116 }
117
118
119 public void setStartTime( long startTime )
120 {
121 this.startTime = startTime;
122 }
123
124
125 public long getExpiryTime()
126 {
127 return expiryTime;
128 }
129
130
131 public void setExpiryTime( long expiryTime )
132 {
133 this.expiryTime = expiryTime;
134 }
135
136
137 public long getRenewTill()
138 {
139 return renewTill;
140 }
141
142
143 public void setRenewTill( long renewTill )
144 {
145 this.renewTill = renewTill;
146 }
147
148
149 public List<HostAddress> getHostAddresses()
150 {
151 return hostAddresses;
152 }
153
154
155 public void setForwardable( boolean forwardable )
156 {
157 setOrClear( KdcOptions.FORWARDABLE, forwardable );
158 }
159
160
161 public void setProxiable( boolean proxiable )
162 {
163 setOrClear( KdcOptions.PROXIABLE, proxiable );
164 }
165
166
167 public void setAllowPostdate( boolean allowPostdate )
168 {
169 setOrClear( KdcOptions.ALLOW_POSTDATE, allowPostdate );
170 }
171
172
173 public void setPostdated( boolean postdated )
174 {
175 setOrClear( KdcOptions.POSTDATED, postdated );
176 }
177
178
179 public void setRenewableOk( boolean renewableOk )
180 {
181 setOrClear( KdcOptions.RENEWABLE_OK, renewableOk );
182 }
183
184
185 public void setRenewable( boolean renewable )
186 {
187 setOrClear( KdcOptions.RENEWABLE, renewable );
188 }
189
190
191 public KdcOptions getOptions()
192 {
193 return options;
194 }
195
196
197 public boolean isPreAuthEnabled()
198 {
199 return preAuthEnabled;
200 }
201
202
203 public void setPreAuthEnabled( boolean preAuthEnabled )
204 {
205 this.preAuthEnabled = preAuthEnabled;
206 }
207
208 public String getSName()
209 {
210 return KdcClientUtil.extractName( serverPrincipal );
211 }
212
213 public String getCName()
214 {
215 return KdcClientUtil.extractName( clientPrincipal );
216 }
217
218
219 public Set<EncryptionType> getETypes()
220 {
221 return eTypes;
222 }
223
224
225 public void setETypes( Set<EncryptionType> eTypes )
226 {
227 this.eTypes = eTypes;
228 }
229
230
231 private void setOrClear( int pos, boolean set )
232 {
233 if ( set )
234 {
235 options.setBit( pos );
236 }
237 else
238 {
239 options.clearBit( pos );
240 }
241 }
242 }