本文整理汇总了Java中org.springframework.security.cas.authentication.CasAssertionAuthenticationToken类的典型用法代码示例。如果您正苦于以下问题:Java CasAssertionAuthenticationToken类的具体用法?Java CasAssertionAuthenticationToken怎么用?Java CasAssertionAuthenticationToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CasAssertionAuthenticationToken类属于org.springframework.security.cas.authentication包,在下文中一共展示了CasAssertionAuthenticationToken类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadUserDetails
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
@Override
public UserDetails loadUserDetails(CasAssertionAuthenticationToken token) throws UsernameNotFoundException {
String login = token.getPrincipal().toString();
String lowercaseLogin = login.toLowerCase();
log.debug("Authenticating '{}'", login);
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
if (admins != null && admins.contains(lowercaseLogin)) {
grantedAuthorities.add(new SimpleGrantedAuthority(AuthoritiesConstants.ADMIN));
} else {
grantedAuthorities.add(new GrantedAuthority() {
private static final long serialVersionUID = 1L;
@Override
public String getAuthority() {
return AuthoritiesConstants.USER;
}
});
}
return new AppUserDetails(lowercaseLogin, grantedAuthorities);
}
示例2: correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
@Test
public void correctlyExtractsNamedAttributeFromAssertionAndConvertsThemToAuthorities() {
GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds
= new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService();
uds.setConvertToUpperCase(false);
uds.setConvertSpacesToUnderscores(false);
uds.setAttribute("a");
uds.setRolePrefix("");
Assertion assertion = mock(Assertion.class);
AttributePrincipal principal = mock(AttributePrincipal.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put("a", Arrays.asList("CN=role_a1,OU=roles,DC=spring,DC=io", "CN=role_a2,OU=roles,DC=spring,DC=io"));
attributes.put("b", "b");
attributes.put("c", "c");
attributes.put("d", null);
attributes.put("someother", "unused");
when(assertion.getPrincipal()).thenReturn(principal);
when(principal.getAttributes()).thenReturn(attributes);
when(principal.getName()).thenReturn("somebody");
CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
UserDetails user = uds.loadUserDetails(token);
Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
assertTrue(roles.size() == 2);
assertTrue(roles.contains("role_a1"));
assertTrue(roles.contains("role_a2"));
}
开发者ID:acu-dev,项目名称:spring-security-cas-memberOf-roles,代码行数:27,代码来源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java
示例3: correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
@Test
public void correctlyExtractsDefaultNamedAttributeFromAssertionAndConvertsThemToAuthorities() {
GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService uds
= new GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsService();
Assertion assertion = mock(Assertion.class);
AttributePrincipal principal = mock(AttributePrincipal.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put("memberOf", Arrays.asList("CN=a1,ou=other,OU=roles,DC=spring,DC=io", "CN=a2,OU=roles,dc=spring,DC=io", null));
attributes.put("someother", "unused");
when(assertion.getPrincipal()).thenReturn(principal);
when(principal.getAttributes()).thenReturn(attributes);
when(principal.getName()).thenReturn("somebody");
CasAssertionAuthenticationToken token = new CasAssertionAuthenticationToken(assertion, "ticket");
UserDetails user = uds.loadUserDetails(token);
Set<String> roles = AuthorityUtils.authorityListToSet(user.getAuthorities());
assertTrue(roles.size() == 2);
assertTrue(roles.contains("ROLE_A1"));
assertTrue(roles.contains("ROLE_A2"));
}
开发者ID:acu-dev,项目名称:spring-security-cas-memberOf-roles,代码行数:20,代码来源:GrantedAuthorityFromMemberOfAssertionAttributeUserDetailsServiceTest.java
示例4: loadUserDetails
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
@Override
public UserDetails loadUserDetails(CasAssertionAuthenticationToken token) throws UsernameNotFoundException {
System.out.println("当前的用户名是:" + token.getName());
/*这里我为了方便,就直接返回一个用户信息,实际当中这里修改为查询数据库或者调用服务什么的来获取用户信息*/
UserInfo userInfo = new UserInfo();
userInfo.setUsername("admin");
userInfo.setName("admin");
Set<AuthorityInfo> authorities = new HashSet<AuthorityInfo>();
AuthorityInfo authorityInfo = new AuthorityInfo("TEST");
authorities.add(authorityInfo);
userInfo.setAuthorities(authorities);
return userInfo;
}
示例5: customUserDetailsService
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
/**
* 用户自定义的AuthenticationUserDetailsService
*/
@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> customUserDetailsService() {
return new CustomUserDetailsService();
}
示例6: customUserDetailsService
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> customUserDetailsService() {
return new CustomUserDetailsService(adminList());
}