我已经设置了 samAccountName: mti 并设置了 [email protected]。当我使用 sameAccountName 时,一切正常,但 userPrincipal 则不然。我想同时有两个选项,但首先我只尝试使用 userPricipalName。
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(environmentsVariables.LDAP_DOMAIN, environmentsVariables.LDAP_PROVIDER_URL);
// provider.setSearchFilter("(&(objectClass=user)(samAccountName={1}))");
provider.setSearchFilter("(&(objectClass=user)(userPrincipalName={0}))");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
provider.setUserDetailsContextMapper(userDetailsContextMapper());
return provider;
}
我想同时有两个选择
LDAP 允许布尔运算符尝试不同的输入。例如,您可以执行以下操作:
provider.setSearchFilter("(|" +
"(&(objectClass=user)(userPrincipalName={0}))" +
"(&(objectClass=user)(samAccountName={1}))" +
")");
sameAccountName 一切正常,但 userPrincipal 不
默认情况下,Spring Security 将采用提供的用户名并附加域以创建绑定主体。因此,如果用户输入 'smti
作为用户名,则{0}
( userPrincipalName1
) 将是[email protected]
,{1}
( samAccountName
) 将是mti
。这可能是它不适用于samAccountName
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句