mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-18 22:38:09 +08:00
openldap,activedirectory密码验证支持
openldap,activedirectory密码验证支持,需要先完成用户同步
This commit is contained in:
@@ -54,6 +54,12 @@ public abstract class AbstractAuthenticationRealm {
|
||||
protected LoginHistoryService loginHistoryService;
|
||||
|
||||
protected AbstractRemeberMeService remeberMeService;
|
||||
|
||||
protected boolean ldapSupport;
|
||||
|
||||
protected AbstractAuthenticationRealm ldapAuthenticationRealm;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -53,9 +53,13 @@ public class DefaultJdbcAuthenticationRealm extends AbstractAuthenticationRealm
|
||||
*/
|
||||
public boolean passwordMatches(UserInfo userInfo, String password) {
|
||||
boolean passwordMatches = false;
|
||||
_logger.info("password : "
|
||||
+ PasswordReciprocal.getInstance().rawPassword(userInfo.getUsername(), password));
|
||||
passwordMatches = passwordEncoder.matches(password,userInfo.getPassword());
|
||||
if(ldapSupport) {
|
||||
passwordMatches =this.ldapAuthenticationRealm.passwordMatches(userInfo, password);
|
||||
}else {
|
||||
_logger.debug("password : "
|
||||
+ PasswordReciprocal.getInstance().rawPassword(userInfo.getUsername(), password));
|
||||
passwordMatches = passwordEncoder.matches(password,userInfo.getPassword());
|
||||
}
|
||||
_logger.debug("passwordvalid : " + passwordMatches);
|
||||
if (!passwordMatches) {
|
||||
passwordPolicyValidator.setBadPasswordCount(userInfo);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.maxkey.authn.realm.jdbc;
|
||||
|
||||
import org.maxkey.authn.realm.AbstractAuthenticationRealm;
|
||||
import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
|
||||
import org.maxkey.persistence.db.LoginHistoryService;
|
||||
import org.maxkey.persistence.db.LoginService;
|
||||
@@ -59,5 +60,27 @@ public class JdbcAuthenticationRealm extends DefaultJdbcAuthenticationRealm {
|
||||
}
|
||||
|
||||
|
||||
public JdbcAuthenticationRealm(
|
||||
PasswordEncoder passwordEncoder,
|
||||
PasswordPolicyValidator passwordPolicyValidator,
|
||||
LoginService loginService,
|
||||
LoginHistoryService loginHistoryService,
|
||||
AbstractRemeberMeService remeberMeService,
|
||||
JdbcTemplate jdbcTemplate,
|
||||
AbstractAuthenticationRealm ldapAuthenticationRealm,
|
||||
boolean ldapSupport
|
||||
) {
|
||||
|
||||
this.passwordEncoder =passwordEncoder;
|
||||
this.passwordPolicyValidator=passwordPolicyValidator;
|
||||
this.loginService = loginService;
|
||||
this.loginHistoryService = loginHistoryService;
|
||||
this.remeberMeService = remeberMeService;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.ldapAuthenticationRealm = ldapAuthenticationRealm;
|
||||
this.ldapSupport = ldapSupport;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class LdapServer implements IAuthenticationServer {
|
||||
*/
|
||||
@Override
|
||||
public boolean authenticate(String username, String password) {
|
||||
String queryFilter = "("+filterAttribute+"="+username+")";
|
||||
String queryFilter = String.format(filterAttribute, username);
|
||||
_logger.info(" filter : " + queryFilter);
|
||||
String dn="";
|
||||
SearchControls constraints = new SearchControls();
|
||||
@@ -69,7 +69,7 @@ public final class LdapServer implements IAuthenticationServer {
|
||||
} catch (NamingException e) {
|
||||
_logger.error("query throw NamingException:" + e.getMessage());
|
||||
} finally {
|
||||
ldapUtils.close();
|
||||
//ldapUtils.close();
|
||||
}
|
||||
|
||||
LdapUtils ldapPassWordValid=new LdapUtils(ldapUtils.getProviderUrl(),dn,password);
|
||||
|
||||
Reference in New Issue
Block a user