繁体   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