0

我有一个名为“abc”的模块,它具有用于用户身份验证的安全功能

并且用户名和密码通过 ldap 服务器进行身份验证

<authentication-manager alias="authenticationManager" erase-credentials="false">
<authentication-provider ref="preAuthenticatedLdapAuthenticationProvider" />

<ldap-server id="ldapServerIDGreenBus" url="${ldap.URL}/${ldap.Base}"
    manager-dn="${ldap.Username}" manager-password="${ldap.Password}" />

我正在为所有具有任何角色的用户截取 url 模式。

问题:我在此模块中内置了忘记密码服务,在用户登录之前,因此没有定义任何角色,我只接收用户的电子邮件,以便我可以更改密码并将其发送到用户的主要地址。

因此,我尝试了两件事

1.<intercept-url pattern="/forgotPassword" access="permitAll"/>

结果:失败,因为 permitAll 确实进行了身份验证,但它允许所有模式,前提是它们必须具有身份验证对象(用户名和密码)。

2. <http pattern="/forgotPassword" security="none" />

结果:失败并在邮递员中检查并显示了这一点

安全认证错误

4

1 回答 1

1

您也可以使用可覆盖的“配置”方法在 SecurityConfig 文件中定义权限。我会尝试这样的事情。我在下面添加了匹配的“forgotPassword”网址。

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(authProvider);
}

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests() 
            .antMatchers("/forgotPassword/**").permitAll()
            .antMatchers("/**").hasRole("USER") 
            .anyRequest().authenticated()
            .and()          
        .formLogin()
            .loginPage("/login")
            .successForwardUrl("/loginSuccess")
            .failureUrl("/loginError")
            .permitAll()                
            .and()
        .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
}

}
于 2018-05-17T16:16:38.597 回答