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


Java UsernamePasswordAuthenticationToken.getAuthorities方法代码示例

本文整理汇总了Java中org.springframework.security.authentication.UsernamePasswordAuthenticationToken.getAuthorities方法的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordAuthenticationToken.getAuthorities方法的具体用法?Java UsernamePasswordAuthenticationToken.getAuthorities怎么用?Java UsernamePasswordAuthenticationToken.getAuthorities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.authentication.UsernamePasswordAuthenticationToken的用法示例。


在下文中一共展示了UsernamePasswordAuthenticationToken.getAuthorities方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUserVO

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
@Transactional
public AitUserVO getUserVO() {
	UsernamePasswordAuthenticationToken principal = getAitPrincipal();

	Map<String, String> details = (Map<String, String>) principal.getDetails();

	String username = getUsername();

	AitUser user = userRepo.getByUsername(username);
	// se crea el usuario si no existe
	if (user == null) {
		logger.info("Creating new user {}", username);
		user = new AitUser();
		user.setUsername(username);
		user.setFirstName(details.get("given_name"));
		user.setLastName(details.get("family_name"));
		user.setEmail(details.get("email"));
		user.setEnabled(true);
	}
	AitUserVO userVO = new AitUserVO();
	try {
		BeanUtils.copyProperties(user, userVO);
		SecurityContextHolder.getContext().getAuthentication();
		// se crea el menu del usuario
		Collection<GrantedAuthority> authorities = principal.getAuthorities();
		if (!authorities.isEmpty()) {
			StringBuffer sb = new StringBuffer();
			for (GrantedAuthority auth : authorities) {
				userVO.getRoles().add(auth.getAuthority());
				sb.append(",").append(auth.getAuthority()).append(",");
			}
			user.setUserRoles(sb.toString());
			logger.info("Loading user menu for authorities: {}", authorities);
			List<AitMenu> menuList = menuRepo.findRootOpts();
			for (AitMenu menuOpc : menuList) {
				AitMenuVO opc = new AitMenuVO();
				BeanUtils.copyProperties(menuOpc, opc, "children");
				if (hasAuthority(opc, menuOpc.getChildren(), authorities)) {
					userVO.getMenu().add(opc);
				}
			}
		}
		userRepo.save(user);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return userVO;
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:51,代码来源:AitUserSrv.java


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