mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 17:38:32 +08:00
LDAP同步和登录问题
decoder credentials
This commit is contained in:
parent
8f9c5dad08
commit
7944b16bd1
@ -149,8 +149,9 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
historyLogin.setBrowser(browser.getName());
|
historyLogin.setBrowser(browser.getName());
|
||||||
historyLogin.setPlatform(browser.getPlatform());
|
historyLogin.setPlatform(browser.getPlatform());
|
||||||
historyLogin.setSourceIp(userInfo.getLastLoginIp());
|
historyLogin.setSourceIp(userInfo.getLastLoginIp());
|
||||||
historyLogin.setIpRegion(IpRegionFactory.getFactory().region(userInfo.getLastLoginIp()));
|
//TODO:
|
||||||
historyLogin.setIpLocation(IpRegionFactory.getFactory().getLocation(historyLogin.getIpRegion()));
|
//historyLogin.setIpRegion(IpRegionFactory.getFactory().region(userInfo.getLastLoginIp()));
|
||||||
|
//historyLogin.setIpLocation(IpRegionFactory.getFactory().getLocation(historyLogin.getIpRegion()));
|
||||||
historyLogin.setProvider(provider);
|
historyLogin.setProvider(provider);
|
||||||
historyLogin.setCode(code);
|
historyLogin.setCode(code);
|
||||||
historyLogin.setLoginType(type);
|
historyLogin.setLoginType(type);
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.maxkey.authn.realm.IAuthenticationServer;
|
import org.maxkey.authn.realm.IAuthenticationServer;
|
||||||
|
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||||
import org.maxkey.entity.LdapContext;
|
import org.maxkey.entity.LdapContext;
|
||||||
import org.maxkey.persistence.ldap.ActiveDirectoryUtils;
|
import org.maxkey.persistence.ldap.ActiveDirectoryUtils;
|
||||||
import org.maxkey.persistence.ldap.LdapUtils;
|
import org.maxkey.persistence.ldap.LdapUtils;
|
||||||
@ -57,7 +58,8 @@ public class LdapAuthenticationRealmService {
|
|||||||
ActiveDirectoryUtils ldapUtils = new ActiveDirectoryUtils(
|
ActiveDirectoryUtils ldapUtils = new ActiveDirectoryUtils(
|
||||||
ldapContext.getProviderUrl(),
|
ldapContext.getProviderUrl(),
|
||||||
ldapContext.getPrincipal(),
|
ldapContext.getPrincipal(),
|
||||||
ldapContext.getCredentials(),
|
PasswordReciprocal.getInstance().decoder(
|
||||||
|
ldapContext.getCredentials()),
|
||||||
ldapContext.getMsadDomain());
|
ldapContext.getMsadDomain());
|
||||||
ldapServer.setActiveDirectoryUtils(ldapUtils);
|
ldapServer.setActiveDirectoryUtils(ldapUtils);
|
||||||
if(ldapContext.getAccountMapping().equalsIgnoreCase("YES")) {
|
if(ldapContext.getAccountMapping().equalsIgnoreCase("YES")) {
|
||||||
@ -70,7 +72,8 @@ public class LdapAuthenticationRealmService {
|
|||||||
LdapUtils ldapUtils = new LdapUtils(
|
LdapUtils ldapUtils = new LdapUtils(
|
||||||
ldapContext.getProviderUrl(),
|
ldapContext.getProviderUrl(),
|
||||||
ldapContext.getPrincipal(),
|
ldapContext.getPrincipal(),
|
||||||
ldapContext.getCredentials(),
|
PasswordReciprocal.getInstance().decoder(
|
||||||
|
ldapContext.getCredentials()),
|
||||||
ldapContext.getBasedn());
|
ldapContext.getBasedn());
|
||||||
standardLdapServer.setLdapUtils(ldapUtils);
|
standardLdapServer.setLdapUtils(ldapUtils);
|
||||||
standardLdapServer.setFilterAttribute(ldapContext.getFilters());
|
standardLdapServer.setFilterAttribute(ldapContext.getFilters());
|
||||||
|
|||||||
@ -45,20 +45,17 @@ public class ReciprocalUtilsTest {
|
|||||||
String urlencodeString="中国";
|
String urlencodeString="中国";
|
||||||
String urlencode = java.net.URLEncoder.encode(urlencodeString, "utf-8");
|
String urlencode = java.net.URLEncoder.encode(urlencodeString, "utf-8");
|
||||||
System.out.println(urlencode);
|
System.out.println(urlencode);
|
||||||
String urldecodeString="http://exchange.connsec.com/owa/?ae=Item&a=Open&t=IPM.Note&id=RgAAAABPKgpqnlfYQ7BVC%2fBfH2XIBwCS0xhUjzMYSLVky9bw7LddAAAAjov5AACS0xhUjzMYSLVky9bw7LddAAADzoy%2fAAAA&pspid=_1428036768398_867461813";
|
String urldecodeString="http://exchange.maxkey.top/owa/?ae=Item&a=Open&t=IPM.Note&id=RgAAAABPKgpqnlfYQ7BVC%2fBfH2XIBwCS0xhUjzMYSLVky9bw7LddAAAAjov5AACS0xhUjzMYSLVky9bw7LddAAADzoy%2fAAAA&pspid=_1428036768398_867461813";
|
||||||
String urldcode = java.net.URLDecoder.decode(urldecodeString, "utf-8");
|
String urldcode = java.net.URLDecoder.decode(urldecodeString, "utf-8");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(urldcode);*/
|
System.out.println(urldcode);*/
|
||||||
|
|
||||||
|
|
||||||
String encoderString="root";
|
String encoderString="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
encoderString = PasswordReciprocal.getInstance().encode(encoderString);
|
encoderString = PasswordReciprocal.getInstance().encode(encoderString);
|
||||||
System.out.println( encoderString);
|
System.out.println( encoderString);
|
||||||
|
System.out.println( "length " + encoderString.length());
|
||||||
|
|
||||||
encoderString=PasswordReciprocal.getInstance().decoder(encoderString);
|
encoderString=PasswordReciprocal.getInstance().decoder(encoderString);
|
||||||
System.out.println(encoderString );
|
System.out.println(encoderString );
|
||||||
|
|||||||
@ -108,40 +108,60 @@ public class LdapUsersService extends AbstractSynchronizerService implements IS
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
userInfo.setId(userInfo.generateId());
|
userInfo.setId(userInfo.generateId());
|
||||||
userInfo.setFormattedName(LdapUtils.getAttributeStringValue(InetOrgPerson.CN,attributeMap));//閸忋劌鎮<EFBFBD>
|
String cn = LdapUtils.getAttributeStringValue(InetOrgPerson.CN,attributeMap);
|
||||||
//鐠愶附鍩<EFBFBD>
|
String uid = LdapUtils.getAttributeStringValue(InetOrgPerson.UID,attributeMap);
|
||||||
userInfo.setUsername(LdapUtils.getAttributeStringValue(InetOrgPerson.UID,attributeMap));//鐠愶箑褰<EFBFBD>
|
String sn = LdapUtils.getAttributeStringValue(InetOrgPerson.SN,attributeMap);
|
||||||
userInfo.setFamilyName(LdapUtils.getAttributeStringValue(InetOrgPerson.SN,attributeMap));//婵拷
|
String givenName = LdapUtils.getAttributeStringValue(InetOrgPerson.GIVENNAME,attributeMap);
|
||||||
userInfo.setGivenName(LdapUtils.getAttributeStringValue(InetOrgPerson.GIVENNAME,attributeMap));//閸氾拷
|
String initials = LdapUtils.getAttributeStringValue(InetOrgPerson.INITIALS,attributeMap);
|
||||||
userInfo.setNickName(LdapUtils.getAttributeStringValue(InetOrgPerson.INITIALS,attributeMap));//閺勭數袨
|
String displayName = LdapUtils.getAttributeStringValue(InetOrgPerson.DISPLAYNAME,attributeMap);
|
||||||
userInfo.setNameZhShortSpell(LdapUtils.getAttributeStringValue(InetOrgPerson.INITIALS,attributeMap));//閼昏鲸鏋冪紓鈺佸晸
|
userInfo.setFormattedName(sn + givenName);
|
||||||
userInfo.setDisplayName(LdapUtils.getAttributeStringValue(InetOrgPerson.DISPLAYNAME,attributeMap));//閺勫墽銇氶崥宥囆<EFBFBD>
|
if(StringUtils.isBlank(uid)) {
|
||||||
|
userInfo.setUsername(cn);
|
||||||
|
userInfo.setWindowsAccount(cn);
|
||||||
|
}else {
|
||||||
|
userInfo.setUsername(uid);
|
||||||
|
userInfo.setWindowsAccount(uid);
|
||||||
|
}
|
||||||
|
userInfo.setFamilyName(sn);
|
||||||
|
userInfo.setGivenName(givenName);
|
||||||
|
if(StringUtils.isBlank(initials)) {
|
||||||
|
userInfo.setNickName(sn + givenName);
|
||||||
|
userInfo.setNameZhShortSpell(sn + givenName);
|
||||||
|
}else {
|
||||||
|
userInfo.setNickName(initials);
|
||||||
|
userInfo.setNameZhShortSpell(initials);
|
||||||
|
}
|
||||||
|
if(StringUtils.isBlank(displayName)) {
|
||||||
|
userInfo.setDisplayName(sn + givenName);
|
||||||
|
}else {
|
||||||
|
userInfo.setDisplayName(displayName);
|
||||||
|
}
|
||||||
|
|
||||||
userInfo.setEmployeeNumber(LdapUtils.getAttributeStringValue(InetOrgPerson.EMPLOYEENUMBER,attributeMap));
|
userInfo.setEmployeeNumber(LdapUtils.getAttributeStringValue(InetOrgPerson.EMPLOYEENUMBER,attributeMap));
|
||||||
//userInfo.setDepartment(LdapUtils.getAttributeStringValue(InetOrgPerson.OU,attributeMap));
|
//userInfo.setDepartment(LdapUtils.getAttributeStringValue(InetOrgPerson.OU,attributeMap));
|
||||||
//userInfo.setDepartmentId(LdapUtils.getAttributeStringValue(InetOrgPerson.DEPARTMENTNUMBER,attributeMap));
|
//userInfo.setDepartmentId(LdapUtils.getAttributeStringValue(InetOrgPerson.DEPARTMENTNUMBER,attributeMap));
|
||||||
userInfo.setJobTitle(LdapUtils.getAttributeStringValue(InetOrgPerson.TITLE,attributeMap));//閼卞苯濮<EFBFBD>
|
userInfo.setJobTitle(LdapUtils.getAttributeStringValue(InetOrgPerson.TITLE,attributeMap));
|
||||||
userInfo.setWorkOfficeName(LdapUtils.getAttributeStringValue(InetOrgPerson.PHYSICALDELIVERYOFFICENAME,attributeMap));//閸旂偛鍙曠<EFBFBD>癸拷
|
userInfo.setWorkOfficeName(LdapUtils.getAttributeStringValue(InetOrgPerson.PHYSICALDELIVERYOFFICENAME,attributeMap));
|
||||||
userInfo.setWorkEmail(LdapUtils.getAttributeStringValue(InetOrgPerson.MAIL,attributeMap));//闁喕娆<EFBFBD>
|
userInfo.setWorkEmail(LdapUtils.getAttributeStringValue(InetOrgPerson.MAIL,attributeMap));
|
||||||
userInfo.setWorkRegion(LdapUtils.getAttributeStringValue(InetOrgPerson.ST,attributeMap));//閻拷
|
userInfo.setWorkRegion(LdapUtils.getAttributeStringValue(InetOrgPerson.ST,attributeMap));
|
||||||
userInfo.setWorkLocality(LdapUtils.getAttributeStringValue(InetOrgPerson.L,attributeMap));//閸橈拷
|
userInfo.setWorkLocality(LdapUtils.getAttributeStringValue(InetOrgPerson.L,attributeMap));
|
||||||
userInfo.setWorkStreetAddress(LdapUtils.getAttributeStringValue(InetOrgPerson.STREET,attributeMap));//鐞涙浜<EFBFBD>
|
userInfo.setWorkStreetAddress(LdapUtils.getAttributeStringValue(InetOrgPerson.STREET,attributeMap));
|
||||||
userInfo.setWorkPostalCode(LdapUtils.getAttributeStringValue(InetOrgPerson.POSTALCODE,attributeMap));//闁喚绱<EFBFBD>
|
userInfo.setWorkPostalCode(LdapUtils.getAttributeStringValue(InetOrgPerson.POSTALCODE,attributeMap));
|
||||||
userInfo.setWorkAddressFormatted(LdapUtils.getAttributeStringValue(InetOrgPerson.POSTOFFICEBOX,attributeMap));//闁喗鏂傞柇顔绢唸
|
userInfo.setWorkAddressFormatted(LdapUtils.getAttributeStringValue(InetOrgPerson.POSTOFFICEBOX,attributeMap));
|
||||||
userInfo.setWorkFax(LdapUtils.getAttributeStringValue(InetOrgPerson.FACSIMILETELEPHONENUMBER,attributeMap));
|
userInfo.setWorkFax(LdapUtils.getAttributeStringValue(InetOrgPerson.FACSIMILETELEPHONENUMBER,attributeMap));
|
||||||
|
|
||||||
userInfo.setHomePhoneNumber(LdapUtils.getAttributeStringValue(InetOrgPerson.HOMEPHONE,attributeMap));//鐎硅泛娑甸悽浣冪樈
|
userInfo.setHomePhoneNumber(LdapUtils.getAttributeStringValue(InetOrgPerson.HOMEPHONE,attributeMap));
|
||||||
userInfo.setHomeAddressFormatted(LdapUtils.getAttributeStringValue(InetOrgPerson.HOMEPOSTALADDRESS,attributeMap));//閻絻鐦芥径鍥ㄦ暈
|
userInfo.setHomeAddressFormatted(LdapUtils.getAttributeStringValue(InetOrgPerson.HOMEPOSTALADDRESS,attributeMap));
|
||||||
|
|
||||||
if(LdapUtils.getAttributeStringValue(InetOrgPerson.MOBILE,attributeMap).equals("")) {
|
if(LdapUtils.getAttributeStringValue(InetOrgPerson.MOBILE,attributeMap).equals("")) {
|
||||||
userInfo.setMobile(userInfo.getId());
|
userInfo.setMobile(userInfo.getId());
|
||||||
}else {
|
}else {
|
||||||
userInfo.setMobile(LdapUtils.getAttributeStringValue(InetOrgPerson.MOBILE,attributeMap));//閹靛婧<EFBFBD>
|
userInfo.setMobile(LdapUtils.getAttributeStringValue(InetOrgPerson.MOBILE,attributeMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo.setPreferredLanguage(LdapUtils.getAttributeStringValue(InetOrgPerson.PREFERREDLANGUAGE,attributeMap));//鐠囶叀鈻<EFBFBD>
|
userInfo.setPreferredLanguage(LdapUtils.getAttributeStringValue(InetOrgPerson.PREFERREDLANGUAGE,attributeMap));
|
||||||
|
|
||||||
userInfo.setDescription(LdapUtils.getAttributeStringValue(InetOrgPerson.DESCRIPTION,attributeMap));//閹诲繗鍫<EFBFBD>
|
userInfo.setDescription(LdapUtils.getAttributeStringValue(InetOrgPerson.DESCRIPTION,attributeMap));
|
||||||
userInfo.setUserState("RESIDENT");
|
userInfo.setUserState("RESIDENT");
|
||||||
userInfo.setUserType("EMPLOYEE");
|
userInfo.setUserType("EMPLOYEE");
|
||||||
userInfo.setTimeZone("Asia/Shanghai");
|
userInfo.setTimeZone("Asia/Shanghai");
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||||
import org.maxkey.entity.Synchronizers;
|
import org.maxkey.entity.Synchronizers;
|
||||||
import org.maxkey.synchronizer.SynchronizerJob;
|
import org.maxkey.synchronizer.SynchronizerJob;
|
||||||
import org.quartz.CronExpression;
|
import org.quartz.CronExpression;
|
||||||
@ -104,7 +105,9 @@ public class SynchronizerAutoConfiguration implements InitializingBean {
|
|||||||
synchronizer.setProviderUrl(rs.getString("providerurl"));
|
synchronizer.setProviderUrl(rs.getString("providerurl"));
|
||||||
synchronizer.setDriverClass(rs.getString("driverclass"));
|
synchronizer.setDriverClass(rs.getString("driverclass"));
|
||||||
synchronizer.setPrincipal( rs.getString("principal"));
|
synchronizer.setPrincipal( rs.getString("principal"));
|
||||||
synchronizer.setCredentials(rs.getString("credentials"));
|
synchronizer.setCredentials(
|
||||||
|
PasswordReciprocal.getInstance().decoder(
|
||||||
|
rs.getString("credentials")));
|
||||||
synchronizer.setResumeTime( rs.getString("resumetime"));
|
synchronizer.setResumeTime( rs.getString("resumetime"));
|
||||||
synchronizer.setSuspendTime(rs.getString("suspendtime"));
|
synchronizer.setSuspendTime(rs.getString("suspendtime"));
|
||||||
synchronizer.setFilters( rs.getString("filters"));
|
synchronizer.setFilters( rs.getString("filters"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user