[英]Spring security : configure JWT with formLogin
我正在嘗試使用 formLogin 身份驗證配置 JWT 過濾器。 (我的服務器為UI客戶端提供服務(這就是為什么我需要FormLogin),並且我也將Rest終點點(由Z1D1D1FADBD91FADBD9150349C135781140FFEESTENTING YERYEN -Z1DZ)YS19D711D.11D.11D.11D.11D.11。
這是我的配置方法:登錄后 -> 如果我試圖到達 /kuku 路徑 - 我得到 302 並再次登錄頁面。
如果我要刪除 addFilterBefore -> 我的角色工作正常。
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests()
.antMatchers("/login").permitAll()
.antMatchers("/").hasRole("ADMIN")
.antMatchers("/kuku/**").hasRole("ADMIN")
.anyRequest()
.authenticated()
.and()
.formLogin().defaultSuccessUrl("/inital.html", true)
;
http.addFilterBefore(new JwtFilter(), UsernamePasswordAuthenticationFilter.class);
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
String userName = "Admin"; // currently due to Vault IMPL - this input is hardcoded .
String password ="Admin"
auth.inMemoryAuthentication()
.withUser(userName).password(passwordEncoder().encode(password))
.roles("ADMIN");
}
嘗試將csrf().disable()添加到您的configure(http)方法中。 這適用於我的情況,我的配置與您的配置相似。 雖然,我建議搜索這是否安全,因為這會禁用內置的 csrf 保護。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.