我使用Java Spring启动了一个不安全的应用程序,并且产生了正确的结果。在那之后,我获得了Spring Security的保护,并且获得了完全的成功,并且能够使用浏览器和嵌入式formLogin()
获得结果。在下一步中,我想删除formLogin()
以便仅通过前端访问我的服务。当我尝试通过邮递员使用服务时,总是收到错误403。我认为问题出在我的WebSecurityConfig
文件中。所以我发布了它:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().fullyAuthenticated();
//.and()
//.formLogin();
}
@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");
}
}