本文整理汇总了Java中javax.security.auth.kerberos.KerberosPrincipal.KRB_NT_PRINCIPAL属性的典型用法代码示例。如果您正苦于以下问题:Java KerberosPrincipal.KRB_NT_PRINCIPAL属性的具体用法?Java KerberosPrincipal.KRB_NT_PRINCIPAL怎么用?Java KerberosPrincipal.KRB_NT_PRINCIPAL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.security.auth.kerberos.KerberosPrincipal
的用法示例。
在下文中一共展示了KerberosPrincipal.KRB_NT_PRINCIPAL属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clientPasswordloginSuccess
@Test
public void clientPasswordloginSuccess() {
Subject clientSubject = krb5ClientHelper.krb5PasswordLogin(testPassword);
KerberosPrincipal testingPrincipal = new KerberosPrincipal(clientPrincipal, KerberosPrincipal.KRB_NT_PRINCIPAL);
Set<KerberosPrincipal> principals = clientSubject.getPrincipals(KerberosPrincipal.class);
assertTrue(principals.contains(testingPrincipal));
assertEquals(krb5ClientHelper.principalNameFromSubject(clientSubject), clientPrincipal);
}
示例2: doLocalhost
private SpnegoPrincipal doLocalhost() {
final String username = System.getProperty("user.name");
if (null == username || username.isEmpty()) {
return new SpnegoPrincipal(this.serverPrincipal.getName() + '@'
+ this.serverPrincipal.getRealm()
, this.serverPrincipal.getNameType());
} else {
return new SpnegoPrincipal(username + '@'
+ this.serverPrincipal.getRealm()
, KerberosPrincipal.KRB_NT_PRINCIPAL);
}
}
示例3: getInitiatorSubject
public static Subject getInitiatorSubject ( String userName, String password, String realm, Long expire ) throws Exception {
KerberosPrincipal principal = new KerberosPrincipal(String.format("%[email protected]%s", userName, realm), KerberosPrincipal.KRB_NT_PRINCIPAL);
return getInitiatorSubject(principal, password, expire);
}
示例4: doBasicAuth
/**
* Performs authentication using the BASIC Auth mechanism.
*
* <p>
* Returns null if authentication failed or if the provided
* the auth scheme did not contain BASIC Auth data/token.
* </p>
*
* @return SpnegoPrincipal for the given auth scheme.
*/
private SpnegoPrincipal doBasicAuth(final SpnegoAuthScheme scheme
, final SpnegoHttpServletResponse resp) throws IOException {
final byte[] data = scheme.getToken();
if (0 == data.length) {
LOGGER.finer("Basic Auth data was NULL.");
return null;
}
final String[] basicData = new String(data).split(":", 2);
// assert
if (basicData.length != 2) {
throw new IllegalArgumentException("Username/Password may"
+ " have contained an invalid character. basicData.length="
+ basicData.length);
}
// substring to remove domain (if provided)
final String username = basicData[0].substring(basicData[0].indexOf('\\') + 1);
final String password = basicData[1];
final CallbackHandler handler = SpnegoProvider.getUsernamePasswordHandler(
username, password);
SpnegoPrincipal principal = null;
try {
// assert
if (null == username || username.isEmpty()) {
throw new LoginException("Username is required.");
}
final LoginContext cntxt = new LoginContext(this.clientModuleName, handler);
// validate username/password by login/logout
cntxt.login();
cntxt.logout();
principal = new SpnegoPrincipal(username + '@'
+ this.serverPrincipal.getRealm()
, KerberosPrincipal.KRB_NT_PRINCIPAL);
} catch (LoginException le) {
LOGGER.info(le.getMessage() + ": Login failed. username=" + username
+ "; password.hashCode()=" + password.hashCode());
LOGGER.log(Level.FINE, "Cause", le);
resp.setHeader(Constants.AUTHN_HEADER, Constants.NEGOTIATE_HEADER);
resp.addHeader(Constants.AUTHN_HEADER, Constants.BASIC_HEADER
+ " realm=\"" + this.serverPrincipal.getRealm() + '\"');
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED, true);
}
return principal;
}
示例5: doSpnegoAuth
/**
* Performs authentication using the SPNEGO mechanism.
*
* <p>
* Returns null if authentication failed or if the provided
* the auth scheme did not contain the SPNEGO/GSS token.
* </p>
*
* @return SpnegoPrincipal for the given auth scheme.
*/
private SpnegoPrincipal doSpnegoAuth(
final SpnegoAuthScheme scheme, final SpnegoHttpServletResponse resp)
throws GSSException, IOException {
final String principal;
final byte[] gss = scheme.getToken();
if (0 == gss.length) {
LOGGER.finer("GSS data was NULL.");
return null;
}
GSSContext context = null;
GSSCredential delegCred = null;
try {
byte[] token = null;
SpnegoAuthenticator.LOCK.lock();
try {
context = SpnegoAuthenticator.MANAGER.createContext(this.serverCredentials);
token = context.acceptSecContext(gss, 0, gss.length);
} finally {
SpnegoAuthenticator.LOCK.unlock();
}
if (null == token) {
LOGGER.finer("Token was NULL.");
return null;
}
resp.setHeader(Constants.AUTHN_HEADER, Constants.NEGOTIATE_HEADER
+ ' ' + Base64.encode(token));
if (!context.isEstablished()) {
LOGGER.fine("context not established");
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED, true);
return null;
}
principal = context.getSrcName().toString();
if (this.allowDelegation && context.getCredDelegState()) {
delegCred = context.getDelegCred();
}
} finally {
if (null != context) {
SpnegoAuthenticator.LOCK.lock();
try {
context.dispose();
} finally {
SpnegoAuthenticator.LOCK.unlock();
}
}
}
return new SpnegoPrincipal(principal, KerberosPrincipal.KRB_NT_PRINCIPAL, delegCred);
}