本文整理汇总了Java中sun.security.krb5.internal.ccache.CredentialsCache.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java CredentialsCache.getInstance方法的具体用法?Java CredentialsCache.getInstance怎么用?Java CredentialsCache.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.security.krb5.internal.ccache.CredentialsCache
的用法示例。
在下文中一共展示了CredentialsCache.getInstance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
示例4: 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;
}
示例5: acquireTGTFromCache
import sun.security.krb5.internal.ccache.CredentialsCache; //导入方法依赖的package包/类
/**
* Returns a TGT for the given client principal from a ticket cache.
*
* @param princ the client principal. A value of null means that the
* default principal name in the credentials cache will be used.
* @param ticketCache the path to the tickets file. A value
* of null will be accepted to indicate that the default
* path should be searched
* @returns the TGT credentials or null if none were found. If the tgt
* expired, it is the responsibility of the caller to determine this.
*/
public static Credentials acquireTGTFromCache(PrincipalName princ,
String ticketCache)
throws KrbException, IOException {
if (ticketCache == null) {
// The default ticket cache on Windows is not a file.
String os = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("os.name"));
if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS")) {
Credentials creds = acquireDefaultCreds();
if (creds == null) {
if (DEBUG) {
System.out.println(">>> Found no TGT's in LSA");
}
return null;
}
if (princ != null) {
if (creds.getClient().equals(princ)) {
if (DEBUG) {
System.out.println(">>> Obtained TGT from LSA: "
+ creds);
}
return creds;
} else {
if (DEBUG) {
System.out.println(">>> LSA contains TGT for "
+ creds.getClient()
+ " not "
+ princ);
}
return null;
}
} else {
if (DEBUG) {
System.out.println(">>> Obtained TGT from LSA: "
+ creds);
}
return creds;
}
}
}
/*
* Returns the appropriate cache. If ticketCache is null, it is the
* default cache otherwise it is the cache filename contained in it.
*/
CredentialsCache ccache =
CredentialsCache.getInstance(princ, ticketCache);
if (ccache == null)
return null;
sun.security.krb5.internal.ccache.Credentials tgtCred =
ccache.getDefaultCreds();
if (EType.isSupported(tgtCred.getEType())) {
return tgtCred.setKrbCreds();
} else {
if (DEBUG) {
System.out.println(
">>> unsupported key type found the default TGT: " +
tgtCred.getEType());
}
return null;
}
}
示例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.
public static synchronized Credentials acquireDefaultCreds() {
Credentials result = null;
if (cache == null) {
cache = CredentialsCache.getInstance();
}
if (cache != null) {
if (DEBUG) {
System.out.println(">>> KrbCreds found the default ticket " +
"granting ticket in credential cache.");
}
sun.security.krb5.internal.ccache.Credentials temp =
cache.getDefaultCreds();
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");
result = acquireDefaultNativeCreds();
// only TGT with DES key will be returned by native method
}
}
return result;
}
示例7: 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");
}
result = acquireDefaultNativeCreds(
EType.getDefaults("default_tkt_enctypes"));
}
}
return result;
}
示例8: 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();
// java -cp $test.classes EmptyCC readcc
ProcessBuilder pb = new ProcessBuilder(
new File(new File(System.getProperty("java.home"), "bin"),
"java").getPath(),
"-cp",
System.getProperty("test.classes"),
"EmptyCC",
ccache,
"readcc"
);
pb.environment().put("KRB5CCNAME", ccache);
pb.redirectErrorStream(true);
Process p = pb.start();
try (InputStream ins = p.getInputStream()) {
byte[] buf = new byte[8192];
int n;
while ((n = ins.read(buf)) > 0) {
System.out.write(buf, 0, n);
}
}
if (p.waitFor() != 0) {
throw new Exception("Test failed");
}
} 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);
}
}
示例9: 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.
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");
result = acquireDefaultNativeCreds();
// only TGT with DES key will be returned by native method
}
}
return result;
}
示例10: getCache
import sun.security.krb5.internal.ccache.CredentialsCache; //导入方法依赖的package包/类
/**
* Get credentials tickets cache (from file with default name /tmp/krb5cc_${uuid} for Linux)
*
* @return credentials tickets cache
*/
public static CredentialsCache getCache() {
return CredentialsCache.getInstance();
}