当我想向Spring java发出请求时,为什么会出现错误403?

时间:2020-05-07 05:43:28

标签: spring spring-security ldap postman spring-ldap

我使用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");
}

}

0 个答案:

没有答案