当前位置: 首页>>代码示例>>Java>>正文


Java PreAuthenticatedAuthenticationToken.getCredentials方法代码示例

本文整理汇总了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);
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:15,代码来源:ShibAuthenticatedUserDetailsService.java

示例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()+"]");
}
 
开发者ID:UKCA,项目名称:CAPortal,代码行数:27,代码来源:CaX509JdbcPreAuthUserDetails.java

示例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
  );
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:11,代码来源:UserContextFactory.java

示例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");
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:28,代码来源:PreAuthTokenSourceTrustAuthenticationProvider.java


注:本文中的org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken.getCredentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。