ActiveDirectoryLdapAuthenticationProvider和使用userDetailsService的身份验证

J

我的应用程序中有两个不同的用户。Ldap用户和api用户。Ldap用户具有访问端点的权限,而api用户则具有不同的端点的权限。我已经使用UserDetailsS​​ervice实现了api用户身份验证,并在我的application.yaml文件中包含了详细信息。我现在面临的问题是,我的api用户也正在访问只有Ldap用户应访问的终结点。我该如何预防。请在下面找到我的代码段

public class ServiceSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    @Qualifier("ldapProvider")
    private AuthenticationProvider authenticationProvider;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

// security for apiuser
              http
                .authorizeRequests()
                .antMatchers(“/abcd/**).hasRole(“admin”)
                .and()
                .httpBasic().and().userDetailsService(userDetailsService());
      

// security for ldap users
        http
                .csrf().disable()
                .authorizeRequests()
                .antMatchers(“/ghhgh” + "/**").fullyAuthenticated()
                .antMatchers("/login*").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().and()
                .authenticationProvider(authenticationProvider)
                .exceptionHandling();
    }

    public UserDetailsService userDetailsService() {

        UserDetails user = User.withUsername(“api”)
                .password(passwordEncoder().encode(“test”))
                .roles(“admin”)
              return new InMemoryUserDetailsManager(user);
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}
阿米尔·施奈尔

在春季安全性中,确实有可能注册多个身份验证机制。

但是您不能将特定的身份验证提供程序注册到特定的路由。
春天的安全文档说:

ProviderManager是的最常用实现AuthenticationManagerProviderManager委托给ListAuthenticationProviders每个人AuthenticationProvider都有机会表明认证应该成功,失败,或者表明它不能做出决定并允许下游AuthenticationProvider进行决定。

因此,在每个请求中,AuthenticationProvider都将一个接一个地检查注册的s,直到一个成功或全部失败。

要解决您的问题,您需要定义多个自定义权限,并为您分配用户。
然后,您可以使用这些权限保护端点。

例如,您赋予每个ldap用户权限LDAP_USER和每个api用户权限API_USER然后,您可以相应地配置安全性:

注册所有AuthenticationProvider:


@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.authenticationProvider(ldapProvider);
        auth.userDetailsService(userDetailsService());
    }

并配置端点:


@Override
protected void configure(HttpSecurity http) throws Exception {


    http
      (...)
      .authorizeRequests()

// security for apiuser
      .antMatchers(“/abcd/**).hasRole(“API_USER”)

// security for ldap users
      .antMatchers(“/ghhgh” + "/**").hasRole("LDAP_USER")
      (...)
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用UserDetailsService的Spring Security身份验证

来自分类Dev

使用ASP身份的会话和用户身份验证

来自分类Dev

使用Passport.js验证角色和身份验证

来自分类Dev

使用ASP.NET身份验证和LDAP的身份验证/授权

来自分类Dev

如何同时使用内部窗体身份验证和Azure AD身份验证

来自分类Dev

混合使用Azure AD身份验证和Forms身份验证

来自分类Dev

使用 Devise 在 Rails 中划分经过身份验证和未经身份验证的布局

来自分类Dev

HttpWebRequest和身份验证

来自分类Dev

Express 身份验证和护照身份验证

来自分类Dev

结合使用Django模板和用户身份验证

来自分类Dev

如何使用Node和Express对github进行身份验证

来自分类Dev

使用Spring Security无需身份验证和授权

来自分类Dev

使用OWIN SelfHost和Facebook身份验证

来自分类Dev

使用机构和Microsoft帐户的Azure AD身份验证

来自分类Dev

使用TLS和Python进行身份验证

来自分类Dev

使用python和selenium的随机银行类型身份验证

来自分类Dev

MVC 5和使用声明的默认身份验证

来自分类Dev

使用Devise和MongoMapper进行Rails 4身份验证

来自分类Dev

如何同时使用Cookie和BASIC身份验证?

来自分类Dev

使用Go和AngularJS进行用户身份验证

来自分类Dev

使用devise和twitter API的Twitter身份验证

来自分类Dev

使用Silex和Symfony 3配置LDAP身份验证

来自分类Dev

API身份验证和OAuth2的使用

来自分类Dev

使用AFHTTPSessionManager和身份验证下载文件

来自分类Dev

Soap身份验证标头和使用PHP的请求

来自分类Dev

使用Cakephp和PhoneGap进行身份验证

来自分类Dev

使用Symfony 2.8和3.1的LDAP HTTP身份验证

来自分类Dev

使用Google登录和SwiftUI检查用户身份验证

来自分类Dev

使用GraphQL和Django进行身份验证

Related 相关文章

热门标签

归档