author | sundar |
Mon, 31 Aug 2015 17:51:02 +0530 | |
changeset 32434 | 769b3d81ae69 |
parent 26630 | 7973c5ab32da |
child 34894 | 3248b89d1921 |
permissions | -rw-r--r-- |
3482 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20742
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
3482 | 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 |
3482 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3482 | 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. |
|
3482 | 24 |
*/ |
25 |
||
26 |
package com.sun.security.jgss; |
|
27 |
||
28 |
import org.ietf.jgss.*; |
|
26629
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
29 |
import sun.security.jgss.GSSContextImpl; |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
30 |
import sun.security.krb5.internal.AuthorizationData; |
3482 | 31 |
|
32 |
/** |
|
33 |
* The extended GSSContext interface for supporting additional |
|
34 |
* functionalities not defined by {@code org.ietf.jgss.GSSContext}, |
|
35 |
* such as querying context-specific attributes. |
|
36 |
*/ |
|
20742
4ae78e8060d6
8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents:
5506
diff
changeset
|
37 |
@jdk.Exported |
3482 | 38 |
public interface ExtendedGSSContext extends GSSContext { |
26629
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
39 |
|
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
40 |
// The impl is almost identical to GSSContextImpl with only 2 differences: |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
41 |
// 1. It implements the extended interface |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
42 |
// 2. It translates result to data types here in inquireSecContext |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
43 |
static class ExtendedGSSContextImpl extends GSSContextImpl |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
44 |
implements ExtendedGSSContext { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
45 |
|
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
46 |
public ExtendedGSSContextImpl(GSSContextImpl old) { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
47 |
super(old); |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
48 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
49 |
|
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
50 |
@Override |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
51 |
public Object inquireSecContext(InquireType type) throws GSSException { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
52 |
SecurityManager security = System.getSecurityManager(); |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
53 |
if (security != null) { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
54 |
security.checkPermission( |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
55 |
new InquireSecContextPermission(type.toString())); |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
56 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
57 |
Object output = super.inquireSecContext(type.name()); |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
58 |
if (output != null) { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
59 |
if (type == InquireType.KRB5_GET_AUTHZ_DATA) { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
60 |
AuthorizationData ad = (AuthorizationData) output; |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
61 |
AuthorizationDataEntry[] authzData = |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
62 |
new AuthorizationDataEntry[ad.count()]; |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
63 |
for (int i = 0; i < ad.count(); i++) { |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
64 |
authzData[i] = new AuthorizationDataEntry( |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
65 |
ad.item(i).adType, ad.item(i).adData); |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
66 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
67 |
output = authzData; |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
68 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
69 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
70 |
return output; |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
71 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
72 |
} |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
73 |
|
3482 | 74 |
/** |
75 |
* Return the mechanism-specific attribute associated with {@code type}. |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23010
diff
changeset
|
76 |
* <p> |
3482 | 77 |
* If there is a security manager, an {@link InquireSecContextPermission} |
78 |
* with the name {@code type.mech} must be granted. Otherwise, this could |
|
26629
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
79 |
* result in a {@link SecurityException}. |
3b9ed8175488
8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents:
25859
diff
changeset
|
80 |
* <p> |
3482 | 81 |
* Example: |
82 |
* <pre> |
|
83 |
* GSSContext ctxt = m.createContext(...) |
|
84 |
* // Establishing the context |
|
85 |
* if (ctxt instanceof ExtendedGSSContext) { |
|
86 |
* ExtendedGSSContext ex = (ExtendedGSSContext)ctxt; |
|
87 |
* try { |
|
88 |
* Key key = (key)ex.inquireSecContext( |
|
89 |
* InquireType.KRB5_GET_SESSION_KEY); |
|
90 |
* // read key info |
|
91 |
* } catch (GSSException gsse) { |
|
92 |
* // deal with exception |
|
93 |
* } |
|
94 |
* } |
|
95 |
* </pre> |
|
96 |
* @param type the type of the attribute requested |
|
97 |
* @return the attribute, see the method documentation for details. |
|
98 |
* @throws GSSException containing the following |
|
99 |
* major error codes: |
|
100 |
* {@link GSSException#BAD_MECH GSSException.BAD_MECH} if the mechanism |
|
101 |
* does not support this method, |
|
102 |
* {@link GSSException#UNAVAILABLE GSSException.UNAVAILABLE} if the |
|
103 |
* type specified is not supported, |
|
104 |
* {@link GSSException#NO_CONTEXT GSSException.NO_CONTEXT} if the |
|
105 |
* security context is invalid, |
|
106 |
* {@link GSSException#FAILURE GSSException.FAILURE} for other |
|
107 |
* unspecified failures. |
|
108 |
* @throws SecurityException if a security manager exists and a proper |
|
109 |
* {@link InquireSecContextPermission} is not granted. |
|
110 |
* @see InquireSecContextPermission |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
23010
diff
changeset
|
111 |
* @see InquireType |
3482 | 112 |
*/ |
113 |
public Object inquireSecContext(InquireType type) |
|
114 |
throws GSSException; |
|
4336 | 115 |
|
116 |
/** |
|
117 |
* Requests that the delegation policy be respected. When a true value is |
|
118 |
* requested, the underlying context would use the delegation policy |
|
119 |
* defined by the environment as a hint to determine whether credentials |
|
120 |
* delegation should be performed. This request can only be made on the |
|
121 |
* context initiator's side and it has to be done prior to the first |
|
122 |
* call to <code>initSecContext</code>. |
|
123 |
* <p> |
|
124 |
* When this flag is false, delegation will only be tried when the |
|
125 |
* {@link GSSContext#requestCredDeleg(boolean) credentials delegation flag} |
|
126 |
* is true. |
|
127 |
* <p> |
|
128 |
* When this flag is true but the |
|
129 |
* {@link GSSContext#requestCredDeleg(boolean) credentials delegation flag} |
|
130 |
* is false, delegation will be only tried if the delegation policy permits |
|
131 |
* delegation. |
|
132 |
* <p> |
|
133 |
* When both this flag and the |
|
134 |
* {@link GSSContext#requestCredDeleg(boolean) credentials delegation flag} |
|
135 |
* are true, delegation will be always tried. However, if the delegation |
|
136 |
* policy does not permit delegation, the value of |
|
137 |
* {@link #getDelegPolicyState} will be false, even |
|
138 |
* if delegation is performed successfully. |
|
139 |
* <p> |
|
140 |
* In any case, if the delegation is not successful, the value returned |
|
141 |
* by {@link GSSContext#getCredDelegState()} is false, and the value |
|
142 |
* returned by {@link #getDelegPolicyState()} is also false. |
|
143 |
* <p> |
|
144 |
* Not all mechanisms support delegation policy. Therefore, the |
|
145 |
* application should check to see if the request was honored with the |
|
146 |
* {@link #getDelegPolicyState() getDelegPolicyState} method. When |
|
147 |
* delegation policy is not supported, <code>requestDelegPolicy</code> |
|
148 |
* should return silently without throwing an exception. |
|
149 |
* <p> |
|
150 |
* Note: for the Kerberos 5 mechanism, the delegation policy is expressed |
|
151 |
* through the OK-AS-DELEGATE flag in the service ticket. When it's true, |
|
152 |
* the KDC permits delegation to the target server. In a cross-realm |
|
153 |
* environment, in order for delegation be permitted, all cross-realm TGTs |
|
154 |
* on the authentication path must also have the OK-AS-DELAGATE flags set. |
|
155 |
* @param state true if the policy should be respected |
|
156 |
* @throws GSSException containing the following |
|
157 |
* major error codes: |
|
158 |
* {@link GSSException#FAILURE GSSException.FAILURE} |
|
159 |
*/ |
|
160 |
public void requestDelegPolicy(boolean state) throws GSSException; |
|
161 |
||
162 |
/** |
|
163 |
* Returns the delegation policy response. Called after a security context |
|
164 |
* is established. This method can be only called on the initiator's side. |
|
165 |
* See {@link ExtendedGSSContext#requestDelegPolicy}. |
|
166 |
* @return the delegation policy response |
|
167 |
*/ |
|
168 |
public boolean getDelegPolicyState(); |
|
3482 | 169 |
} |