本文整理汇总了Java中org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken.getCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java PreAuthenticatedAuthenticationToken.getCredentials方法的具体用法?Java PreAuthenticatedAuthenticationToken.getCredentials怎么用?Java PreAuthenticatedAuthenticationToken.getCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken
的用法示例。
在下文中一共展示了PreAuthenticatedAuthenticationToken.getCredentials方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadUserDetails
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException {
Set<SimpleGrantedAuthority> authorities = new HashSet<SimpleGrantedAuthority>();
String credentials = (String)token.getCredentials();
for(String credential : StringUtils.split(credentials, ";")) {
if(mappingGroupesRoles != null && mappingGroupesRoles.containsKey(credential)){
authorities.add(new SimpleGrantedAuthority(mappingGroupesRoles.get(credential)));
}
}
for(String roleFromLdap : ldapGroup2UserRoleService.getRoles(token.getName())) {
authorities.add(new SimpleGrantedAuthority(roleFromLdap));
}
log.info("Shib & Ldap Credentials for " + token.getName() + " -> " + authorities);
return createUserDetails(token, authorities);
}
示例2: loadUserDetails
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
/**
* Query CA database for user with given X509Certificate and load their roles.
* If user is not found, throw a UsernameNotFoundException.
*
* @param token Must be castable to a {@link java.security.cert.X509Certificate} object
* @return UserDetails (never null)
*/
@Override
public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) {
// http://stackoverflow.com/questions/14563397/spring-security-x-509-authentication-without-user-service
X509Certificate certificate = (X509Certificate) token.getCredentials();
String dn = certificate.getSubjectDN().toString();
// Convert provided DN to rfc2253 style (commas with no spaces)
// from: "CN=david meredith, L=DL, OU=CLRC, O=eScience, C=UK"
// to: "CN=david meredith,L=DL,OU=CLRC,O=eScience,C=UK"
dn = dn.replaceAll(", ", ",");
BigInteger serial = certificate.getSerialNumber();
log.info("Auth request for dn: [" + dn + "] serial: [" + serial.toString() + "]");
CertificateRow cr = this.jdbcCertDao.findById(serial.longValue());
if (cr != null) {
List<GrantedAuthority> auths = this.securityContextService.getGrantedAuthorities(cr);
return new CaUser(dn, true, true, true, true, auths, cr);
}
throw new UsernameNotFoundException("User Not found [" + dn + "] ["+serial.toString()+"]");
}
示例3: createUserContext
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
private UserContext createUserContext(PreAuthenticatedAuthenticationToken authentication) {
X509Certificate certificate = (X509Certificate) authentication.getCredentials();
return new UserContext(
certificate.getNotBefore().toInstant().getEpochSecond(),
certificate.getNotAfter().toInstant().getEpochSecond(),
certificate.getSubjectDN().getName(),
UserContext.AUTH_METHOD_MUTUAL_TLS
);
}
示例4: authenticate
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; //导入方法依赖的package包/类
@Override
public Authentication authenticate(final Authentication authentication) {
if (!supports(authentication.getClass())) {
return null;
}
final PreAuthenticatedAuthenticationToken token = (PreAuthenticatedAuthenticationToken) authentication;
final Object credentials = token.getCredentials();
final Object principal = token.getPrincipal();
final Object tokenDetails = token.getDetails();
final Collection<GrantedAuthority> authorities = token.getAuthorities();
if (principal == null) {
throw new BadCredentialsException("The provided principal and credentials are not match");
}
final boolean successAuthentication = calculateAuthenticationSuccess(principal, credentials, tokenDetails);
if (successAuthentication) {
final PreAuthenticatedAuthenticationToken successToken = new PreAuthenticatedAuthenticationToken(principal,
credentials, authorities);
successToken.setDetails(tokenDetails);
return successToken;
}
throw new BadCredentialsException("The provided principal and credentials are not match");
}