UserPrincipalName始终为active directory身份验证的搜索筛选器失败:提供的密码无效

7nbnzgx9  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(362)

我已经设置了samaccountname:mti并设置了userprincipalname=martintig@domena.com. 当我使用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;
    }
oogrdqng

oogrdqng1#

我想同时有两个选择
ldap允许布尔运算符尝试不同的输入。例如,您可以执行以下操作:

provider.setSearchFilter("(|" +
    "(&(objectClass=user)(userPrincipalName={0}))" +
    "(&(objectClass=user)(samAccountName={1}))" +
")");

sameaccountname一切正常,但userprincipal不正常
默认情况下,spring security将使用提供的用户名并附加域以创建绑定主体。因此,如果用户输入 mti 作为用户名, {0} ( userPrincipalName1 )将是 mti@domena.com{1} ( samAccountName )将是 mti . 这可能是它不起作用的原因 samAccountName .

相关问题