无法在spring boot security中登录我的自定义登录页面

gs_*_*lad 5 java jsp spring-mvc spring-security spring-boot

我的问题是:当我尝试登录我的自定义登录页面时,它会再次将我重定向到登录页面(如果我输入正确或错误的凭据,则无关紧要).在调试中我没有达到我的自定义UserDetailService也很奇怪,我认为这意味着spring甚至不会检查用户的凭据.

我有自定义登录表单/WEB-INF/jsp/login.jsp:

...    
<form name='loginForm' action="<c:url value='j_spring_security_check' />" method='POST'>

        <table>
            <tr>
                <td>User:</td>
                <td><input type='text' name='j_username' value=''></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type='password' name='j_password' /></td>
            </tr>
            <tr>
                <td colspan='2'><input name="submit" type="submit"
                                       value="submit" /></td>
            </tr>
        </table>

        <input type="hidden" name="${_csrf.parameterName}"
               value="${_csrf.token}" />

    </form>
...
Run Code Online (Sandbox Code Playgroud)

这是配置:

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests().antMatchers("/", "/welcome", "/resources/**").permitAll()
                .anyRequest().authenticated().and()
                .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and()
                .logout().logoutUrl("/login?logout").permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是控制器内部:

@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    ModelAndView model = new ModelAndView();
    if (error != null) {
        model.addObject("error", "Invalid username and password!");
    }

    if (logout != null) {
        model.addObject("msg", "You've been logged out successfully.");
    }
    model.setViewName("login");

    return model;

}
Run Code Online (Sandbox Code Playgroud)

src/main/resources/application.properties我有:

spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
Run Code Online (Sandbox Code Playgroud)

Dav*_*yer 8

这些j_spring_security_check,j_username,j_password名字都是旧的默认值(预春季安全3.2).

默认值现在:login,usernamepassword.