【发布时间】:2020-12-01 00:30:39
【问题描述】:
我的应用程序中有两个不同的用户。 ldap 用户和 api 用户。 Ldap 用户有权访问一个端点,而 api 用户有权访问不同的端点。我已经使用 UserDetailsService 实现了 api 用户身份验证,并在我的 application.yaml 文件中有详细信息。 我现在面临的问题是,只有 Ldap 用户应该访问的端点现在也被我的 api 用户访问。我该如何防止这种情况。请在下面找到我的代码 sn-p
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();
}
}
【问题讨论】:
-
从您的代码中,我无法判断为哪个用户组创建了哪个端点,但是如果您想将它们分开,请给 api 用户一个角色
api,给 ldap 用户一个角色ldap然后使用这些角色保护您的端点.antMatchers("ldap_endpoint").hasRole("ldap").antMatchers("api_endpoint").hasRole("api") -
@Am我已经编辑了我的帖子
标签: spring spring-boot security active-directory ldap