簡體   English   中英

使用 Spring 保護應用程序安全不起作用

[英]Securing app with Spring Security doesn't work

我寫了一個簡單的后端軟件,我想用 Spring Security 和 LDAP 來保護它。 很明顯,項目的 LDAP 部分工作正常。 問題是,當我使用formLogin()輸入時,它不起作用,當我使用 postman 時,它顯示結果而不詢問用戶名和密碼! 我認為我的webSecurityConfig中有問題。 這是我的webSecurityConfig代碼:

@Configuration public class WebSecurityConfig 擴展 WebSecurityConfigurerAdapter {

 @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable().authorizeRequests().antMatchers("/**").permitAll().anyRequest().fullyAuthenticated(); } @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.ldapAuthentication().userDnPatterns("uid={0},ou=people").groupSearchBase("ou=people").contextSource().url("ldap://localhost:10389/dc=example,dc=com").and().passwordCompare().passwordEncoder(new LdapShaPasswordEncoder() { }).passwordAttribute("userPassword"); } }

使用@EnableWebSecurity啟用 Spring 安全性。

@Configuration 
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

}

並從您的配置中刪除.antMatchers("/**").permitAll() ,因為它匹配所有請求。 此構造通常用於指定特定的白名單端點,例如不需要安全性的 static 文檔:

.antMatchers("/docs/**").permitAll()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM