@Test public void requestWhenCustomSessionAuthenticationStrategyProvidedThenCalled() throws Exception { this.spring.register(CustomSessionAuthenticationStrategyConfig.class).autowire(); this.mvc.perform(formLogin().user("user").password("password")); verify(CustomSessionAuthenticationStrategyConfig.customSessionAuthenticationStrategy) .onAuthentication(any(Authentication.class), any(HttpServletRequest.class), any(HttpServletResponse.class)); }
/** * Specify both the password parameter name and the password. * * @param passwordParameter the HTTP parameter to place the password. Default is * "password". * @param password the value of the password parameter. Default is "password". * @return the {@link FormLoginRequestBuilder} for additional customizations */ public FormLoginRequestBuilder password(String passwordParameter, String password) { passwordParam(passwordParameter); this.password = password; return this; }
/** * Specify both the password parameter name and the password. * * @param usernameParameter the HTTP parameter to place the username. Default is * "username". * @param username the value of the username parameter. Default is "user". * @return the {@link FormLoginRequestBuilder} for additional customizations */ public FormLoginRequestBuilder user(String usernameParameter, String username) { userParameter(usernameParameter); this.username = username; return this; }
/** * Specify both the password parameter name and the password. * * @param passwordParameter the HTTP parameter to place the password. Default is * "password". * @param password the value of the password parameter. Default is "password". * @return the {@link FormLoginRequestBuilder} for additional customizations */ public FormLoginRequestBuilder password(String passwordParameter, String password) { passwordParam(passwordParameter); this.password = password; return this; }
/** * Creates a request (including any necessary {@link CsrfToken}) that will submit a * form based login to POST {@code loginProcessingUrl}. * * @param loginProcessingUrl the URL to POST to * * @return the FormLoginRequestBuilder for further customizations */ public static FormLoginRequestBuilder formLogin(String loginProcessingUrl) { return formLogin().loginProcessingUrl(loginProcessingUrl); }
/** * Creates a request (including any necessary {@link CsrfToken}) that will submit a * form based login to POST {@code loginProcessingUrl}. * * @param loginProcessingUrl the URL to POST to * * @return the FormLoginRequestBuilder for further customizations */ public static FormLoginRequestBuilder formLogin(String loginProcessingUrl) { return formLogin().loginProcessingUrl(loginProcessingUrl); }
/** * Creates a request (including any necessary {@link CsrfToken}) that will submit a * form based login to POST "/login". * * @return the FormLoginRequestBuilder for further customizations */ public static FormLoginRequestBuilder formLogin() { return new FormLoginRequestBuilder(); }
/** * Specify both the password parameter name and the password. * * @param usernameParameter the HTTP parameter to place the username. Default is * "username". * @param username the value of the username parameter. Default is "user". * @return the {@link FormLoginRequestBuilder} for additional customizations */ public FormLoginRequestBuilder user(String usernameParameter, String username) { userParameter(usernameParameter); this.username = username; return this; }
/** * Creates a request (including any necessary {@link CsrfToken}) that will submit a * form based login to POST "/login". * * @return the FormLoginRequestBuilder for further customizations */ public static FormLoginRequestBuilder formLogin() { return new FormLoginRequestBuilder(); }
@Test public void authenticationManagerWhenMultipleProvidersThenWorks() throws Exception { this.spring.register(MultiAuthenticationProvidersConfig.class).autowire(); this.mockMvc.perform(formLogin()) .andExpect(authenticated().withUsername("user").withRoles("USER")); this.mockMvc.perform(formLogin().user("admin")) .andExpect(authenticated().withUsername("admin").withRoles("USER", "ADMIN")); }
public void buildWhenUserFromProperties() throws Exception { this.spring.register(UserFromPropertiesConfig.class).autowire(); this.mockMvc.perform(formLogin().user("joe", "joespassword")) .andExpect(authenticated().withUsername("joe").withRoles("USER")); }