author | weijun |
Fri, 17 Jun 2016 09:46:34 +0800 | |
changeset 39047 | cf08ea56b4de |
parent 36511 | 9d0388c6b336 |
child 42338 | a60f280f803c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21961
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
||
27 |
package com.sun.security.auth.module; |
|
28 |
||
29 |
import java.io.*; |
|
16503
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
30 |
import java.security.AccessController; |
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
31 |
import java.security.PrivilegedAction; |
2 | 32 |
import java.text.MessageFormat; |
33 |
import java.util.*; |
|
34 |
||
35 |
import javax.security.auth.*; |
|
25662 | 36 |
import javax.security.auth.kerberos.KerberosTicket; |
37 |
import javax.security.auth.kerberos.KerberosPrincipal; |
|
38 |
import javax.security.auth.kerberos.KerberosKey; |
|
39 |
import javax.security.auth.kerberos.KeyTab; |
|
2 | 40 |
import javax.security.auth.callback.*; |
41 |
import javax.security.auth.login.*; |
|
42 |
import javax.security.auth.spi.*; |
|
43 |
||
44 |
import sun.security.krb5.*; |
|
45 |
import sun.security.jgss.krb5.Krb5Util; |
|
46 |
import sun.security.krb5.Credentials; |
|
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
31643
diff
changeset
|
47 |
import sun.security.util.HexDumpEncoder; |
2 | 48 |
|
49 |
/** |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
50 |
* This {@code LoginModule} authenticates users using |
2 | 51 |
* Kerberos protocols. |
52 |
* |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
53 |
* <p> The configuration entry for {@code Krb5LoginModule} has |
2 | 54 |
* several options that control the authentication process and |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
55 |
* additions to the {@code Subject}'s private credential |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
56 |
* set. Irrespective of these options, the {@code Subject}'s |
2 | 57 |
* principal set and private credentials set are updated only when |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
58 |
* {@code commit} is called. |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
59 |
* When {@code commit} is called, the {@code KerberosPrincipal} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
60 |
* is added to the {@code Subject}'s principal set (unless the |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
61 |
* {@code principal} is specified as "*"). If {@code isInitiator} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
62 |
* is true, the {@code KerberosTicket} is |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
63 |
* added to the {@code Subject}'s private credentials. |
2 | 64 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
65 |
* <p> If the configuration entry for {@code KerberosLoginModule} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
66 |
* has the option {@code storeKey} set to true, then |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
67 |
* {@code KerberosKey} or {@code KeyTab} will also be added to the |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
68 |
* subject's private credentials. {@code KerberosKey}, the principal's |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
69 |
* key(s) will be derived from user's password, and {@code KeyTab} is |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
70 |
* the keytab used when {@code useKeyTab} is set to true. The |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
71 |
* {@code KeyTab} object is restricted to be used by the specified |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
72 |
* principal unless the principal value is "*". |
2 | 73 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
74 |
* <p> This {@code LoginModule} recognizes the {@code doNotPrompt} |
2 | 75 |
* option. If set to true the user will not be prompted for the password. |
76 |
* |
|
77 |
* <p> The user can specify the location of the ticket cache by using |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
78 |
* the option {@code ticketCache} in the configuration entry. |
2 | 79 |
* |
80 |
* <p>The user can specify the keytab location by using |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
81 |
* the option {@code keyTab} |
2 | 82 |
* in the configuration entry. |
83 |
* |
|
84 |
* <p> The principal name can be specified in the configuration entry |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
85 |
* by using the option {@code principal}. The principal name |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
86 |
* can either be a simple user name, a service name such as |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
87 |
* {@code host/mission.eng.sun.com}, or "*". The principal can also |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
88 |
* be set using the system property {@code sun.security.krb5.principal}. |
2 | 89 |
* This property is checked during login. If this property is not set, then |
90 |
* the principal name from the configuration is used. In the |
|
91 |
* case where the principal property is not set and the principal |
|
92 |
* entry also does not exist, the user is prompted for the name. |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
93 |
* When this property of entry is set, and {@code useTicketCache} |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
94 |
* is set to true, only TGT belonging to this principal is used. |
2 | 95 |
* |
96 |
* <p> The following is a list of configuration options supported |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
97 |
* for {@code Krb5LoginModule}: |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
98 |
* <blockquote><dl> |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
99 |
* <dt>{@code refreshKrb5Config}:</dt> |
2 | 100 |
* <dd> Set this to true, if you want the configuration |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
101 |
* to be refreshed before the {@code login} method is called.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
102 |
* <dt>{@code useTicketCache}:</dt> |
2 | 103 |
* <dd>Set this to true, if you want the |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
104 |
* TGT to be obtained from the ticket cache. Set this option |
2 | 105 |
* to false if you do not want this module to use the ticket cache. |
106 |
* (Default is False). |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
107 |
* This module will search for the ticket |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
108 |
* cache in the following locations: On Solaris and Linux |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
109 |
* it will look for the ticket cache in /tmp/krb5cc_{@code uid} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
110 |
* where the uid is numeric user identifier. If the ticket cache is |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
111 |
* not available in the above location, or if we are on a |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
112 |
* Windows platform, it will look for the cache as |
2 | 113 |
* {user.home}{file.separator}krb5cc_{user.name}. |
114 |
* You can override the ticket cache location by using |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
115 |
* {@code ticketCache}. |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
116 |
* For Windows, if a ticket cannot be retrieved from the file ticket cache, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
117 |
* it will use Local Security Authority (LSA) API to get the TGT. |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
118 |
* <dt>{@code ticketCache}:</dt> |
2 | 119 |
* <dd>Set this to the name of the ticket |
120 |
* cache that contains user's TGT. |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
121 |
* If this is set, {@code useTicketCache} |
2 | 122 |
* must also be set to true; Otherwise a configuration error will |
123 |
* be returned.</dd> |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
124 |
* <dt>{@code renewTGT}:</dt> |
31643
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
125 |
* <dd>Set this to true, if you want to renew the TGT when it's more than |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
126 |
* half-way expired (the time until expiration is less than the time |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
127 |
* since start time). If this is set, {@code useTicketCache} must also be |
2 | 128 |
* set to true; otherwise a configuration error will be returned.</dd> |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
129 |
* <dt>{@code doNotPrompt}:</dt> |
2 | 130 |
* <dd>Set this to true if you do not want to be |
131 |
* prompted for the password |
|
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
132 |
* if credentials can not be obtained from the cache, the keytab, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
133 |
* or through shared state.(Default is false) |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
134 |
* If set to true, credential must be obtained through cache, keytab, |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
135 |
* or shared state. Otherwise, authentication will fail.</dd> |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
136 |
* <dt>{@code useKeyTab}:</dt> |
2 | 137 |
* <dd>Set this to true if you |
138 |
* want the module to get the principal's key from the |
|
139 |
* the keytab.(default value is False) |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
140 |
* If {@code keytab} is not set then |
2 | 141 |
* the module will locate the keytab from the |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
142 |
* Kerberos configuration file. |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
143 |
* If it is not specified in the Kerberos configuration file |
2 | 144 |
* then it will look for the file |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
145 |
* {@code {user.home}{file.separator}}krb5.keytab.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
146 |
* <dt>{@code keyTab}:</dt> |
2 | 147 |
* <dd>Set this to the file name of the |
148 |
* keytab to get principal's secret key.</dd> |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
149 |
* <dt>{@code storeKey}:</dt> |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
150 |
* <dd>Set this to true to if you want the keytab or the |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
151 |
* principal's key to be stored in the Subject's private credentials. |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
152 |
* For {@code isInitiator} being false, if {@code principal} |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
153 |
* is "*", the {@link KeyTab} stored can be used by anyone, otherwise, |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
154 |
* it's restricted to be used by the specified principal only.</dd> |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
155 |
* <dt>{@code principal}:</dt> |
2 | 156 |
* <dd>The name of the principal that should |
157 |
* be used. The principal can be a simple username such as |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
158 |
* "{@code testuser}" or a service name such as |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
159 |
* "{@code host/testhost.eng.sun.com}". You can use the |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
160 |
* {@code principal} option to set the principal when there are |
2 | 161 |
* credentials for multiple principals in the |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
162 |
* {@code keyTab} or when you want a specific ticket cache only. |
2 | 163 |
* The principal can also be set using the system property |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
164 |
* {@code sun.security.krb5.principal}. In addition, if this |
2 | 165 |
* system property is defined, then it will be used. If this property |
166 |
* is not set, then the principal name from the configuration will be |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
167 |
* used. |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
168 |
* The principal name can be set to "*" when {@code isInitiator} is false. |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
169 |
* In this case, the acceptor is not bound to a single principal. It can |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
170 |
* act as any principal an initiator requests if keys for that principal |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
171 |
* can be found. When {@code isInitiator} is true, the principal name |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
172 |
* cannot be set to "*". |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
173 |
* </dd> |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
174 |
* <dt>{@code isInitiator}:</dt> |
2 | 175 |
* <dd>Set this to true, if initiator. Set this to false, if acceptor only. |
176 |
* (Default is true). |
|
177 |
* Note: Do not set this value to false for initiators.</dd> |
|
178 |
* </dl></blockquote> |
|
179 |
* |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
180 |
* <p> This {@code LoginModule} also recognizes the following additional |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
181 |
* {@code Configuration} |
2 | 182 |
* options that enable you to share username and passwords across different |
183 |
* authentication modules: |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
184 |
* <blockquote><dl> |
2 | 185 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
186 |
* <dt>{@code useFirstPass}:</dt> |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
187 |
* <dd>if, true, this LoginModule retrieves the |
2 | 188 |
* username and password from the module's shared state, |
189 |
* using "javax.security.auth.login.name" and |
|
190 |
* "javax.security.auth.login.password" as the respective |
|
191 |
* keys. The retrieved values are used for authentication. |
|
192 |
* If authentication fails, no attempt for a retry |
|
193 |
* is made, and the failure is reported back to the |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
194 |
* calling application.</dd> |
2 | 195 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
196 |
* <dt>{@code tryFirstPass}:</dt> |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
197 |
* <dd>if, true, this LoginModule retrieves the |
2 | 198 |
* the username and password from the module's shared |
199 |
* state using "javax.security.auth.login.name" and |
|
200 |
* "javax.security.auth.login.password" as the respective |
|
201 |
* keys. The retrieved values are used for |
|
202 |
* authentication. |
|
203 |
* If authentication fails, the module uses the |
|
204 |
* CallbackHandler to retrieve a new username |
|
205 |
* and password, and another attempt to authenticate |
|
206 |
* is made. If the authentication fails, |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
207 |
* the failure is reported back to the calling application</dd> |
2 | 208 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
209 |
* <dt>{@code storePass}:</dt> |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
210 |
* <dd>if, true, this LoginModule stores the username and |
2 | 211 |
* password obtained from the CallbackHandler in the |
212 |
* modules shared state, using |
|
213 |
* "javax.security.auth.login.name" and |
|
214 |
* "javax.security.auth.login.password" as the respective |
|
215 |
* keys. This is not performed if existing values already |
|
216 |
* exist for the username and password in the shared |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
217 |
* state, or if authentication fails.</dd> |
2 | 218 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
219 |
* <dt>{@code clearPass}:</dt> |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
220 |
* <dd>if, true, this LoginModule clears the |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
221 |
* username and password stored in the module's shared |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
222 |
* state after both phases of authentication |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
223 |
* (login and commit) have completed.</dd> |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
224 |
* </dl></blockquote> |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
225 |
* <p>If the principal system property or key is already provided, the value of |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
226 |
* "javax.security.auth.login.name" in the shared state is ignored. |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
227 |
* <p>When multiple mechanisms to retrieve a ticket or key is provided, the |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
228 |
* preference order is: |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
229 |
* <ol> |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
230 |
* <li>ticket cache |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
231 |
* <li>keytab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
232 |
* <li>shared state |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
233 |
* <li>user prompt |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
234 |
* </ol> |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
235 |
* |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
236 |
* <p>Note that if any step fails, it will fallback to the next step. |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
237 |
* There's only one exception, if the shared state step fails and |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
238 |
* {@code useFirstPass = true}, no user prompt is made. |
2 | 239 |
* <p>Examples of some configuration values for Krb5LoginModule in |
240 |
* JAAS config file and the results are: |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
241 |
* <blockquote><dl> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
242 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
243 |
* doNotPrompt = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
244 |
* This is an illegal combination since none of {@code useTicketCache, |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
245 |
* useKeyTab, useFirstPass} and {@code tryFirstPass} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
246 |
* is set and the user can not be prompted for the password.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
247 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
248 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
249 |
* ticketCache = <filename>}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
250 |
* This is an illegal combination since {@code useTicketCache} |
2 | 251 |
* is not set to true and the ticketCache is set. A configuration error |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
252 |
* will occur.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
253 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
254 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
255 |
* renewTGT = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
256 |
* This is an illegal combination since {@code useTicketCache} is |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
257 |
* not set to true and renewTGT is set. A configuration error will occur.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
258 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
259 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
260 |
* storeKey = true useTicketCache = true doNotPrompt = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
261 |
* This is an illegal combination since {@code storeKey} is set to |
2 | 262 |
* true but the key can not be obtained either by prompting the user or from |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
263 |
* the keytab, or from the shared state. A configuration error will occur.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
264 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
265 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
266 |
* keyTab = <filename> doNotPrompt = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
267 |
* This is an illegal combination since useKeyTab is not set to true and |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
268 |
* the keyTab is set. A configuration error will occur.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
269 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
270 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
271 |
* debug = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
272 |
* Prompt the user for the principal name and the password. |
2 | 273 |
* Use the authentication exchange to get TGT from the KDC and |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
274 |
* populate the {@code Subject} with the principal and TGT. |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
275 |
* Output debug messages.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
276 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
277 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
278 |
* useTicketCache = true doNotPrompt = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
279 |
* Check the default cache for TGT and populate the {@code Subject} |
2 | 280 |
* with the principal and TGT. If the TGT is not available, |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
281 |
* do not prompt the user, instead fail the authentication.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
282 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
283 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
284 |
* principal = <name> useTicketCache = true doNotPrompt = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
285 |
* Get the TGT from the default cache for the principal and populate the |
2 | 286 |
* Subject's principal and private creds set. If ticket cache is |
287 |
* not available or does not contain the principal's TGT |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
288 |
* authentication will fail.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
289 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
290 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
291 |
* useTicketCache = true |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
292 |
* ticketCache = <file name> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
293 |
* useKeyTab = true |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
294 |
* keyTab = <keytab filename> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
295 |
* principal = <principal name> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
296 |
* doNotPrompt = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
297 |
* Search the cache for the principal's TGT. If it is not available |
2 | 298 |
* use the key in the keytab to perform authentication exchange with the |
299 |
* KDC and acquire the TGT. |
|
300 |
* The Subject will be populated with the principal and the TGT. |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
301 |
* If the key is not available or valid then authentication will fail.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
302 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
303 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
304 |
* useTicketCache = true ticketCache = <filename>}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
305 |
* The TGT will be obtained from the cache specified. |
2 | 306 |
* The Kerberos principal name used will be the principal name in |
307 |
* the Ticket cache. If the TGT is not available in the |
|
308 |
* ticket cache the user will be prompted for the principal name |
|
309 |
* and the password. The TGT will be obtained using the authentication |
|
310 |
* exchange with the KDC. |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
311 |
* The Subject will be populated with the TGT.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
312 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
313 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
314 |
* useKeyTab = true keyTab=<keytab filename> principal = <principal name> storeKey = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
315 |
* The key for the principal will be retrieved from the keytab. |
2 | 316 |
* If the key is not available in the keytab the user will be prompted |
317 |
* for the principal's password. The Subject will be populated |
|
318 |
* with the principal's key either from the keytab or derived from the |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
319 |
* password entered.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
320 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
321 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
322 |
* useKeyTab = true keyTab = <keytabname> storeKey = true doNotPrompt = false}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
323 |
* The user will be prompted for the service principal name. |
2 | 324 |
* If the principal's |
325 |
* longterm key is available in the keytab , it will be added to the |
|
326 |
* Subject's private credentials. An authentication exchange will be |
|
327 |
* attempted with the principal name and the key from the Keytab. |
|
328 |
* If successful the TGT will be added to the |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
329 |
* Subject's private credentials set. Otherwise the authentication will fail.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
330 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
331 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
332 |
* isInitiator = false useKeyTab = true keyTab = <keytabname> storeKey = true principal = *}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
333 |
* The acceptor will be an unbound acceptor and it can act as any principal |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
334 |
* as long that principal has keys in the keytab.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
335 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
336 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
337 |
* useTicketCache = true |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
338 |
* ticketCache = <file name> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
339 |
* useKeyTab = true |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
340 |
* keyTab = <file name> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
341 |
* storeKey = true |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
342 |
* principal = <principal name>}</pre> |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
343 |
* The client's TGT will be retrieved from the ticket cache and added to the |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
344 |
* {@code Subject}'s private credentials. If the TGT is not available |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
345 |
* in the ticket cache, or the TGT's client name does not match the principal |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
346 |
* name, Java will use a secret key to obtain the TGT using the authentication |
2 | 347 |
* exchange and added to the Subject's private credentials. |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
348 |
* This secret key will be first retrieved from the keytab. If the key |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
349 |
* is not available, the user will be prompted for the password. In either |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
350 |
* case, the key derived from the password will be added to the |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
351 |
* Subject's private credentials set.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
352 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
353 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
354 |
* isInitiator = false}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
355 |
* Configured to act as acceptor only, credentials are not acquired |
2 | 356 |
* via AS exchange. For acceptors only, set this value to false. |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
357 |
* For initiators, do not set this value to false.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
358 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
359 |
* <dd><pre>{@code |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
360 |
* isInitiator = true}</pre> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
361 |
* Configured to act as initiator, credentials are acquired |
2 | 362 |
* via AS exchange. For initiators, set this value to true, or leave this |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
363 |
* option unset, in which case default value (true) will be used.</dd> |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
364 |
* |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
365 |
* </dl></blockquote> |
2 | 366 |
* |
367 |
* @author Ram Marti |
|
368 |
*/ |
|
369 |
||
370 |
public class Krb5LoginModule implements LoginModule { |
|
371 |
||
372 |
// initial state |
|
373 |
private Subject subject; |
|
374 |
private CallbackHandler callbackHandler; |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
375 |
private Map<String, Object> sharedState; |
2 | 376 |
private Map<String, ?> options; |
377 |
||
378 |
// configurable option |
|
379 |
private boolean debug = false; |
|
380 |
private boolean storeKey = false; |
|
381 |
private boolean doNotPrompt = false; |
|
382 |
private boolean useTicketCache = false; |
|
383 |
private boolean useKeyTab = false; |
|
384 |
private String ticketCacheName = null; |
|
385 |
private String keyTabName = null; |
|
386 |
private String princName = null; |
|
387 |
||
388 |
private boolean useFirstPass = false; |
|
389 |
private boolean tryFirstPass = false; |
|
390 |
private boolean storePass = false; |
|
391 |
private boolean clearPass = false; |
|
392 |
private boolean refreshKrb5Config = false; |
|
393 |
private boolean renewTGT = false; |
|
394 |
||
395 |
// specify if initiator. |
|
396 |
// perform authentication exchange if initiator |
|
397 |
private boolean isInitiator = true; |
|
398 |
||
399 |
// the authentication status |
|
400 |
private boolean succeeded = false; |
|
401 |
private boolean commitSucceeded = false; |
|
402 |
private String username; |
|
9499 | 403 |
|
404 |
// Encryption keys calculated from password. Assigned when storekey == true |
|
405 |
// and useKeyTab == false (or true but not found) |
|
2 | 406 |
private EncryptionKey[] encKeys = null; |
9499 | 407 |
|
408 |
KeyTab ktab = null; |
|
409 |
||
2 | 410 |
private Credentials cred = null; |
411 |
||
412 |
private PrincipalName principal = null; |
|
413 |
private KerberosPrincipal kerbClientPrinc = null; |
|
414 |
private KerberosTicket kerbTicket = null; |
|
415 |
private KerberosKey[] kerbKeys = null; |
|
416 |
private StringBuffer krb5PrincName = null; |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
417 |
private boolean unboundServer = false; |
2 | 418 |
private char[] password = null; |
419 |
||
420 |
private static final String NAME = "javax.security.auth.login.name"; |
|
421 |
private static final String PWD = "javax.security.auth.login.password"; |
|
16503
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
422 |
private static final ResourceBundle rb = AccessController.doPrivileged( |
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
423 |
new PrivilegedAction<ResourceBundle>() { |
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
424 |
public ResourceBundle run() { |
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
425 |
return ResourceBundle.getBundle( |
36511 | 426 |
"sun.security.util.AuthResources", |
427 |
sun.security.util.ResourcesMgr.class.getModule()); |
|
16503
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
428 |
} |
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
429 |
} |
03d7a6155092
8009970: Several LoginModule classes need extra permission to load AuthResources
weijun
parents:
15649
diff
changeset
|
430 |
); |
2 | 431 |
|
432 |
/** |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
433 |
* Initialize this {@code LoginModule}. |
2 | 434 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
435 |
* @param subject the {@code Subject} to be authenticated. |
2 | 436 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
437 |
* @param callbackHandler a {@code CallbackHandler} for |
2 | 438 |
* communication with the end user (prompting for |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
439 |
* usernames and passwords, for example). |
2 | 440 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
441 |
* @param sharedState shared {@code LoginModule} state. |
2 | 442 |
* |
443 |
* @param options options specified in the login |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
444 |
* {@code Configuration} for this particular |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
445 |
* {@code LoginModule}. |
2 | 446 |
*/ |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
447 |
// Unchecked warning from (Map<String, Object>)sharedState is safe |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
448 |
// since javax.security.auth.login.LoginContext passes a raw HashMap. |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
449 |
// Unchecked warnings from options.get(String) are safe since we are |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
450 |
// passing known keys. |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
451 |
@SuppressWarnings("unchecked") |
2 | 452 |
public void initialize(Subject subject, |
453 |
CallbackHandler callbackHandler, |
|
454 |
Map<String, ?> sharedState, |
|
455 |
Map<String, ?> options) { |
|
456 |
||
457 |
this.subject = subject; |
|
458 |
this.callbackHandler = callbackHandler; |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9499
diff
changeset
|
459 |
this.sharedState = (Map<String, Object>)sharedState; |
2 | 460 |
this.options = options; |
461 |
||
462 |
// initialize any configured options |
|
463 |
||
464 |
debug = "true".equalsIgnoreCase((String)options.get("debug")); |
|
465 |
storeKey = "true".equalsIgnoreCase((String)options.get("storeKey")); |
|
466 |
doNotPrompt = "true".equalsIgnoreCase((String)options.get |
|
467 |
("doNotPrompt")); |
|
468 |
useTicketCache = "true".equalsIgnoreCase((String)options.get |
|
469 |
("useTicketCache")); |
|
470 |
useKeyTab = "true".equalsIgnoreCase((String)options.get("useKeyTab")); |
|
471 |
ticketCacheName = (String)options.get("ticketCache"); |
|
472 |
keyTabName = (String)options.get("keyTab"); |
|
13590
f7f85d7f7a82
7152121: Krb5LoginModule no longer handles keyTabNames with "file:" prefix
weijun
parents:
10695
diff
changeset
|
473 |
if (keyTabName != null) { |
f7f85d7f7a82
7152121: Krb5LoginModule no longer handles keyTabNames with "file:" prefix
weijun
parents:
10695
diff
changeset
|
474 |
keyTabName = sun.security.krb5.internal.ktab.KeyTab.normalize( |
f7f85d7f7a82
7152121: Krb5LoginModule no longer handles keyTabNames with "file:" prefix
weijun
parents:
10695
diff
changeset
|
475 |
keyTabName); |
f7f85d7f7a82
7152121: Krb5LoginModule no longer handles keyTabNames with "file:" prefix
weijun
parents:
10695
diff
changeset
|
476 |
} |
2 | 477 |
princName = (String)options.get("principal"); |
478 |
refreshKrb5Config = |
|
479 |
"true".equalsIgnoreCase((String)options.get("refreshKrb5Config")); |
|
480 |
renewTGT = |
|
481 |
"true".equalsIgnoreCase((String)options.get("renewTGT")); |
|
482 |
||
483 |
// check isInitiator value |
|
484 |
String isInitiatorValue = ((String)options.get("isInitiator")); |
|
485 |
if (isInitiatorValue == null) { |
|
486 |
// use default, if value not set |
|
487 |
} else { |
|
488 |
isInitiator = "true".equalsIgnoreCase(isInitiatorValue); |
|
489 |
} |
|
490 |
||
491 |
tryFirstPass = |
|
492 |
"true".equalsIgnoreCase |
|
493 |
((String)options.get("tryFirstPass")); |
|
494 |
useFirstPass = |
|
495 |
"true".equalsIgnoreCase |
|
496 |
((String)options.get("useFirstPass")); |
|
497 |
storePass = |
|
498 |
"true".equalsIgnoreCase((String)options.get("storePass")); |
|
499 |
clearPass = |
|
500 |
"true".equalsIgnoreCase((String)options.get("clearPass")); |
|
501 |
if (debug) { |
|
502 |
System.out.print("Debug is " + debug |
|
503 |
+ " storeKey " + storeKey |
|
504 |
+ " useTicketCache " + useTicketCache |
|
505 |
+ " useKeyTab " + useKeyTab |
|
506 |
+ " doNotPrompt " + doNotPrompt |
|
507 |
+ " ticketCache is " + ticketCacheName |
|
508 |
+ " isInitiator " + isInitiator |
|
509 |
+ " KeyTab is " + keyTabName |
|
510 |
+ " refreshKrb5Config is " + refreshKrb5Config |
|
511 |
+ " principal is " + princName |
|
512 |
+ " tryFirstPass is " + tryFirstPass |
|
513 |
+ " useFirstPass is " + useFirstPass |
|
514 |
+ " storePass is " + storePass |
|
515 |
+ " clearPass is " + clearPass + "\n"); |
|
516 |
} |
|
517 |
} |
|
518 |
||
519 |
||
520 |
/** |
|
521 |
* Authenticate the user |
|
522 |
* |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
523 |
* @return true in all cases since this {@code LoginModule} |
2 | 524 |
* should not be ignored. |
525 |
* |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
526 |
* @exception FailedLoginException if the authentication fails. |
2 | 527 |
* |
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
528 |
* @exception LoginException if this {@code LoginModule} |
2 | 529 |
* is unable to perform the authentication. |
530 |
*/ |
|
531 |
public boolean login() throws LoginException { |
|
532 |
||
533 |
if (refreshKrb5Config) { |
|
534 |
try { |
|
535 |
if (debug) { |
|
536 |
System.out.println("Refreshing Kerberos configuration"); |
|
537 |
} |
|
538 |
sun.security.krb5.Config.refresh(); |
|
539 |
} catch (KrbException ke) { |
|
540 |
LoginException le = new LoginException(ke.getMessage()); |
|
541 |
le.initCause(ke); |
|
542 |
throw le; |
|
543 |
} |
|
544 |
} |
|
545 |
String principalProperty = System.getProperty |
|
546 |
("sun.security.krb5.principal"); |
|
547 |
if (principalProperty != null) { |
|
548 |
krb5PrincName = new StringBuffer(principalProperty); |
|
549 |
} else { |
|
550 |
if (princName != null) { |
|
551 |
krb5PrincName = new StringBuffer(princName); |
|
552 |
} |
|
553 |
} |
|
554 |
||
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
555 |
validateConfiguration(); |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
556 |
|
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
557 |
if (krb5PrincName != null && krb5PrincName.toString().equals("*")) { |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
558 |
unboundServer = true; |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
559 |
} |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
560 |
|
2 | 561 |
if (tryFirstPass) { |
562 |
try { |
|
563 |
attemptAuthentication(true); |
|
564 |
if (debug) |
|
565 |
System.out.println("\t\t[Krb5LoginModule] " + |
|
566 |
"authentication succeeded"); |
|
567 |
succeeded = true; |
|
568 |
cleanState(); |
|
569 |
return true; |
|
570 |
} catch (LoginException le) { |
|
571 |
// authentication failed -- try again below by prompting |
|
572 |
cleanState(); |
|
573 |
if (debug) { |
|
574 |
System.out.println("\t\t[Krb5LoginModule] " + |
|
575 |
"tryFirstPass failed with:" + |
|
576 |
le.getMessage()); |
|
577 |
} |
|
578 |
} |
|
579 |
} else if (useFirstPass) { |
|
580 |
try { |
|
581 |
attemptAuthentication(true); |
|
582 |
succeeded = true; |
|
583 |
cleanState(); |
|
584 |
return true; |
|
585 |
} catch (LoginException e) { |
|
586 |
// authentication failed -- clean out state |
|
587 |
if (debug) { |
|
588 |
System.out.println("\t\t[Krb5LoginModule] " + |
|
589 |
"authentication failed \n" + |
|
590 |
e.getMessage()); |
|
591 |
} |
|
592 |
succeeded = false; |
|
593 |
cleanState(); |
|
594 |
throw e; |
|
595 |
} |
|
596 |
} |
|
597 |
||
598 |
// attempt the authentication by getting the username and pwd |
|
599 |
// by prompting or configuration i.e. not from shared state |
|
600 |
||
601 |
try { |
|
602 |
attemptAuthentication(false); |
|
603 |
succeeded = true; |
|
604 |
cleanState(); |
|
605 |
return true; |
|
606 |
} catch (LoginException e) { |
|
607 |
// authentication failed -- clean out state |
|
608 |
if (debug) { |
|
609 |
System.out.println("\t\t[Krb5LoginModule] " + |
|
610 |
"authentication failed \n" + |
|
611 |
e.getMessage()); |
|
612 |
} |
|
613 |
succeeded = false; |
|
614 |
cleanState(); |
|
615 |
throw e; |
|
616 |
} |
|
617 |
} |
|
618 |
/** |
|
619 |
* process the configuration options |
|
620 |
* Get the TGT either out of |
|
621 |
* cache or from the KDC using the password entered |
|
622 |
* Check the permission before getting the TGT |
|
623 |
*/ |
|
624 |
||
625 |
private void attemptAuthentication(boolean getPasswdFromSharedState) |
|
626 |
throws LoginException { |
|
627 |
||
628 |
/* |
|
629 |
* Check the creds cache to see whether |
|
630 |
* we have TGT for this client principal |
|
631 |
*/ |
|
632 |
if (krb5PrincName != null) { |
|
633 |
try { |
|
634 |
principal = new PrincipalName |
|
635 |
(krb5PrincName.toString(), |
|
636 |
PrincipalName.KRB_NT_PRINCIPAL); |
|
637 |
} catch (KrbException e) { |
|
638 |
LoginException le = new LoginException(e.getMessage()); |
|
639 |
le.initCause(e); |
|
640 |
throw le; |
|
641 |
} |
|
642 |
} |
|
643 |
||
644 |
try { |
|
645 |
if (useTicketCache) { |
|
646 |
// ticketCacheName == null implies the default cache |
|
647 |
if (debug) |
|
648 |
System.out.println("Acquire TGT from Cache"); |
|
649 |
cred = Credentials.acquireTGTFromCache |
|
650 |
(principal, ticketCacheName); |
|
651 |
||
652 |
if (cred != null) { |
|
31643
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
653 |
if (renewTGT && isOld(cred)) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
654 |
// renew if ticket is old. |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
655 |
Credentials newCred = renewCredentials(cred); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
656 |
if (newCred != null) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
657 |
cred = newCred; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
658 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
659 |
} |
2 | 660 |
if (!isCurrent(cred)) { |
31643
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
661 |
// credentials have expired |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
662 |
cred = null; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
663 |
if (debug) |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
664 |
System.out.println("Credentials are" + |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
665 |
" no longer valid"); |
2 | 666 |
} |
667 |
} |
|
668 |
||
669 |
if (cred != null) { |
|
670 |
// get the principal name from the ticket cache |
|
671 |
if (principal == null) { |
|
672 |
principal = cred.getClient(); |
|
673 |
} |
|
674 |
} |
|
675 |
if (debug) { |
|
676 |
System.out.println("Principal is " + principal); |
|
677 |
if (cred == null) { |
|
678 |
System.out.println |
|
679 |
("null credentials from Ticket Cache"); |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
||
684 |
// cred = null indicates that we didn't get the creds |
|
685 |
// from the cache or useTicketCache was false |
|
686 |
||
687 |
if (cred == null) { |
|
688 |
// We need the principal name whether we use keytab |
|
689 |
// or AS Exchange |
|
690 |
if (principal == null) { |
|
691 |
promptForName(getPasswdFromSharedState); |
|
692 |
principal = new PrincipalName |
|
693 |
(krb5PrincName.toString(), |
|
694 |
PrincipalName.KRB_NT_PRINCIPAL); |
|
695 |
} |
|
9499 | 696 |
|
697 |
/* |
|
698 |
* Before dynamic KeyTab support (6894072), here we check if |
|
699 |
* the keytab contains keys for the principal. If no, keytab |
|
700 |
* will not be used and password is prompted for. |
|
701 |
* |
|
702 |
* After 6894072, we normally don't check it, and expect the |
|
703 |
* keys can be populated until a real connection is made. The |
|
704 |
* check is still done when isInitiator == true, where the keys |
|
705 |
* will be used right now. |
|
706 |
* |
|
707 |
* Probably tricky relations: |
|
708 |
* |
|
709 |
* useKeyTab is config flag, but when it's true but the ktab |
|
710 |
* does not contains keys for principal, we would use password |
|
711 |
* and keep the flag unchanged (for reuse?). In this method, |
|
712 |
* we use (ktab != null) to check whether keytab is used. |
|
713 |
* After this method (and when storeKey == true), we use |
|
714 |
* (encKeys == null) to check. |
|
715 |
*/ |
|
2 | 716 |
if (useKeyTab) { |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
717 |
if (!unboundServer) { |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
718 |
KerberosPrincipal kp = |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
719 |
new KerberosPrincipal(principal.getName()); |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
720 |
ktab = (keyTabName == null) |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
721 |
? KeyTab.getInstance(kp) |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
722 |
: KeyTab.getInstance(kp, new File(keyTabName)); |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
723 |
} else { |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
724 |
ktab = (keyTabName == null) |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
725 |
? KeyTab.getUnboundInstance() |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
726 |
: KeyTab.getUnboundInstance(new File(keyTabName)); |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
727 |
} |
9499 | 728 |
if (isInitiator) { |
729 |
if (Krb5Util.keysFromJavaxKeyTab(ktab, principal).length |
|
730 |
== 0) { |
|
731 |
ktab = null; |
|
732 |
if (debug) { |
|
733 |
System.out.println |
|
734 |
("Key for the principal " + |
|
735 |
principal + |
|
736 |
" not available in " + |
|
737 |
((keyTabName == null) ? |
|
738 |
"default key tab" : keyTabName)); |
|
739 |
} |
|
740 |
} |
|
2 | 741 |
} |
742 |
} |
|
7183 | 743 |
|
744 |
KrbAsReqBuilder builder; |
|
9499 | 745 |
|
746 |
if (ktab == null) { |
|
2 | 747 |
promptForPass(getPasswdFromSharedState); |
7183 | 748 |
builder = new KrbAsReqBuilder(principal, password); |
2 | 749 |
if (isInitiator) { |
7183 | 750 |
// XXX Even if isInitiator=false, it might be |
751 |
// better to do an AS-REQ so that keys can be |
|
752 |
// updated with PA info |
|
753 |
cred = builder.action().getCreds(); |
|
2 | 754 |
} |
9499 | 755 |
if (storeKey) { |
10695
08c28770f82b
7089889: Krb5LoginModule.login() throws an exception if used without a keytab
weijun
parents:
10336
diff
changeset
|
756 |
encKeys = builder.getKeys(isInitiator); |
9499 | 757 |
// When encKeys is empty, the login actually fails. |
758 |
// For compatibility, exception is thrown in commit(). |
|
759 |
} |
|
2 | 760 |
} else { |
9499 | 761 |
builder = new KrbAsReqBuilder(principal, ktab); |
2 | 762 |
if (isInitiator) { |
7183 | 763 |
cred = builder.action().getCreds(); |
2 | 764 |
} |
765 |
} |
|
7183 | 766 |
builder.destroy(); |
2 | 767 |
|
768 |
if (debug) { |
|
769 |
System.out.println("principal is " + principal); |
|
770 |
HexDumpEncoder hd = new HexDumpEncoder(); |
|
9499 | 771 |
if (ktab != null) { |
772 |
System.out.println("Will use keytab"); |
|
773 |
} else if (storeKey) { |
|
774 |
for (int i = 0; i < encKeys.length; i++) { |
|
775 |
System.out.println("EncryptionKey: keyType=" + |
|
776 |
encKeys[i].getEType() + |
|
777 |
" keyBytes (hex dump)=" + |
|
778 |
hd.encodeBuffer(encKeys[i].getBytes())); |
|
779 |
} |
|
2 | 780 |
} |
781 |
} |
|
782 |
||
783 |
// we should hava a non-null cred |
|
784 |
if (isInitiator && (cred == null)) { |
|
785 |
throw new LoginException |
|
786 |
("TGT Can not be obtained from the KDC "); |
|
787 |
} |
|
788 |
||
789 |
} |
|
790 |
} catch (KrbException e) { |
|
791 |
LoginException le = new LoginException(e.getMessage()); |
|
792 |
le.initCause(e); |
|
793 |
throw le; |
|
794 |
} catch (IOException ioe) { |
|
795 |
LoginException ie = new LoginException(ioe.getMessage()); |
|
796 |
ie.initCause(ioe); |
|
797 |
throw ie; |
|
798 |
} |
|
799 |
} |
|
800 |
||
801 |
private void promptForName(boolean getPasswdFromSharedState) |
|
802 |
throws LoginException { |
|
803 |
krb5PrincName = new StringBuffer(""); |
|
804 |
if (getPasswdFromSharedState) { |
|
805 |
// use the name saved by the first module in the stack |
|
806 |
username = (String)sharedState.get(NAME); |
|
807 |
if (debug) { |
|
808 |
System.out.println |
|
809 |
("username from shared state is " + username + "\n"); |
|
810 |
} |
|
811 |
if (username == null) { |
|
812 |
System.out.println |
|
813 |
("username from shared state is null\n"); |
|
814 |
throw new LoginException |
|
815 |
("Username can not be obtained from sharedstate "); |
|
816 |
} |
|
817 |
if (debug) { |
|
818 |
System.out.println |
|
819 |
("username from shared state is " + username + "\n"); |
|
820 |
} |
|
821 |
if (username != null && username.length() > 0) { |
|
822 |
krb5PrincName.insert(0, username); |
|
823 |
return; |
|
824 |
} |
|
825 |
} |
|
826 |
||
827 |
if (doNotPrompt) { |
|
828 |
throw new LoginException |
|
14199
ed2d2261dfbc
8001204: typo: Unable to obtain Princpal Name for authentication
weijun
parents:
14030
diff
changeset
|
829 |
("Unable to obtain Principal Name for authentication "); |
2 | 830 |
} else { |
831 |
if (callbackHandler == null) |
|
832 |
throw new LoginException("No CallbackHandler " |
|
833 |
+ "available " |
|
834 |
+ "to garner authentication " |
|
835 |
+ "information from the user"); |
|
836 |
try { |
|
837 |
String defUsername = System.getProperty("user.name"); |
|
838 |
||
839 |
Callback[] callbacks = new Callback[1]; |
|
840 |
MessageFormat form = new MessageFormat( |
|
841 |
rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
842 |
"Kerberos.username.defUsername.")); |
2 | 843 |
Object[] source = {defUsername}; |
844 |
callbacks[0] = new NameCallback(form.format(source)); |
|
845 |
callbackHandler.handle(callbacks); |
|
846 |
username = ((NameCallback)callbacks[0]).getName(); |
|
847 |
if (username == null || username.length() == 0) |
|
848 |
username = defUsername; |
|
849 |
krb5PrincName.insert(0, username); |
|
850 |
||
851 |
} catch (java.io.IOException ioe) { |
|
852 |
throw new LoginException(ioe.getMessage()); |
|
853 |
} catch (UnsupportedCallbackException uce) { |
|
854 |
throw new LoginException |
|
855 |
(uce.getMessage() |
|
856 |
+" not available to garner " |
|
857 |
+" authentication information " |
|
858 |
+" from the user"); |
|
859 |
} |
|
860 |
} |
|
861 |
} |
|
862 |
||
863 |
private void promptForPass(boolean getPasswdFromSharedState) |
|
864 |
throws LoginException { |
|
865 |
||
866 |
if (getPasswdFromSharedState) { |
|
867 |
// use the password saved by the first module in the stack |
|
868 |
password = (char[])sharedState.get(PWD); |
|
869 |
if (password == null) { |
|
870 |
if (debug) { |
|
871 |
System.out.println |
|
872 |
("Password from shared state is null"); |
|
873 |
} |
|
874 |
throw new LoginException |
|
875 |
("Password can not be obtained from sharedstate "); |
|
876 |
} |
|
877 |
if (debug) { |
|
878 |
System.out.println |
|
879 |
("password is " + new String(password)); |
|
880 |
} |
|
881 |
return; |
|
882 |
} |
|
883 |
if (doNotPrompt) { |
|
884 |
throw new LoginException |
|
885 |
("Unable to obtain password from user\n"); |
|
886 |
} else { |
|
887 |
if (callbackHandler == null) |
|
888 |
throw new LoginException("No CallbackHandler " |
|
889 |
+ "available " |
|
890 |
+ "to garner authentication " |
|
891 |
+ "information from the user"); |
|
892 |
try { |
|
893 |
Callback[] callbacks = new Callback[1]; |
|
894 |
String userName = krb5PrincName.toString(); |
|
895 |
MessageFormat form = new MessageFormat( |
|
896 |
rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
897 |
"Kerberos.password.for.username.")); |
2 | 898 |
Object[] source = {userName}; |
899 |
callbacks[0] = new PasswordCallback( |
|
900 |
form.format(source), |
|
901 |
false); |
|
902 |
callbackHandler.handle(callbacks); |
|
903 |
char[] tmpPassword = ((PasswordCallback) |
|
904 |
callbacks[0]).getPassword(); |
|
905 |
if (tmpPassword == null) { |
|
21961
50019af27ca3
8028351: JWS doesn't get authenticated when using kerberos auth proxy
weijun
parents:
20742
diff
changeset
|
906 |
throw new LoginException("No password provided"); |
2 | 907 |
} |
908 |
password = new char[tmpPassword.length]; |
|
909 |
System.arraycopy(tmpPassword, 0, |
|
910 |
password, 0, tmpPassword.length); |
|
911 |
((PasswordCallback)callbacks[0]).clearPassword(); |
|
912 |
||
913 |
||
914 |
// clear tmpPassword |
|
915 |
for (int i = 0; i < tmpPassword.length; i++) |
|
916 |
tmpPassword[i] = ' '; |
|
917 |
tmpPassword = null; |
|
918 |
if (debug) { |
|
919 |
System.out.println("\t\t[Krb5LoginModule] " + |
|
920 |
"user entered username: " + |
|
921 |
krb5PrincName); |
|
922 |
System.out.println(); |
|
923 |
} |
|
924 |
} catch (java.io.IOException ioe) { |
|
925 |
throw new LoginException(ioe.getMessage()); |
|
926 |
} catch (UnsupportedCallbackException uce) { |
|
927 |
throw new LoginException(uce.getMessage() |
|
928 |
+" not available to garner " |
|
929 |
+" authentication information " |
|
930 |
+ "from the user"); |
|
931 |
} |
|
932 |
} |
|
933 |
} |
|
934 |
||
935 |
private void validateConfiguration() throws LoginException { |
|
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
936 |
if (doNotPrompt && !useTicketCache && !useKeyTab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
937 |
&& !tryFirstPass && !useFirstPass) |
2 | 938 |
throw new LoginException |
939 |
("Configuration Error" |
|
940 |
+ " - either doNotPrompt should be " |
|
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
941 |
+ " false or at least one of useTicketCache, " |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
942 |
+ " useKeyTab, tryFirstPass and useFirstPass" |
2 | 943 |
+ " should be true"); |
944 |
if (ticketCacheName != null && !useTicketCache) |
|
945 |
throw new LoginException |
|
946 |
("Configuration Error " |
|
947 |
+ " - useTicketCache should be set " |
|
948 |
+ "to true to use the ticket cache" |
|
949 |
+ ticketCacheName); |
|
950 |
if (keyTabName != null & !useKeyTab) |
|
951 |
throw new LoginException |
|
952 |
("Configuration Error - useKeyTab should be set to true " |
|
953 |
+ "to use the keytab" + keyTabName); |
|
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
954 |
if (storeKey && doNotPrompt && !useKeyTab |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
955 |
&& !tryFirstPass && !useFirstPass) |
2 | 956 |
throw new LoginException |
1575
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
957 |
("Configuration Error - either doNotPrompt should be set to " |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
958 |
+ " false or at least one of tryFirstPass, useFirstPass " |
e0f1979051b5
6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents:
793
diff
changeset
|
959 |
+ "or useKeyTab must be set to true for storeKey option"); |
2 | 960 |
if (renewTGT && !useTicketCache) |
961 |
throw new LoginException |
|
962 |
("Configuration Error" |
|
963 |
+ " - either useTicketCache should be " |
|
964 |
+ " true or renewTGT should be false"); |
|
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
965 |
if (krb5PrincName != null && krb5PrincName.toString().equals("*")) { |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
966 |
if (isInitiator) { |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
967 |
throw new LoginException |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
968 |
("Configuration Error" |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
969 |
+ " - principal cannot be * when isInitiator is true"); |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
970 |
} |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
971 |
} |
2 | 972 |
} |
973 |
||
31643
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
974 |
private static boolean isCurrent(Credentials creds) |
2 | 975 |
{ |
976 |
Date endTime = creds.getEndTime(); |
|
977 |
if (endTime != null) { |
|
978 |
return (System.currentTimeMillis() <= endTime.getTime()); |
|
979 |
} |
|
980 |
return true; |
|
981 |
} |
|
982 |
||
31643
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
983 |
private static boolean isOld(Credentials creds) |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
984 |
{ |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
985 |
Date endTime = creds.getEndTime(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
986 |
if (endTime != null) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
987 |
Date authTime = creds.getAuthTime(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
988 |
long now = System.currentTimeMillis(); |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
989 |
if (authTime != null) { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
990 |
// pass the mid between auth and end |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
991 |
return now - authTime.getTime() > endTime.getTime() - now; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
992 |
} else { |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
993 |
// will expire in less than 2 hours |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
994 |
return now <= endTime.getTime() - 1000*3600*2L; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
995 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
996 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
997 |
return false; |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
998 |
} |
abad00f2c027
8058290: JAAS Krb5LoginModule has suspect ticket-renewal logic, relies on clockskew grace
weijun
parents:
30044
diff
changeset
|
999 |
|
2 | 1000 |
private Credentials renewCredentials(Credentials creds) |
1001 |
{ |
|
1002 |
Credentials lcreds; |
|
1003 |
try { |
|
1004 |
if (!creds.isRenewable()) |
|
1005 |
throw new RefreshFailedException("This ticket" + |
|
1006 |
" is not renewable"); |
|
1007 |
if (System.currentTimeMillis() > cred.getRenewTill().getTime()) |
|
1008 |
throw new RefreshFailedException("This ticket is past " |
|
1009 |
+ "its last renewal time."); |
|
1010 |
lcreds = creds.renew(); |
|
1011 |
if (debug) |
|
1012 |
System.out.println("Renewed Kerberos Ticket"); |
|
1013 |
} catch (Exception e) { |
|
1014 |
lcreds = null; |
|
1015 |
if (debug) |
|
1016 |
System.out.println("Ticket could not be renewed : " |
|
1017 |
+ e.getMessage()); |
|
1018 |
} |
|
1019 |
return lcreds; |
|
1020 |
} |
|
1021 |
||
1022 |
/** |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1023 |
* This method is called if the LoginContext's |
2 | 1024 |
* overall authentication succeeded |
1025 |
* (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL |
|
1026 |
* LoginModules succeeded). |
|
1027 |
* |
|
1028 |
* <p> If this LoginModule's own authentication attempt |
|
1029 |
* succeeded (checked by retrieving the private state saved by the |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1030 |
* {@code login} method), then this method associates a |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1031 |
* {@code Krb5Principal} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1032 |
* with the {@code Subject} located in the |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1033 |
* {@code LoginModule}. It adds Kerberos Credentials to the |
2 | 1034 |
* the Subject's private credentials set. If this LoginModule's own |
1035 |
* authentication attempted failed, then this method removes |
|
1036 |
* any state that was originally saved. |
|
1037 |
* |
|
1038 |
* @exception LoginException if the commit fails. |
|
1039 |
* |
|
1040 |
* @return true if this LoginModule's own login and commit |
|
1041 |
* attempts succeeded, or false otherwise. |
|
1042 |
*/ |
|
1043 |
||
1044 |
public boolean commit() throws LoginException { |
|
1045 |
||
1046 |
/* |
|
1047 |
* Let us add the Krb5 Creds to the Subject's |
|
1048 |
* private credentials. The credentials are of type |
|
1049 |
* KerberosKey or KerberosTicket |
|
1050 |
*/ |
|
1051 |
if (succeeded == false) { |
|
1052 |
return false; |
|
1053 |
} else { |
|
1054 |
||
1055 |
if (isInitiator && (cred == null)) { |
|
1056 |
succeeded = false; |
|
1057 |
throw new LoginException("Null Client Credential"); |
|
1058 |
} |
|
1059 |
||
1060 |
if (subject.isReadOnly()) { |
|
1061 |
cleanKerberosCred(); |
|
1062 |
throw new LoginException("Subject is Readonly"); |
|
1063 |
} |
|
1064 |
||
1065 |
/* |
|
1066 |
* Add the Principal (authenticated identity) |
|
1067 |
* to the Subject's principal set and |
|
1068 |
* add the credentials (TGT or Service key) to the |
|
1069 |
* Subject's private credentials |
|
1070 |
*/ |
|
1071 |
||
1072 |
Set<Object> privCredSet = subject.getPrivateCredentials(); |
|
1073 |
Set<java.security.Principal> princSet = subject.getPrincipals(); |
|
1074 |
kerbClientPrinc = new KerberosPrincipal(principal.getName()); |
|
1075 |
||
1076 |
// create Kerberos Ticket |
|
1077 |
if (isInitiator) { |
|
1078 |
kerbTicket = Krb5Util.credsToTicket(cred); |
|
1079 |
} |
|
1080 |
||
9499 | 1081 |
if (storeKey && encKeys != null) { |
1082 |
if (encKeys.length == 0) { |
|
2 | 1083 |
succeeded = false; |
1084 |
throw new LoginException("Null Server Key "); |
|
1085 |
} |
|
1086 |
||
1087 |
kerbKeys = new KerberosKey[encKeys.length]; |
|
1088 |
for (int i = 0; i < encKeys.length; i ++) { |
|
1089 |
Integer temp = encKeys[i].getKeyVersionNumber(); |
|
1090 |
kerbKeys[i] = new KerberosKey(kerbClientPrinc, |
|
1091 |
encKeys[i].getBytes(), |
|
1092 |
encKeys[i].getEType(), |
|
1093 |
(temp == null? |
|
1094 |
0: temp.intValue())); |
|
1095 |
} |
|
1096 |
||
1097 |
} |
|
9499 | 1098 |
// Let us add the kerbClientPrinc,kerbTicket and KeyTab/KerbKey (if |
2 | 1099 |
// storeKey is true) |
15649
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
1100 |
|
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
1101 |
// We won't add "*" as a KerberosPrincipal |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
1102 |
if (!unboundServer && |
f6bd3d34f844
8001104: Unbound SASL service: the GSSAPI/krb5 mech
weijun
parents:
14769
diff
changeset
|
1103 |
!princSet.contains(kerbClientPrinc)) { |
2 | 1104 |
princSet.add(kerbClientPrinc); |
9499 | 1105 |
} |
2 | 1106 |
|
1107 |
// add the TGT |
|
1108 |
if (kerbTicket != null) { |
|
1109 |
if (!privCredSet.contains(kerbTicket)) |
|
1110 |
privCredSet.add(kerbTicket); |
|
1111 |
} |
|
1112 |
||
1113 |
if (storeKey) { |
|
9499 | 1114 |
if (encKeys == null) { |
14030
8dc91f5c3d67
7201053: Krb5LoginModule shows NPE when both useTicketCache and storeKey are set to true
weijun
parents:
13590
diff
changeset
|
1115 |
if (ktab != null) { |
8dc91f5c3d67
7201053: Krb5LoginModule shows NPE when both useTicketCache and storeKey are set to true
weijun
parents:
13590
diff
changeset
|
1116 |
if (!privCredSet.contains(ktab)) { |
8dc91f5c3d67
7201053: Krb5LoginModule shows NPE when both useTicketCache and storeKey are set to true
weijun
parents:
13590
diff
changeset
|
1117 |
privCredSet.add(ktab); |
9499 | 1118 |
} |
14030
8dc91f5c3d67
7201053: Krb5LoginModule shows NPE when both useTicketCache and storeKey are set to true
weijun
parents:
13590
diff
changeset
|
1119 |
} else { |
8dc91f5c3d67
7201053: Krb5LoginModule shows NPE when both useTicketCache and storeKey are set to true
weijun
parents:
13590
diff
changeset
|
1120 |
succeeded = false; |
8dc91f5c3d67
7201053: Krb5LoginModule shows NPE when both useTicketCache and storeKey are set to true
weijun
parents:
13590
diff
changeset
|
1121 |
throw new LoginException("No key to store"); |
2 | 1122 |
} |
9499 | 1123 |
} else { |
1124 |
for (int i = 0; i < kerbKeys.length; i ++) { |
|
1125 |
if (!privCredSet.contains(kerbKeys[i])) { |
|
1126 |
privCredSet.add(kerbKeys[i]); |
|
1127 |
} |
|
1128 |
encKeys[i].destroy(); |
|
1129 |
encKeys[i] = null; |
|
1130 |
if (debug) { |
|
1131 |
System.out.println("Added server's key" |
|
1132 |
+ kerbKeys[i]); |
|
1133 |
System.out.println("\t\t[Krb5LoginModule] " + |
|
1134 |
"added Krb5Principal " + |
|
1135 |
kerbClientPrinc.toString() |
|
1136 |
+ " to Subject"); |
|
1137 |
} |
|
2 | 1138 |
} |
1139 |
} |
|
1140 |
} |
|
1141 |
} |
|
1142 |
commitSucceeded = true; |
|
1143 |
if (debug) |
|
1144 |
System.out.println("Commit Succeeded \n"); |
|
1145 |
return true; |
|
1146 |
} |
|
1147 |
||
1148 |
/** |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1149 |
* This method is called if the LoginContext's |
2 | 1150 |
* overall authentication failed. |
1151 |
* (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL |
|
1152 |
* LoginModules did not succeed). |
|
1153 |
* |
|
1154 |
* <p> If this LoginModule's own authentication attempt |
|
1155 |
* succeeded (checked by retrieving the private state saved by the |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1156 |
* {@code login} and {@code commit} methods), |
2 | 1157 |
* then this method cleans up any state that was originally saved. |
1158 |
* |
|
1159 |
* @exception LoginException if the abort fails. |
|
1160 |
* |
|
1161 |
* @return false if this LoginModule's own login and/or commit attempts |
|
1162 |
* failed, and true otherwise. |
|
1163 |
*/ |
|
1164 |
||
1165 |
public boolean abort() throws LoginException { |
|
1166 |
if (succeeded == false) { |
|
1167 |
return false; |
|
1168 |
} else if (succeeded == true && commitSucceeded == false) { |
|
1169 |
// login succeeded but overall authentication failed |
|
1170 |
succeeded = false; |
|
1171 |
cleanKerberosCred(); |
|
1172 |
} else { |
|
1173 |
// overall authentication succeeded and commit succeeded, |
|
1174 |
// but someone else's commit failed |
|
1175 |
logout(); |
|
1176 |
} |
|
1177 |
return true; |
|
1178 |
} |
|
1179 |
||
1180 |
/** |
|
1181 |
* Logout the user. |
|
1182 |
* |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1183 |
* <p> This method removes the {@code Krb5Principal} |
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1184 |
* that was added by the {@code commit} method. |
2 | 1185 |
* |
1186 |
* @exception LoginException if the logout fails. |
|
1187 |
* |
|
30044
bab15bbe2ca3
8078528: clean out tidy warnings from security.auth
avstepan
parents:
25859
diff
changeset
|
1188 |
* @return true in all cases since this {@code LoginModule} |
2 | 1189 |
* should not be ignored. |
1190 |
*/ |
|
1191 |
public boolean logout() throws LoginException { |
|
1192 |
||
1193 |
if (debug) { |
|
1194 |
System.out.println("\t\t[Krb5LoginModule]: " + |
|
1195 |
"Entering logout"); |
|
1196 |
} |
|
1197 |
||
1198 |
if (subject.isReadOnly()) { |
|
1199 |
cleanKerberosCred(); |
|
1200 |
throw new LoginException("Subject is Readonly"); |
|
1201 |
} |
|
1202 |
||
1203 |
subject.getPrincipals().remove(kerbClientPrinc); |
|
1204 |
// Let us remove all Kerberos credentials stored in the Subject |
|
1205 |
Iterator<Object> it = subject.getPrivateCredentials().iterator(); |
|
1206 |
while (it.hasNext()) { |
|
1207 |
Object o = it.next(); |
|
1208 |
if (o instanceof KerberosTicket || |
|
9499 | 1209 |
o instanceof KerberosKey || |
1210 |
o instanceof KeyTab) { |
|
2 | 1211 |
it.remove(); |
1212 |
} |
|
1213 |
} |
|
1214 |
// clean the kerberos ticket and keys |
|
1215 |
cleanKerberosCred(); |
|
1216 |
||
1217 |
succeeded = false; |
|
1218 |
commitSucceeded = false; |
|
1219 |
if (debug) { |
|
1220 |
System.out.println("\t\t[Krb5LoginModule]: " + |
|
1221 |
"logged out Subject"); |
|
1222 |
} |
|
1223 |
return true; |
|
1224 |
} |
|
1225 |
||
1226 |
/** |
|
1227 |
* Clean Kerberos credentials |
|
1228 |
*/ |
|
1229 |
private void cleanKerberosCred() throws LoginException { |
|
1230 |
// Clean the ticket and server key |
|
1231 |
try { |
|
1232 |
if (kerbTicket != null) |
|
1233 |
kerbTicket.destroy(); |
|
1234 |
if (kerbKeys != null) { |
|
1235 |
for (int i = 0; i < kerbKeys.length; i++) { |
|
1236 |
kerbKeys[i].destroy(); |
|
1237 |
} |
|
1238 |
} |
|
1239 |
} catch (DestroyFailedException e) { |
|
1240 |
throw new LoginException |
|
1241 |
("Destroy Failed on Kerberos Private Credentials"); |
|
1242 |
} |
|
1243 |
kerbTicket = null; |
|
1244 |
kerbKeys = null; |
|
1245 |
kerbClientPrinc = null; |
|
1246 |
} |
|
1247 |
||
1248 |
/** |
|
1249 |
* Clean out the state |
|
1250 |
*/ |
|
1251 |
private void cleanState() { |
|
1252 |
||
1253 |
// save input as shared state only if |
|
1254 |
// authentication succeeded |
|
1255 |
if (succeeded) { |
|
1256 |
if (storePass && |
|
1257 |
!sharedState.containsKey(NAME) && |
|
1258 |
!sharedState.containsKey(PWD)) { |
|
1259 |
sharedState.put(NAME, username); |
|
1260 |
sharedState.put(PWD, password); |
|
1261 |
} |
|
793
8183c2b0985f
6716534: Krb5LoginModule has not cleaned temp info between authentication attempts
weijun
parents:
2
diff
changeset
|
1262 |
} else { |
8183c2b0985f
6716534: Krb5LoginModule has not cleaned temp info between authentication attempts
weijun
parents:
2
diff
changeset
|
1263 |
// remove temp results for the next try |
8183c2b0985f
6716534: Krb5LoginModule has not cleaned temp info between authentication attempts
weijun
parents:
2
diff
changeset
|
1264 |
encKeys = null; |
9499 | 1265 |
ktab = null; |
793
8183c2b0985f
6716534: Krb5LoginModule has not cleaned temp info between authentication attempts
weijun
parents:
2
diff
changeset
|
1266 |
principal = null; |
2 | 1267 |
} |
1268 |
username = null; |
|
1269 |
password = null; |
|
1270 |
if (krb5PrincName != null && krb5PrincName.length() != 0) |
|
1271 |
krb5PrincName.delete(0, krb5PrincName.length()); |
|
1272 |
krb5PrincName = null; |
|
1273 |
if (clearPass) { |
|
1274 |
sharedState.remove(NAME); |
|
1275 |
sharedState.remove(PWD); |
|
1276 |
} |
|
1277 |
} |
|
1278 |
} |