2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
5506
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
2
|
23 |
*/
|
|
24 |
|
|
25 |
/*
|
|
26 |
*
|
|
27 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved.
|
|
28 |
* Copyright 1997 The Open Group Research Institute. All rights reserved.
|
|
29 |
*/
|
|
30 |
|
|
31 |
package sun.security.krb5.internal.ccache;
|
|
32 |
|
|
33 |
import sun.security.krb5.*;
|
|
34 |
import sun.security.krb5.internal.*;
|
58611
|
35 |
|
|
36 |
import java.util.List;
|
2
|
37 |
import java.io.IOException;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* CredentialsCache stores credentials(tickets, session keys, etc) in a semi-permanent store
|
|
41 |
* for later use by different program.
|
|
42 |
*
|
|
43 |
* @author Yanni Zhang
|
|
44 |
*/
|
|
45 |
public abstract class CredentialsCache {
|
|
46 |
static CredentialsCache singleton = null;
|
|
47 |
static String cacheName;
|
|
48 |
private static boolean DEBUG = Krb5.DEBUG;
|
|
49 |
|
|
50 |
public static CredentialsCache getInstance(PrincipalName principal) {
|
|
51 |
return FileCredentialsCache.acquireInstance(principal, null);
|
|
52 |
}
|
|
53 |
|
|
54 |
public static CredentialsCache getInstance(String cache) {
|
|
55 |
if ((cache.length() >= 5) && cache.substring(0, 5).equalsIgnoreCase("FILE:")) {
|
|
56 |
return FileCredentialsCache.acquireInstance(null, cache.substring(5));
|
|
57 |
}
|
|
58 |
// XXX else, memory credential cache
|
|
59 |
// default is file credential cache.
|
|
60 |
return FileCredentialsCache.acquireInstance(null, cache);
|
|
61 |
}
|
|
62 |
|
|
63 |
public static CredentialsCache getInstance(PrincipalName principal,
|
|
64 |
String cache) {
|
|
65 |
|
|
66 |
// XXX Modify this to use URL framework of the JDK
|
|
67 |
if (cache != null &&
|
|
68 |
(cache.length() >= 5) &&
|
|
69 |
cache.regionMatches(true, 0, "FILE:", 0, 5)) {
|
|
70 |
return FileCredentialsCache.acquireInstance(principal,
|
|
71 |
cache.substring(5));
|
|
72 |
}
|
|
73 |
|
|
74 |
// When cache is null, read the default cache.
|
|
75 |
// XXX else ..we haven't provided support for memory credential cache
|
|
76 |
// yet. (supported in native code)
|
|
77 |
// default is file credentials cache.
|
|
78 |
return FileCredentialsCache.acquireInstance(principal, cache);
|
|
79 |
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Gets the default credentials cache.
|
|
84 |
*/
|
|
85 |
public static CredentialsCache getInstance() {
|
|
86 |
// Default credentials cache is file-based.
|
|
87 |
return FileCredentialsCache.acquireInstance();
|
|
88 |
}
|
|
89 |
|
|
90 |
public static CredentialsCache create(PrincipalName principal, String name) {
|
|
91 |
if (name == null) {
|
|
92 |
throw new RuntimeException("cache name error");
|
|
93 |
}
|
|
94 |
if ((name.length() >= 5)
|
|
95 |
&& name.regionMatches(true, 0, "FILE:", 0, 5)) {
|
|
96 |
name = name.substring(5);
|
|
97 |
return (FileCredentialsCache.New(principal, name));
|
|
98 |
}
|
|
99 |
// else return file credentials cache
|
|
100 |
// default is file credentials cache.
|
|
101 |
return (FileCredentialsCache.New(principal, name));
|
|
102 |
}
|
|
103 |
|
|
104 |
public static CredentialsCache create(PrincipalName principal) {
|
|
105 |
// create a default credentials cache for a specified principal
|
|
106 |
return (FileCredentialsCache.New(principal));
|
|
107 |
}
|
|
108 |
|
|
109 |
public static String cacheName() {
|
|
110 |
return cacheName;
|
|
111 |
}
|
|
112 |
|
|
113 |
public abstract PrincipalName getPrimaryPrincipal();
|
|
114 |
public abstract void update(Credentials c);
|
|
115 |
public abstract void save() throws IOException, KrbException;
|
|
116 |
public abstract Credentials[] getCredsList();
|
|
117 |
public abstract Credentials getDefaultCreds();
|
58611
|
118 |
public abstract sun.security.krb5.Credentials getInitialCreds();
|
13247
|
119 |
public abstract Credentials getCreds(PrincipalName sname);
|
|
120 |
public abstract Credentials getCreds(LoginOptions options, PrincipalName sname);
|
58611
|
121 |
public abstract void addConfigEntry(ConfigEntry e);
|
|
122 |
public abstract List<ConfigEntry> getConfigEntries();
|
|
123 |
|
|
124 |
public ConfigEntry getConfigEntry(String name) {
|
|
125 |
List<ConfigEntry> entries = getConfigEntries();
|
|
126 |
if (entries != null) {
|
|
127 |
for (ConfigEntry e : entries) {
|
|
128 |
if (e.getName().equals(name)) {
|
|
129 |
return e;
|
|
130 |
}
|
|
131 |
}
|
|
132 |
}
|
|
133 |
return null;
|
|
134 |
}
|
|
135 |
|
|
136 |
public static class ConfigEntry {
|
|
137 |
|
|
138 |
public ConfigEntry(String name, PrincipalName princ, byte[] data) {
|
|
139 |
this.name = name;
|
|
140 |
this.princ = princ;
|
|
141 |
this.data = data;
|
|
142 |
}
|
|
143 |
|
|
144 |
private final String name;
|
|
145 |
private final PrincipalName princ;
|
|
146 |
private final byte[] data; // not worth cloning
|
|
147 |
|
|
148 |
public String getName() {
|
|
149 |
return name;
|
|
150 |
}
|
|
151 |
|
|
152 |
public PrincipalName getPrinc() {
|
|
153 |
return princ;
|
|
154 |
}
|
|
155 |
|
|
156 |
public byte[] getData() {
|
|
157 |
return data;
|
|
158 |
}
|
|
159 |
|
|
160 |
@Override
|
|
161 |
public String toString() {
|
|
162 |
return name + (princ != null ? ("." + princ) : "")
|
|
163 |
+ ": " + new String(data);
|
|
164 |
}
|
|
165 |
|
|
166 |
public PrincipalName getSName() {
|
|
167 |
try {
|
|
168 |
return new PrincipalName("krb5_ccache_conf_data/" + name
|
|
169 |
+ (princ != null ? ("/" + princ) : "")
|
|
170 |
+ "@X-CACHECONF:");
|
|
171 |
} catch (RealmException e) {
|
|
172 |
throw new AssertionError(e);
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
2
|
176 |
}
|