當前位置: 首頁>>代碼示例>>Java>>正文


Java GSSManager.createCredential方法代碼示例

本文整理匯總了Java中org.ietf.jgss.GSSManager.createCredential方法的典型用法代碼示例。如果您正苦於以下問題:Java GSSManager.createCredential方法的具體用法?Java GSSManager.createCredential怎麽用?Java GSSManager.createCredential使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.ietf.jgss.GSSManager的用法示例。


在下文中一共展示了GSSManager.createCredential方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = 11*3600;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:LifeTimeInSeconds.java

示例2: main

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    new OneKDC(null).writeJAASConf();
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    GSSManager gm = GSSManager.getInstance();
    GSSCredential cred = gm.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    int time = cred.getRemainingLifetime();
    int time2 = cred.getRemainingInitLifetime(null);
    // The test KDC issues a TGT with a default lifetime of 11 hours
    int elevenhrs = KDC.DEFAULT_LIFETIME;
    if (time > elevenhrs+60 || time < elevenhrs-60) {
        throw new Exception("getRemainingLifetime returns wrong value.");
    }
    if (time2 > elevenhrs+60 || time2 < elevenhrs-60) {
        throw new Exception("getRemainingInitLifetime returns wrong value.");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:LifeTimeInSeconds.java

示例3: initGSS

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
GSSContext initGSS() throws Exception {
    final GSSManager MANAGER = GSSManager.getInstance();

    final PrivilegedExceptionAction<GSSCredential> action = new PrivilegedExceptionAction<GSSCredential>() {
        @Override
        public GSSCredential run() throws GSSException {
            return MANAGER.createCredential(null, GSSCredential.DEFAULT_LIFETIME, KrbConstants.SPNEGO, GSSCredential.INITIATE_ONLY);
        }
    };

    final GSSCredential clientcreds = Subject.doAs(initiatorSubject, action);

    final GSSContext context = MANAGER.createContext(MANAGER.createName(acceptorPrincipal, GSSName.NT_USER_NAME, KrbConstants.SPNEGO),
            KrbConstants.SPNEGO, clientcreds, GSSContext.DEFAULT_LIFETIME);

    //TODO make configurable
    context.requestMutualAuth(true);
    context.requestConf(true);
    context.requestInteg(true);
    context.requestReplayDet(true);
    context.requestSequenceDet(true);
    context.requestCredDeleg(false);

    return context;
}
 
開發者ID:codecentric,項目名稱:elasticsearch-shield-kerberos-realm,代碼行數:26,代碼來源:KerberizedClient.java

示例4: getDefaultCredential

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public static GSSCredential getDefaultCredential() throws InvalidSecurityContextException {
	synchronized (ChannelFactory.class) {
		if (cachedCredential == null
				||
				(System.currentTimeMillis() - credentialTime) > DEFAULT_CREDENTIAL_REFRESH_INTERVAL) {
			credentialTime = System.currentTimeMillis();
			GSSManager manager = ExtendedGSSManager.getInstance();
			try {
				cachedCredential = manager.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
			}
			catch (GSSException e) {
				throw new InvalidSecurityContextException(e);
			}
		}
		return cachedCredential;
	}
}
 
開發者ID:swift-lang,項目名稱:swift-k,代碼行數:18,代碼來源:ChannelFactory.java

示例5: testAnonymousServer3

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public void testAnonymousServer3() throws Exception {

GSSManager manager = getGSSManager();

GSSName anonName = manager.createName((String)null, null);
assertTrue(anonName.isAnonymous());

GSSCredential anonCred = manager.createCredential(anonName,
						  GSSCredential.INDEFINITE_LIFETIME,
						  (Oid)null,
						  GSSCredential.INITIATE_AND_ACCEPT);
assertTrue(anonCred.getName().isAnonymous());

// server ctx initalized with anon cred
serverContext = manager.createContext(anonCred);

try {
    establishContext();
    fail("establishContext() did not throw exception as expected.");
} catch (GSSException e) {
    if (e.getMajor() != GSSException.DEFECTIVE_CREDENTIAL) {
	e.printStackTrace();
	fail("Unexpected GSSException");
    }
}
   }
 
開發者ID:NCIP,項目名稱:cagrid-general,代碼行數:27,代碼來源:GlobusGSSContextTest.java

示例6: testBadUsage1

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public void testBadUsage1() throws Exception {
GSSManager manager = getGSSManager();

GSSCredential cred = manager.createCredential(null,
					      GSSCredential.DEFAULT_LIFETIME,
					      (Oid)null,
					      GSSCredential.INITIATE_ONLY);

// creates an accepter context with credential that is 
// supposed to be used for initiators
serverContext = manager.createContext(cred);

try {
    establishContext();
    fail("establishContext() did not throw exception as expected.");
} catch (GSSException e) {
    if (e.getMajor() != GSSException.DEFECTIVE_CREDENTIAL) {
	e.printStackTrace();
	fail("Unexpected GSSException");
    }
}
   }
 
開發者ID:NCIP,項目名稱:cagrid-general,代碼行數:23,代碼來源:GlobusGSSContextTest.java

示例7: testBadUsage2

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public void testBadUsage2() throws Exception {
GSSManager manager = getGSSManager();

GSSCredential cred = manager.createCredential(null,
					      GSSCredential.DEFAULT_LIFETIME,
					      (Oid)null,
					      GSSCredential.ACCEPT_ONLY);

// creates an initiator context with credential that is 
// supposed to be used for acceptor
clientContext = manager.createContext(null, 
				      GSSConstants.MECH_OID,
				      cred,
				      GSSContext.DEFAULT_LIFETIME);

try {
    establishContext();
    fail("establishContext() did not throw exception as expected.");
} catch (GSSException e) {
    if (e.getMajor() != GSSException.DEFECTIVE_CREDENTIAL) {
	e.printStackTrace();
	fail("Unexpected GSSException");
    }
}
   }
 
開發者ID:NCIP,項目名稱:cagrid-general,代碼行數:26,代碼來源:GlobusGSSContextTest.java

示例8: getGSSCredential

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
private static GSSCredential getGSSCredential(final String userName) throws SaslException {
    try {
        Oid krb5Mechanism = new Oid(GSSAPI_OID);
        GSSManager manager = GSSManager.getInstance();
        GSSName name = manager.createName(userName, GSSName.NT_USER_NAME);
        return manager.createCredential(name, GSSCredential.INDEFINITE_LIFETIME, krb5Mechanism, GSSCredential.INITIATE_ONLY);
    } catch (GSSException e) {
        throw new SaslException("Unable to create GSSAPI credential", e);
    }
}
 
開發者ID:mongodb,項目名稱:mongosql-auth-java,代碼行數:11,代碼來源:Gssapi.java

示例9: generateTicket

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
private String generateTicket() throws GSSException {
  final GSSManager manager = GSSManager.getInstance();
  // Oid for kerberos principal name
  Oid krb5PrincipalOid = new Oid("1.2.840.113554.1.2.2.1");
  Oid KERB_V5_OID = new Oid("1.2.840.113554.1.2.2");
  final GSSName clientName = manager.createName(principal,
      krb5PrincipalOid);
  final GSSCredential clientCred = manager.createCredential(clientName,
      8 * 3600,
      KERB_V5_OID,
      GSSCredential.INITIATE_ONLY);

  final GSSName serverName = manager.createName(principal, krb5PrincipalOid);

  final GSSContext context = manager.createContext(serverName,
      KERB_V5_OID,
      clientCred,
      GSSContext.DEFAULT_LIFETIME);
  context.requestMutualAuth(true);
  context.requestConf(false);
  context.requestInteg(true);

  final byte[] outToken = context.initSecContext(new byte[0], 0, 0);
  StringBuffer outputBuffer = new StringBuffer();
  outputBuffer.append("Negotiate ");
  outputBuffer.append(Base64.encodeBytes(outToken).replace("\n", ""));
  System.out.print("Ticket is: " + outputBuffer);
  return outputBuffer.toString();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:30,代碼來源:HttpDoAsClient.java

示例10: GSSAuthentication

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
public GSSAuthentication(byte[] token) throws GSSException {
	GSSManager gssManager = GSSManager.getInstance();
	GSSCredential gssCreds = gssManager.createCredential(
			(GSSName) null, GSSCredential.INDEFINITE_LIFETIME,
			(Oid) null, GSSCredential.ACCEPT_ONLY);
	GSSContext gssContext = gssManager.createContext(gssCreds);

	responseToken = gssContext
			.acceptSecContext(token, 0, token.length);

	if (gssContext.isEstablished()) {
		GSSName name = gssContext.getSrcName();
		username = name.toString();
	}
}
 
開發者ID:cbsit,項目名稱:JaasLounge,代碼行數:16,代碼來源:GSSAuthentication.java

示例11: Kerb5Context

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
Kerb5Context ( String host, String service, String name, int userLifetime, int contextLifetime, String realm ) throws GSSException {
    GSSManager manager = GSSManager.getInstance();
    GSSCredential clientCreds = null;
    Oid mechOid = JGSS_KRB5_MECH_OID;
    if ( realm != null ) {
        this.serviceName = manager.createName(service + "/" + host + "@" + realm, JGSS_KRB5_NAME_OID, mechOid);
    }
    else {
        this.serviceName = manager.createName(service + "@" + host, GSSName.NT_HOSTBASED_SERVICE, mechOid);
    }

    if ( log.isDebugEnabled() ) {
        log.debug("Service name is " + this.serviceName);
    }

    if ( name != null ) {
        this.clientName = manager.createName(name, GSSName.NT_USER_NAME, mechOid);
        clientCreds = manager.createCredential(this.clientName, userLifetime, mechOid, GSSCredential.INITIATE_ONLY);
    }
    else {
        this.clientName = null;
    }

    this.gssContext = manager.createContext(this.serviceName, mechOid, clientCreds, contextLifetime);

    this.gssContext.requestAnonymity(false);
    this.gssContext.requestSequenceDet(false);
    this.gssContext.requestConf(false);
    this.gssContext.requestInteg(false);
    this.gssContext.requestReplayDet(false);

    // per spec these should be set
    this.gssContext.requestMutualAuth(true);
    this.gssContext.requestCredDeleg(true);
}
 
開發者ID:AgNO3,項目名稱:jcifs-ng,代碼行數:36,代碼來源:Kerb5Context.java

示例12: generateTicket

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
private String generateTicket() throws GSSException {
  final GSSManager manager = GSSManager.getInstance();
  // Oid for kerberos principal name
  Oid krb5PrincipalOid = new Oid("1.2.840.113554.1.2.2.1");
  Oid KERB_V5_OID = new Oid("1.2.840.113554.1.2.2");
  final GSSName clientName = manager.createName("hbase/[email protected]",
      krb5PrincipalOid);
  final GSSCredential clientCred = manager.createCredential(clientName,
      8 * 3600,
      KERB_V5_OID,
      GSSCredential.INITIATE_ONLY);

  final GSSName serverName = manager.createName("hbase/[email protected]", krb5PrincipalOid);

  final GSSContext context = manager.createContext(serverName,
      KERB_V5_OID,
      clientCred,
      GSSContext.DEFAULT_LIFETIME);
  context.requestMutualAuth(true);
  context.requestConf(false);
  context.requestInteg(true);

  final byte[] outToken = context.initSecContext(new byte[0], 0, 0);
  StringBuffer outputBuffer = new StringBuffer();
  outputBuffer.append("Negotiate ");
  outputBuffer.append(new BASE64Encoder().encode(outToken).replace("\n", ""));
  System.out.print("Ticket is: " + outputBuffer);
  return outputBuffer.toString();
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:30,代碼來源:HttpDoAsClient.java

示例13: loadDefaultProxy

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
private static GSSCredential loadDefaultProxy() {
    GSSManager manager = ExtendedGSSManager.getInstance();
    try {
        return manager.createCredential(GSSCredential.INITIATE_AND_ACCEPT);
    }
    catch (GSSException e) {
        throw new SecurityException(e);
    }
}
 
開發者ID:swift-lang,項目名稱:swift-k,代碼行數:10,代碼來源:GlobusSecurityContextImpl.java

示例14: getGSSCredential

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
private GSSCredential getGSSCredential(String userName) throws GSSException {
    Oid krb5Mechanism = new Oid(GSSAPI_OID);
    GSSManager manager = GSSManager.getInstance();
    GSSName name = manager.createName(userName, GSSName.NT_USER_NAME);
    return manager.createCredential(name, GSSCredential.INDEFINITE_LIFETIME,
            krb5Mechanism, GSSCredential.INITIATE_ONLY);
}
 
開發者ID:MaOrKsSi,項目名稱:HZS.Durian,代碼行數:8,代碼來源:DBPort.java

示例15: getDefaultCredential

import org.ietf.jgss.GSSManager; //導入方法依賴的package包/類
private static GSSCredential getDefaultCredential() {
GSSManager manager = ExtendedGSSManager.getInstance();
try {
    return manager.createCredential(GSSCredential.INITIATE_ONLY);
} catch(GSSException e) {
    System.err.println("Failed to load default credentials: " + 
		       e.getMessage());
    System.exit(-1);
}
return null;
   }
 
開發者ID:NCIP,項目名稱:cagrid-general,代碼行數:12,代碼來源:MyProxy.java


注:本文中的org.ietf.jgss.GSSManager.createCredential方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。