---
title: "Simulate login from spring web mvc controller"
author: "pentium100"
date: "2012-02-14T15:50:57Z"
tags: []
categories: ["行业应用"]
slug: "simulate-login-from-spring-web-mvc-controller"
draft: false
lastmod: "2012-02-14T15:50:57Z"
id: 1405627
url: "https://pentium100.iteye.com/blog/1405627"
---

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]