本文整理汇总了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;
}