/**
* 获取用户Details信息的回调函数.
*/
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
VgUser user = securityEntityManager.findUserByLoginName(userName);
if (user == null) {
throw new UsernameNotFoundException("用户" + userName + " 不存在");
}
// GrantedAuthority[] grantedAuths = obtainGrantedAuthorities(user);
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
// org.springframework.security.core.userdetails.User userdetail = new org.springframework.security.core.userdetails.User(
// user.getLoginName(), user.getPassword(), enabled, accountNonExpired, credentialsNonExpired,
// accountNonLocked, grantedAuths);
// List<GrantedAuthority> gas = new ArrayList<GrantedAuthority>();
// for(VgRole roles : user.getRoleList()){
// GrantedAuthorityImpl ga = new GrantedAuthorityImpl(roles.getName());
// gas.add(ga);
// }
//
// Authentication auth = new UsernamePasswordAuthenticationToken(user.getId(), null, gas.toArray(new GrantedAuthority[gas.size()]));
// SecurityContextHolder.getContext().setAuthentication(auth);
Set<GrantedAuthority> gas = grantedAuthorities(user);
UserDetails userdetail = new VgUser(user.getId(),user.getLoginName(),user.getRealName(),user.getNickname(),user.getPassword(),enabled,accountNonExpired,credentialsNonExpired,accountNonLocked,gas);
return userdetail;
}