gpt4 book ai didi

java - spring mvc 的 LDAP 身份验证

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:11 26 4
gpt4 key购买 nike

我正在尝试使用我的数据库中的角色在 java 配置 ldap 授权中设置。我的设置是

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity( prePostEnabled = true, securedEnabled = true )
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.
.
.
@Bean
public UserDetailsContextMapper userDetailsContextMapper() {
return new UserDetailsContextMapper() {
@Override
public UserDetails mapUserFromContext(
DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities) {
String lowercaseLogonName = username.toLowerCase();
Optional<PtolUser> userFromDatabase =
ptolUserRepository.findOneByLogonName(lowercaseLogonName);
return userFromDatabase.map(user ->
{
if (!user.isAccountNonExpired()) {
throw new UserNotActivatedException(
"User " + lowercaseLogonName + " was not activated");
}
List<GrantedAuthority> grantedAuthorities = user.getUserAuthorities().parallelStream()
.map(authority -> new SimpleGrantedAuthority(authority.getRole().getName()))
.collect(Collectors.toList());
return new org.springframework.security.core.userdetails.User(lowercaseLogonName,
user.getPassword(), true, user.isAccountNonExpired(), true,
user.isAccountNonLocked(), grantedAuthorities);
}).orElseThrow(
() -> new UsernameNotFoundException(
"User " + lowercaseLogonName + " was not found in the AD"));
}

@Override
public void mapUserToContext(UserDetails user, DirContextAdapter ctx) {
throw new IllegalStateException("Only retrieving data from LDAP is currently supported");
}

};
}
.
.
.
@Bean
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth//
.ldapAuthentication()//
// .userDetailsService(userDetailsService)//
.userDetailsContextMapper(userDetailsContextMapper())//
.userDnPatterns(env.getRequiredProperty("ldap.user_dn_patterns"))//
.groupSearchBase(env.getRequiredProperty("ldap.group_search_base"))//
.groupSearchFilter(env.getRequiredProperty("ldap.group_search_filter"))//
.contextSource()//
.ldif("ptolemaios.ldif");
}
.
.
.
}

但我有以下警告/错误(2次)

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configureGlobal' defined in class path resource [com/ppc/ptol2/config/SecurityConfiguration.class]: Invalid factory method 'configureGlobal': needs to have a non-void return type!

最佳答案

public void configureGlobal(AuthenticationManagerBuilder auth) 方法中删除 @Bean 注释(并添加 @Override 注释)

关于java - spring mvc 的 LDAP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35463554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com