我使用下面的方法來讓用戶授予權限總是:ROLE_ANONYMOUS?
private void autoLogin(User user,
HttpServletRequest request)
{
GrantedAuthority[] grantedAuthorities = new GrantedAuthority[] { new GrantedAuthorityImpl(
"ROLE_ADMIN") };
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
user.getUsername(), user.getPassword(),grantedAuthorities);
// generate session if one doesn't exist
request.getSession();
token.setDetails(new WebAuthenticationDetails(request));
Authentication authenticatedUser = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
}
用戶通過認證註冊後的綱領性登錄,但總是有ROLE_ANONYMOUS我不知道爲什麼? 有什麼想法?
我認爲這是因爲頁面requries ROLE_ADMIN主體和認證後的用戶角色是匿名的,任何人都知道如何在登錄時使用戶主體爲管理員? – 2010-10-13 12:14:38