• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CasAssertionAuthenticationToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TileEntityBrewingStand类代码示例发布时间:2022-05-22
下一篇:
Java UIUtils类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap