Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/ssl/Krb5Helper.java
38830 views
1
/*
2
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package sun.security.ssl;
27
28
import java.security.AccessControlContext;
29
import java.security.AccessController;
30
import java.security.Permission;
31
import java.security.Principal;
32
import java.security.PrivilegedAction;
33
import javax.crypto.SecretKey;
34
import javax.security.auth.Subject;
35
import javax.security.auth.login.LoginException;
36
37
/**
38
* A helper class for Kerberos APIs.
39
*/
40
public final class Krb5Helper {
41
42
private Krb5Helper() { }
43
44
// loads Krb5Proxy implementation class if available
45
private static final String IMPL_CLASS =
46
"sun.security.ssl.krb5.Krb5ProxyImpl";
47
48
private static final Krb5Proxy proxy =
49
AccessController.doPrivileged(new PrivilegedAction<Krb5Proxy>() {
50
@Override
51
public Krb5Proxy run() {
52
try {
53
Class<?> c = Class.forName(IMPL_CLASS, true, null);
54
return (Krb5Proxy)c.newInstance();
55
} catch (ClassNotFoundException cnf) {
56
return null;
57
} catch (InstantiationException e) {
58
throw new AssertionError(e);
59
} catch (IllegalAccessException e) {
60
throw new AssertionError(e);
61
}
62
}});
63
64
private static void ensureAvailable() {
65
if (proxy == null)
66
throw new AssertionError("Kerberos should be available");
67
}
68
69
/**
70
* Returns the Subject associated with client-side of the SSL socket.
71
*/
72
public static Subject getClientSubject(AccessControlContext acc)
73
throws LoginException {
74
ensureAvailable();
75
return proxy.getClientSubject(acc);
76
}
77
78
/**
79
* Returns the Subject associated with server-side of the SSL socket.
80
*/
81
public static Subject getServerSubject(AccessControlContext acc)
82
throws LoginException {
83
ensureAvailable();
84
return proxy.getServerSubject(acc);
85
}
86
87
/**
88
* Returns the KerberosKeys for the default server-side principal.
89
*/
90
public static Object getServiceCreds(AccessControlContext acc)
91
throws LoginException {
92
ensureAvailable();
93
return proxy.getServiceCreds(acc);
94
}
95
96
/**
97
* Returns the server-side principal name associated with the KerberosKey.
98
*/
99
public static String getServerPrincipalName(Object serviceCreds) {
100
ensureAvailable();
101
return proxy.getServerPrincipalName(serviceCreds);
102
}
103
104
/**
105
* Returns the hostname embedded in the principal name.
106
*/
107
public static String getPrincipalHostName(Principal principal) {
108
ensureAvailable();
109
return proxy.getPrincipalHostName(principal);
110
}
111
112
/**
113
* Returns a ServicePermission for the principal name and action.
114
*/
115
public static Permission getServicePermission(String principalName,
116
String action) {
117
ensureAvailable();
118
return proxy.getServicePermission(principalName, action);
119
}
120
121
/**
122
* Determines if the Subject might contain creds for princ.
123
*/
124
public static boolean isRelated(Subject subject, Principal princ) {
125
ensureAvailable();
126
return proxy.isRelated(subject, princ);
127
}
128
}
129
130