本文整理汇总了Java中org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential.setPrincipal方法的典型用法代码示例。如果您正苦于以下问题:Java SpnegoCredential.setPrincipal方法的具体用法?Java SpnegoCredential.setPrincipal怎么用?Java SpnegoCredential.setPrincipal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential
的用法示例。
在下文中一共展示了SpnegoCredential.setPrincipal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected final HandlerResult doAuthentication(
final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
UniAddress dc = null;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if (StringUtils.isNotBlank(this.includePattern)) {
final NbtAddress[] dcs = NbtAddress.getAllByName(this.domainController, NBT_ADDRESS_TYPE, null, null);
for (final NbtAddress dc2 : dcs) {
if(dc2.getHostAddress().matches(this.includePattern)){
dc = new UniAddress(dc2);
break;
}
}
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController, NBT_ADDRESS_TYPE, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[NTLM_TOKEN_TYPE_FIELD_INDEX]) {
case NTLM_TOKEN_TYPE_ONE:
logger.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
logger.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
break;
case NTLM_TOKEN_TYPE_THREE:
logger.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
final byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
logger.debug("Trying to authenticate {} with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(this.principalFactory.createPrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
break;
default:
logger.debug("Unknown type: {}", src[NTLM_TOKEN_TYPE_FIELD_INDEX]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例2: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
final java.security.Principal principal;
final byte[] nextToken;
if (!this.isNTLMallowed && spnegoCredential.isNtlm()) {
throw new FailedLoginException("NTLM not allowed");
}
try {
// proceed authentication using jcifs
synchronized (this) {
this.authentication.reset();
logger.debug("Processing SPNEGO authentication");
this.authentication.process(spnegoCredential.getInitToken());
principal = this.authentication.getPrincipal();
logger.debug("Authenticated SPNEGO principal {}", principal.getName());
logger.debug("Retrieving the next token for authentication");
nextToken = this.authentication.getNextToken();
}
} catch (final jcifs.spnego.AuthenticationException e) {
throw new PreventedException(e.getMessage(), e);
}
// evaluate jcifs response
if (nextToken != null) {
logger.debug("Setting nextToken in credential");
spnegoCredential.setNextToken(nextToken);
} else {
logger.debug("nextToken is null");
}
boolean success = false;
if (principal != null) {
if (spnegoCredential.isNtlm()) {
logger.debug("NTLM Credential is valid for user [{}]", principal.getName());
} else {
logger.debug("Kerberos Credential is valid for user [{}]", principal.getName());
}
spnegoCredential.setPrincipal(getPrincipal(principal.getName(), spnegoCredential.isNtlm()));
success = true;
}
if (!success) {
throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:51,代码来源:JcifsSpnegoAuthenticationHandler.java
示例3: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected final HandlerResult doAuthentication(
final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
UniAddress dc = null;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if (this.includePattern != null) {
final NbtAddress[] dcs= NbtAddress.getAllByName(this.domainController, NBT_ADDRESS_TYPE, null, null);
for (final NbtAddress dc2 : dcs) {
if(dc2.getHostAddress().matches(this.includePattern)){
dc = new UniAddress(dc2);
break;
}
}
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController, NBT_ADDRESS_TYPE, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[NTLM_TOKEN_TYPE_FIELD_INDEX]) {
case NTLM_TOKEN_TYPE_ONE:
logger.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
logger.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
break;
case NTLM_TOKEN_TYPE_THREE:
logger.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
final byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
logger.debug("Trying to authenticate {} with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(this.principalFactory.createPrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
break;
default:
logger.debug("Unknown type: {}", src[NTLM_TOKEN_TYPE_FIELD_INDEX]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例4: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
java.security.Principal principal;
byte[] nextToken;
if (!this.isNTLMallowed && spnegoCredential.isNtlm()) {
throw new FailedLoginException("NTLM not allowed");
}
try {
// proceed authentication using jcifs
synchronized (this) {
this.authentication.reset();
this.authentication.process(spnegoCredential.getInitToken());
principal = this.authentication.getPrincipal();
nextToken = this.authentication.getNextToken();
}
} catch (final jcifs.spnego.AuthenticationException e) {
throw new FailedLoginException(e.getMessage());
}
// evaluate jcifs response
if (nextToken != null) {
logger.debug("Setting nextToken in credential");
spnegoCredential.setNextToken(nextToken);
} else {
logger.debug("nextToken is null");
}
boolean success = false;
if (principal != null) {
if (spnegoCredential.isNtlm()) {
logger.debug("NTLM Credential is valid for user [{}]", principal.getName());
} else {
logger.debug("Kerberos Credential is valid for user [{}]", principal.getName());
}
spnegoCredential.setPrincipal(getPrincipal(principal.getName(), spnegoCredential.isNtlm()));
success = true;
}
if (!success) {
throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:45,代码来源:JCIFSSpnegoAuthenticationHandler.java
示例5: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected final HandlerResult doAuthentication(
final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
UniAddress dc = null;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if(this.includePattern != null){
NbtAddress [] dcs = NbtAddress.getAllByName(this.domainController, 0x1C, null, null);
for (NbtAddress dc2 : dcs) {
if(dc2.getHostAddress().matches(this.includePattern)){
dc = new UniAddress(dc2);
break;
}
}
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController,
0x1C, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[8]) {
case 1:
logger.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
logger.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
case 3:
logger.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
logger.debug("Trying to authenticate {} with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(new SimplePrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
default:
logger.debug("Unknown type: {}", src[8]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new HandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例6: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
Principal principal;
byte[] nextToken;
if (!this.isNTLMallowed && spnegoCredential.isNtlm()) {
throw new FailedLoginException("NTLM not allowed");
}
try {
// proceed authentication using jcifs
synchronized (this) {
this.authentication.reset();
this.authentication.process(spnegoCredential.getInitToken());
principal = this.authentication.getPrincipal();
nextToken = this.authentication.getNextToken();
}
} catch (final jcifs.spnego.AuthenticationException e) {
throw new FailedLoginException(e.getMessage());
}
// evaluate jcifs response
if (nextToken != null) {
logger.debug("Setting nextToken in credential");
spnegoCredential.setNextToken(nextToken);
} else {
logger.debug("nextToken is null");
}
boolean success = false;
if (principal != null) {
if (spnegoCredential.isNtlm()) {
logger.debug("NTLM Credential is valid for user [{}]", principal.getName());
} else {
logger.debug("Kerberos Credential is valid for user [{}]", principal.getName());
}
spnegoCredential.setPrincipal(getSimplePrincipal(principal.getName(), spnegoCredential.isNtlm()));
success = true;
}
if (!success) {
throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
}
return new HandlerResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}
示例7: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
final java.security.Principal principal;
final byte[] nextToken;
if (!this.isNTLMallowed && spnegoCredential.isNtlm()) {
throw new FailedLoginException("NTLM not allowed");
}
try {
// proceed authentication using jcifs
synchronized (this) {
this.authentication.reset();
this.authentication.process(spnegoCredential.getInitToken());
principal = this.authentication.getPrincipal();
nextToken = this.authentication.getNextToken();
}
} catch (final jcifs.spnego.AuthenticationException e) {
throw new FailedLoginException(e.getMessage());
}
// evaluate jcifs response
if (nextToken != null) {
logger.debug("Setting nextToken in credential");
spnegoCredential.setNextToken(nextToken);
} else {
logger.debug("nextToken is null");
}
boolean success = false;
if (principal != null) {
if (spnegoCredential.isNtlm()) {
logger.debug("NTLM Credential is valid for user [{}]", principal.getName());
} else {
logger.debug("Kerberos Credential is valid for user [{}]", principal.getName());
}
spnegoCredential.setPrincipal(getPrincipal(principal.getName(), spnegoCredential.isNtlm()));
success = true;
}
if (!success) {
throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}
示例8: doAuthentication
import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential; //导入方法依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
Principal principal;
byte[] nextToken;
try {
// proceed authentication using jcifs
synchronized (this) {
this.authentication.reset();
this.authentication.process(spnegoCredential.getInitToken());
principal = this.authentication.getPrincipal();
nextToken = this.authentication.getNextToken();
}
} catch (final jcifs.spnego.AuthenticationException e) {
throw new FailedLoginException(e.getMessage());
}
// evaluate jcifs response
if (nextToken != null) {
logger.debug("Setting nextToken in credential");
spnegoCredential.setNextToken(nextToken);
} else {
logger.debug("nextToken is null");
}
boolean success = false;
if (principal != null) {
if (spnegoCredential.isNtlm()) {
logger.debug("NTLM Credential is valid for user [{}]", principal.getName());
spnegoCredential.setPrincipal(getSimplePrincipal(principal.getName(), true));
success = this.isNTLMallowed;
}
// else => kerberos
logger.debug("Kerberos Credential is valid for user [{}]", principal.getName());
spnegoCredential.setPrincipal(getSimplePrincipal(principal.getName(), false));
success = true;
}
if (!success) {
throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
}
return new HandlerResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}