ITeye博客

Simulate login from spring web mvc controller

pentium100 · 2012-02-14 15:50 · JAVA · 行业应用 · Markdown

code as below: [code="java"] List grantedAuthorities = new ArrayList(); grantedAuthorities.add(new GrantedAuthorityImpl("USER")); UsernamePasswordAuthenticationToken uat = new UsernamePasswordAuthenticationToken( "john", "admin", grantedAuthorities); uat.setDetails(user); SecurityContext context = SecurityContextHolder.getContext(); Authentication userAuth = authenticationManager.authenticate(uat); context.setAuthentication(userAuth); [/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。