大家好,我正在嘗試使用 spring boot 2 和 thymeleaf 3 制作自定義登錄表單,應(yīng)用程序有 2 個(gè)安全配置,一個(gè)用于移動(dòng)應(yīng)用程序用戶,另一個(gè)用于餐廳,這是一個(gè) Web 應(yīng)用程序。我正在為餐廳端實(shí)現(xiàn)自定義登錄表單,但是當(dāng)?shù)卿洷韱螘r(shí)提交 spring 嘗試查找 localhost:8080/{loginprocessingurl} 并導(dǎo)致 404 錯(cuò)誤。以下是我的表單、控制器和安全配置:@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") ; }當(dāng)我查看源頁(yè)面時(shí),我看到 thymeleaf 沒(méi)有注入 csrf 令牌輸入。我使用 thymeleaf extras springsecurity 版本 3.0.4,如果我在表單中編寫 csrf 輸入<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />,它給我這個(gè)錯(cuò)誤:EL1007E:在null上找不到屬性或字段'parameterName'事情是我知道spring應(yīng)該在背面處理登錄處理url并進(jìn)行身份驗(yàn)證(我實(shí)現(xiàn)了UserDetailsService并覆蓋WebSecurityConfigurationAdapter 的 configureGlobal 方法我是如何正確知道的,因?yàn)橐苿?dòng)應(yīng)用程序請(qǐng)求運(yùn)行良好(另一個(gè) @Configuration 類))而是在成功 url 上重定向我,它嘗試呈現(xiàn)該登錄處理 url。另一件事當(dāng)我不使用自定義登錄處理 url 而是使用默認(rèn) /login 發(fā)布登錄表單時(shí),它說(shuō) 405 方法不允許,但我在網(wǎng)絡(luò)上嘗試的所有其他示例都是這樣工作的,甚至在開始 Spring Boot K.Siva Prasad Reddy 的 2 本書,我做了表單登錄前。就像我上面所說(shuō)的那樣寫,就像魅力一樣!每個(gè)依賴版本都是一樣的!我一直在處理這 2 天,到處搜索,但找不到解決方案,所以每一個(gè)想法和建議都會(huì)受到贊賞。
Spring Boot 嘗試渲染登錄處理 url
慕尼黑8549860
2022-07-27 09:29:14