public UserDetailsRequestPostProcessor(UserDetails user) { Authentication token = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities()); this.delegate = new AuthenticationRequestPostProcessor(token); }
@Override public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(this.authentication); save(this.authentication, request); return request; } }
/** * Establish a {@link SecurityContext} that uses the specified {@link Authentication} * for the {@link Authentication#getPrincipal()} and a custom {@link UserDetails}. All * details are declarative and do not require that the user actually exists. * * <p> * The support works by associating the user to the HttpServletRequest. To associate * the request to the SecurityContextHolder you need to ensure that the * SecurityContextPersistenceFilter is associated with the MockMvc instance. A few * ways to do this are: * </p> * * <ul> * <li>Invoking apply {@link SecurityMockMvcConfigurers#springSecurity()}</li> * <li>Adding Spring Security's FilterChainProxy to MockMvc</li> * <li>Manually adding {@link SecurityContextPersistenceFilter} to the MockMvc * instance may make sense when using MockMvcBuilders standaloneSetup</li> * </ul> * * @param authentication the Authentication to populate * @return the {@link RequestPostProcessor} to use */ public static RequestPostProcessor authentication(Authentication authentication) { return new AuthenticationRequestPostProcessor(authentication); }
/** * Establish a {@link SecurityContext} that uses the specified {@link Authentication} * for the {@link Authentication#getPrincipal()} and a custom {@link UserDetails}. All * details are declarative and do not require that the user actually exists. * * <p> * The support works by associating the user to the HttpServletRequest. To associate * the request to the SecurityContextHolder you need to ensure that the * SecurityContextPersistenceFilter is associated with the MockMvc instance. A few * ways to do this are: * </p> * * <ul> * <li>Invoking apply {@link SecurityMockMvcConfigurers#springSecurity()}</li> * <li>Adding Spring Security's FilterChainProxy to MockMvc</li> * <li>Manually adding {@link SecurityContextPersistenceFilter} to the MockMvc * instance may make sense when using MockMvcBuilders standaloneSetup</li> * </ul> * * @param authentication the Authentication to populate * @return the {@link RequestPostProcessor} to use */ public static RequestPostProcessor authentication(Authentication authentication) { return new AuthenticationRequestPostProcessor(authentication); }
@Override public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { return this.delegate.postProcessRequest(request); } }
@Override public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { return this.delegate.postProcessRequest(request); } }
public UserDetailsRequestPostProcessor(UserDetails user) { Authentication token = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities()); this.delegate = new AuthenticationRequestPostProcessor(token); }
@Override public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(this.authentication); save(this.authentication, request); return request; } }