【问题标题】:Spring rest api by-passing authenticationSpring rest api绕过认证
【发布时间】:2018-05-17 04:39:40
【问题描述】:

我有一个名为“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.&lt;intercept-url pattern="/forgotPassword" access="permitAll"/&gt;

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

2. &lt;http pattern="/forgotPassword" security="none" /&gt;

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

【问题讨论】:

    标签: spring-boot spring-security spring-ldap spring-security-ldap


    【解决方案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"));
    }
    
    }
    

    【讨论】:

    • 和你做了什么没有区别????
    • 请在备用 xml 配置中回答,因为我已经配置了...
    • URL 模式本身存在差异。
    • 我已在相应的 xml 中用“/forgotPassword/**”替换了我的 url,但仍然无法正常工作
    • 我在“/**”之后使用“/forgotPassword”拦截(已定义角色)因此覆盖
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 2014-05-31
    • 2013-02-25
    • 2013-09-28
    • 2017-05-31
    相关资源
    最近更新 更多