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


Java CasAssertionAuthenticationToken类代码示例

本文整理汇总了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);
}
 
开发者ID:jgribonvald,项目名称:demo-spring-security-cas,代码行数:24,代码来源:CustomUserDetailsService.java

示例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;
}
 
开发者ID:mouxiao,项目名称:shootmimi,代码行数:14,代码来源:CustomUserDetailsService.java

示例5: customUserDetailsService

import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
/**
 * 用户自定义的AuthenticationUserDetailsService
 */
@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> customUserDetailsService() {
    return new CustomUserDetailsService();
}
 
开发者ID:mouxiao,项目名称:shootmimi,代码行数:8,代码来源:CasSecurityConfig.java

示例6: customUserDetailsService

import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken; //导入依赖的package包/类
@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> customUserDetailsService() {
	return new CustomUserDetailsService(adminList());
}
 
开发者ID:jgribonvald,项目名称:demo-spring-security-cas,代码行数:5,代码来源:SecurityConfiguration.java


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