本文整理汇总了Java中sun.security.krb5.internal.ccache.CredentialsCache类的典型用法代码示例。如果您正苦于以下问题:Java CredentialsCache类的具体用法?Java CredentialsCache怎么用?Java CredentialsCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CredentialsCache类属于sun.security.krb5.internal.ccache包,在下文中一共展示了CredentialsCache类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putInCache
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
/**
* Put TGS credentials ticket in cache file to persist credentials.
*
* @param tgsCredentials TGS credentials
* @throws KrbException
* @throws IOException
*/
public static void putInCache(sun.security.krb5.Credentials tgsCredentials)
throws KrbException, IOException {
CredentialsCache cache = CredentialsCache.getInstance();
Credentials ccreds = new sun.security.krb5.internal.ccache.Credentials(
tgsCredentials.getClient(),
tgsCredentials.getServer(),
tgsCredentials.getSessionKey(),
new KerberosTime(tgsCredentials.getAuthTime()),
/*new KerberosTime(tgsCredentials.getStartTime())*/ null,
new KerberosTime(tgsCredentials.getEndTime()),
/*new KerberosTime(receivedCredentials.getRenewTill())*/ null,
false,
tgsCredentials.getTicketFlags(),
/*new HostAddresses(receivedCredentials.getClientAddresses())*/ null,
null,
tgsCredentials.getTicket(),
null);
cache.update(ccreds);
cache.save();
}
示例2: main
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final PrincipalName pn = new PrincipalName("[email protected]");
final String ccache = args[0];
if (args.length == 1) {
// Main process, write the ccache and launch sub process
CredentialsCache cache = CredentialsCache.create(pn, ccache);
cache.save();
Proc p = Proc.create("EmptyCC").args(ccache, "readcc")
.env("KRB5CCNAME", ccache).start();
p.waitFor();
} else {
// Sub process, read the ccache
String cc = System.getenv("KRB5CCNAME");
if (!cc.equals(ccache)) {
throw new Exception("env not set correctly");
}
// 8001208: Fix for KRB5CCNAME not complete
// Make sure the ccache is created with bare file name
if (CredentialsCache.getInstance() == null) {
throw new Exception("Cache not instantiated");
}
if (!new File("tmpcc").exists()) {
throw new Exception("File not found");
}
Credentials.acquireTGTFromCache(pn, null);
}
}
示例3: test03checkCache
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
@Test
public void test03checkCache() {
try {
CredentialsCache cache = KerberosTicketManager.getCache();
Credentials[] credentials = cache.getCredsList();
assertEquals(2, credentials.length);
assertEquals("krbtgt/[email protected]",
credentials[0].getServicePrincipal().toString());
assertEquals("host/[email protected]",
credentials[1].getServicePrincipal().toString());
} catch (RealmException e) {
e.printStackTrace();
}
}
示例4: main
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
for (int i=0; i<TimeInCCache.ccache.length; i++) {
byte old = TimeInCCache.ccache[i];
TimeInCCache.ccache[i] = 0x7f;
Files.write(Paths.get("tmpcc"), TimeInCCache.ccache);
// The next line will return null for I/O issues. That's OK.
CredentialsCache.getInstance("tmpcc");
TimeInCCache.ccache[i] = old;
}
}
示例5: main
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
byte[] ccache = TimeInCCache.ccache;
// The service name starts at 0x52:
//
// 0050: 00 00 00 02 00 00 00 0A 4D 41 58 49 2E 4C
// ----------- -----------
// 0060: 4F 43 41 4C 00 00 00 06 6B 72 62 74 67 74 00 00
// ----------- -----
// 0070: 00 0A 4D 41 58 49 2E 4C 4F 43 41 4C
// -----
//
// which contains 2 (the length of names), a 10-byte realm, a 6-byte
// name[0], and a 10-byte name[1].
// We will empty the realm, and pack the realm string to another
// name (6-byte ".LOCAL"). Finally "krbtgt/[email protected]"
// becomes ".LOCAL/krbtgt/[email protected]".
// length of names is now 3
ccache[0x55] = 3;
// The empty realm
System.arraycopy(new byte[4], 0, ccache, 0x56, 4);
// Length of inserted name is 6
System.arraycopy(new byte[]{0,0,0,6}, 0, ccache, 0x5A, 4);
Files.write(Paths.get("tmpcc"), TimeInCCache.ccache);
if (CredentialsCache.getInstance("tmpcc").getCredsList() != null) {
throw new Exception("Nothing should be there");
}
}
示例6: acquireDefaultCreds
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
/**
* Acquires default credentials.
* <br>The possible locations for default credentials cache is searched in
* the following order:
* <ol>
* <li> The directory and cache file name specified by "KRB5CCNAME" system.
* property.
* <li> The directory and cache file name specified by "KRB5CCNAME"
* environment variable.
* <li> A cache file named krb5cc_{user.name} at {user.home} directory.
* </ol>
* @return a <code>KrbCreds</code> object if the credential is found,
* otherwise return null.
*/
// this method is intentionally changed to not check if the caller's
// principal name matches cache file's principal name.
// It assumes that the GSS call has
// the privilege to access the default cache file.
// This method is only called on Windows and Mac OS X, the native
// acquireDefaultNativeCreds is also available on these platforms.
public static synchronized Credentials acquireDefaultCreds() {
Credentials result = null;
if (cache == null) {
cache = CredentialsCache.getInstance();
}
if (cache != null) {
sun.security.krb5.internal.ccache.Credentials temp =
cache.getDefaultCreds();
if (temp != null) {
if (DEBUG) {
System.out.println(">>> KrbCreds found the default ticket"
+ " granting ticket in credential cache.");
}
if (EType.isSupported(temp.getEType())) {
result = temp.setKrbCreds();
} else {
if (DEBUG) {
System.out.println(
">>> unsupported key type found the default TGT: " +
temp.getEType());
}
}
}
}
if (result == null) {
// Doesn't seem to be a default cache on this system or
// TGT has unsupported encryption type
if (!alreadyTried) {
// See if there's any native code to load
try {
ensureLoaded();
} catch (Exception e) {
if (DEBUG) {
System.out.println("Can not load credentials cache");
e.printStackTrace();
}
alreadyTried = true;
}
}
if (alreadyLoaded) {
// There is some native code
if (DEBUG) {
System.out.println(">> Acquire default native Credentials");
}
try {
result = acquireDefaultNativeCreds(
EType.getDefaults("default_tkt_enctypes"));
} catch (KrbException ke) {
// when there is no default_tkt_enctypes.
}
}
}
return result;
}
示例7: getCache
import sun.security.krb5.internal.ccache.CredentialsCache; //导入依赖的package包/类
public CredentialsCache getCache() {
return cache;
}