我正在開(kāi)發(fā)一個(gè)帶有基于注釋的配置的 spring 安全代碼。但是,在從登錄頁(yè)面點(diǎn)擊WebSecurityConfig類(擴(kuò)展WebSecurityConfigurerAdapter )的配置方法中定義的登錄處理 url 后,即使提供了正確的用戶名和密碼,它也總是重定向到httpSecurity 的.failureHandler()方法而不是.successHandler ( ) 方法。下面是WebSecurityConfig類的configure方法和configureGlobal方法。@Overrideprotected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity .authorizeRequests() .antMatchers("/login.success").access("hasRole('ROLE_USER')") .and() .formLogin() .loginPage("/login.home") .usernameParameter("username") .passwordParameter("password") .loginProcessingUrl("/login.do") .successHandler(applicationLoginSuccessHandler) .failureHandler(applicationLoginFailureHandler) .and() .logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));}@Autowiredpublic void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { authenticationManagerBuilder.inMemoryAuthentication().withUser("user").password("pass").roles("USER");} 這是login.jsp的片段<c:url value="login.do" var="loginUrl"/><form action="${loginUrl}" method="POST"> <c:if test="${param.error != null}"> <p> Invalid username and password. </p> </c:if> <c:if test="${param.logout != null}"> <p> You have been logged out. </p> </c:if> <p> <label for="username">Username</label> <input type="text" id="username" name="username"/> </p> <p> <label for="password">Password</label> <input type="password" id="password" name="password"/> </p> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <button type="submit" class="btn">Log in</button> </form> 我錯(cuò)過(guò)了什么?我正在使用彈簧安全 5.1.2.release
Spring Security 自定義登錄處理 URL 始終重定向到故障處理程序
哆啦的時(shí)光機(jī)
2022-06-15 15:37:58