本文整理匯總了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.");
}
}
示例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.");
}
}
示例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;
}
示例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;
}
}
示例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");
}
}
}
示例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");
}
}
}
示例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");
}
}
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}