В моем веб-приложении Spring я не могу получить правильный objectId
от текущего вошедшего в систему пользователя с учетной записью Active Directory.Кажется, что все атрибуты имеют правильное значение, но значение objectId
всегда установлено на S-1-5-21-1723711471-3183472479-4012130053-3220159935
, и я не знаю, откуда оно.
WebSecurityConfig
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
private ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider =
new ActiveDirectoryLdapAuthenticationProvider(LdapConfig.AD_DOMAIN, LdapConfig.AD_SERVER);
provider.setUserDetailsContextMapper(new LdapUserDetailsContextMapper());
return provider;
}
}
LdapUserDetailsContextMapper
@Slf4j
public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> collection) {
log.info("username: " + username); //username is correct
log.info("DN from ctx: " + ctx.getDn()); // returns correct DN
byte[] byteSid = ctx.getStringAttribute("objectSid").getBytes();
String sid = LdapUtils.convertBinarySidToString(byteSid);
log.info("SID: " + sid); // S-1-5-21-1723711471-3183472479-4012130053-3220159935 everytime
return new User(username, "notUsed", true, true, true, true,
AuthorityUtils.createAuthorityList("ROLE_USER"));
}
@Override
public void mapUserToContext(UserDetails userDetails, DirContextAdapter dirContextAdapter) {
}
}
Как получить правильный SID из Active Directory?