The easiest way to log a user in is to set the Authentication on the SecurityContextHolder's context. For example:
Code:
Authentication authentication = new UsernamePasswordAuthenticationToken("username", "password",
AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContextHolder.getContext().setAuthentication(authentication);
Note that in many instances Spring Security uses a User object as the principal instead of "username". However, depending on your usecase "username" will work just fine.