大家好,我正在嘗試使用 spring boot 2 和 thymeleaf 3 制作自定義登錄表單,應用程序有 2 個安全配置,一個用于移動應用程序用戶,另一個用于餐廳,這是一個 Web 應用程序。我正在為餐廳端實現自定義登錄表單,但是當登錄表單時提交 spring 嘗試查找 localhost:8080/{loginprocessingurl} 并導致 404 錯誤。以下是我的表單、控制器和安全配置:@Configuration @Order(2) // no order means order of config value is last public static class RestaurantSecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception{ http.csrf().and() .antMatcher("/restaurant/**") //antmatcher tekil ?ekilde urlleri farkl? configler i?in gruplamada kullan?l?r .authorizeRequests() .antMatchers("/assets/**", "/webjars/**","/static/**").permitAll() .anyRequest().hasRole("RESTAURANT") .and() .formLogin() .loginPage("/login") .loginProcessingUrl("/restaurant/reslogin") .failureUrl("/restaurant/login?error") .defaultSuccessUrl("/restaurant/tables",true) .permitAll() .and() .logout() .logoutUrl("/restaurant/logout") .deleteCookies("JSESSIONID") ; }當我查看源頁面時,我看到 thymeleaf 沒有注入 csrf 令牌輸入。我使用 thymeleaf extras springsecurity 版本 3.0.4,如果我在表單中編寫 csrf 輸入<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />,它給我這個錯誤:EL1007E:在null上找不到屬性或字段'parameterName'事情是我知道spring應該在背面處理登錄處理url并進行身份驗證(我實現了UserDetailsService并覆蓋WebSecurityConfigurationAdapter 的 configureGlobal 方法我是如何正確知道的,因為移動應用程序請求運行良好(另一個 @Configuration 類))而是在成功 url 上重定向我,它嘗試呈現該登錄處理 url。另一件事當我不使用自定義登錄處理 url 而是使用默認 /login 發布登錄表單時,它說 405 方法不允許,但我在網絡上嘗試的所有其他示例都是這樣工作的,甚至在開始 Spring Boot K.Siva Prasad Reddy 的 2 本書,我做了表單登錄前。就像我上面所說的那樣寫,就像魅力一樣!每個依賴版本都是一樣的!我一直在處理這 2 天,到處搜索,但找不到解決方案,所以每一個想法和建議都會受到贊賞。
Spring Boot 嘗試渲染登錄處理 url
慕尼黑8549860
2022-07-27 09:29:14