Commit 92bffdfd authored by hongguangwu's avatar hongguangwu

Merge remote-tracking branch 'origin/develop' into develop

parents 2a963ced 794049d1
......@@ -2,6 +2,7 @@ package com.yifu.cloud.plus.v1.yifu.common.ldap.util;
import com.unboundid.ldap.sdk.*;
import com.unboundid.ldap.sdk.controls.SubentriesRequestControl;
import com.unboundid.util.Base64;
import com.yifu.cloud.plus.v1.yifu.common.ldap.config.LdapProperties;
import com.yifu.cloud.plus.v1.yifu.common.ldap.entity.PersonVo;
import com.yifu.cloud.plus.v1.yifu.common.ldap.mapper.PersonAttributesMapper;
......@@ -10,15 +11,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.ldap.core.LdapTemplate;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.SearchControls;
import javax.naming.ldap.Control;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import static org.springframework.ldap.query.LdapQueryBuilder.query;
......@@ -33,10 +29,6 @@ public class LdapUtil {
@Autowired
private LdapProperties ldapProperties;
private static LdapContext ctx = null;
private static final Control[] connCtls = null;
/**
* @return List<SearchResultEntry>
* @author huyc
......@@ -64,71 +56,31 @@ public class LdapUtil {
}
// 校验用户名密码的方法
public Boolean authenticate(String usr, String pwd) {
boolean valide;
public Boolean authenticate(String usr, String pwd) throws NoSuchAlgorithmException {
if (pwd == null || "".equals(pwd))
return false;
if (ctx == null) {
getCtx();
}
String userDN = getUserDN(usr);
if ("".equals(userDN) || userDN == null) {
return false;
}
try {
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDN);
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, pwd);
ctx.reconnect(connCtls);
valide = true;
closeCtx();
} catch (NamingException e) {
log.error(userDN + " is not authenticated");
valide = false;
}
return valide;
}
public void getCtx() {
if (ctx != null) {
return;
}
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://" + ldapProperties.getUrl() + ":" + ldapProperties.getPort() +
"/" + ldapProperties.getDn());
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ldapProperties.getUserName());
env.put(Context.SECURITY_CREDENTIALS, ldapProperties.getPassword());
try {
// 链接ldap
ctx = new InitialLdapContext(env, connCtls);
} catch (NamingException e) {
e.printStackTrace();
}
}
public void closeCtx() throws NamingException {
if (ctx != null)
ctx.close();
}
public String getUserDN(String uid) {
StringBuilder userDN = new StringBuilder();
try {
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<?> en = ctx.search("", "uid=" + uid, constraints);
while (en != null && en.hasMoreElements()) {
Object obj = en.nextElement();
if (obj instanceof javax.naming.directory.SearchResult) {
javax.naming.directory.SearchResult si = (javax.naming.directory.SearchResult) obj;
userDN.append(si.getName());
userDN.append(",").append(ldapProperties.getDn());
List<SearchResultEntry> entryList = this.getAllPersonNamesWithTraditionalWay();
byte[] ldapPw = new byte[0];
for (SearchResultEntry resultEntry: entryList){
if (resultEntry.getDN().contains("uid="+usr)) {
String password = resultEntry.getAttributeValue("userPassword");
if (null != password) {
String ldapPwd1 = password.substring(5);
ldapPw = Base64.decode(ldapPwd1);
break;
} else {
return false;
}
}
}
} catch (Exception e) {
e.printStackTrace();
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(pwd.getBytes());
byte[] m = md5.digest();
return MessageDigest.isEqual(m, ldapPw);
} catch (ParseException e) {
log.error(" is not authenticated");
}
return userDN.toString();
return false;
}
}
......@@ -2588,6 +2588,15 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
dispatch.setSettleDomainCode(setInfoVo.getDepartNo());
dispatch.setBelongUnit(setInfoVo.getCustomerId());
dispatch.setBelongUnitName(setInfoVo.getCustomerName());
TEmployeeProject temp = new TEmployeeProject();
temp.setDeptId(dispatch.getSettleDomain());
temp.setEmpId(dispatch.getEmpId());
R<TEmployeeProject> res = archivesDaprUtil.getTEmployeeProjectById(temp);
if (Common.isNotNull(res)){
if (Common.isNotNull(res.getData().getWorkingHours())) {
dispatch.setWorkingHours(res.getData().getWorkingHours());
}
}
}
StringBuffer temp = new StringBuffer();
if (Common.isNotNull(excel.getSocialReduceDate())){
......
......@@ -2332,8 +2332,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
socialParam.setFd_3af9ee3aa9c84a(CommonConstants.EMPTY_STRING);
}
//实缴合计
if (Common.isNotNull(library.getSumAll())) {
socialParam.setFd_3af9ee3c6bfc74(library.getSumAll().toString());
if (Common.isNotNull(library.getSocialSum())) {
socialParam.setFd_3af9ee3c6bfc74(library.getSocialSum().toString());
} else {
socialParam.setFd_3af9ee3c6bfc74(CommonConstants.EMPTY_STRING);
}
......
......@@ -42,6 +42,7 @@ import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -254,7 +255,7 @@ public class UserController {
*/
@SysLog("登录验证")
@PostMapping("/ldapLogin")
public R<Boolean> loginAuthentication(@RequestParam String userName,@RequestParam String password) {
public R<Boolean> loginAuthentication(@RequestParam String userName,@RequestParam String password) throws NoSuchAlgorithmException {
return userService.loginAuthentication(userName,password);
}
......
......@@ -19,6 +19,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -41,4 +42,9 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
List<String> selectDnList();
SysDept selectCountId(@Param("deptId")Long deptId);
int updateDeptById(@Param("dept") SysDept dept);
SysDept selectDeptDn(@Param("deptDn")String deptDn);
}
......@@ -27,6 +27,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserVO;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.validation.BindingResult;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Set;
......@@ -132,6 +133,6 @@ public interface SysUserService extends IService<SysUser> {
* 从ldap中验证登录用户
* @return R
*/
R<Boolean> loginAuthentication(String userName, String password);
R<Boolean> loginAuthentication(String userName, String password) throws NoSuchAlgorithmException;
}
......@@ -60,8 +60,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
private final LdapUtil ldapUtil;
private final SysDeptMapper sysDeptMapper;
private final SysUserMapper sysUserMapper;
/**
......@@ -188,11 +186,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
//获取ldap所有的dn
List<String> entryDnList = entryList.stream().map(SearchResultEntry::getDN).collect(Collectors.toList());
//获取本地dept表中所有的dn
List<String> dnList = sysDeptMapper.selectDnList();
List<String> dnList = baseMapper.selectDnList();
List<String> delList = dnList.stream().filter(p-> !entryDnList.contains(p)).collect(Collectors.toList());
//删除ldap中不存在的dn的数据
if (!delList.isEmpty()) {
sysDeptMapper.delete(Wrappers.<SysDept>query().lambda().in(SysDept::getDeptDn, delList));
baseMapper.delete(Wrappers.<SysDept>query().lambda().in(SysDept::getDeptDn, delList));
}
List<Map<String,Object>> updUserList = new ArrayList<>();
for (SearchResultEntry entry : entryList) {
......@@ -206,35 +204,52 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
String deptName = saveDnList.get(0).replace("ou=", "");
int size = saveDnList.size();
if (size == 1) {
SysDept sysDept = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
SysDept sysDept = baseMapper.selectDeptDn(dn);
if (null == sysDept) {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(0L);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
if (StringUtils.isEmpty(userId)) {
SysDept ins = baseMapper.selectCountId(Long.valueOf(entry.getAttributeValue("x-ouid")));
if (Common.isNotNull(ins)) {
ins.setName(deptName);
ins.setDeptDn(dn);
baseMapper.updateDeptById(ins);
} else {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(0L);
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
}
baseMapper.insert(insertSysDept);
}
}
insertSysDept.setDeptDn(dn);
this.save(insertSysDept);
} else {
sysDept.setName(deptName);
this.updateDeptById(sysDept);
baseMapper.updateDeptById(sysDept);
}
} else {
try {
SysDept sysDept = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn.substring(dn.indexOf("ou=", 2), dn.length())));
if (null != sysDept) {
SysDept sysDeptCount = this.getOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
SysDept sysDeptCount = baseMapper.selectDeptDn(dn);
if (null == sysDeptCount) {
if (StringUtils.isEmpty(userId)) {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(sysDept.getDeptId());
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
SysDept ins = baseMapper.selectCountId(Long.valueOf(entry.getAttributeValue("x-ouid")));
if (Common.isNotNull(ins)) {
ins.setName(deptName);
ins.setDeptDn(dn);
ins.setParentId(sysDept.getDeptId());
baseMapper.updateDeptById(ins);
} else {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(sysDept.getDeptId());
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
}
baseMapper.insert(insertSysDept);
}
this.save(insertSysDept);
}
} else {
if (!StringUtils.isEmpty(userId)) {
......@@ -246,7 +261,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
}else {
sysDeptCount.setName(deptName);
sysDeptCount.setParentId(sysDept.getDeptId());
this.updateDeptById(sysDeptCount);
sysDeptCount.setDeptDn(dn);
baseMapper.updateDeptById(sysDeptCount);
}
}
}
......
......@@ -55,6 +55,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.validation.BindingResult;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -82,8 +83,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
private final LdapUtil ldapUtil;
private final SysUserMapper sysUserMapper;
/**
* 保存用户信息
* @param userDto DTO 对象
......@@ -431,10 +430,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
}
if (!updateList.isEmpty()) {
sysUserMapper.batchUpdateUser(updateList);
baseMapper.batchUpdateUser(updateList);
}
if (!insertList.isEmpty()) {
sysUserMapper.batchInsertUser(insertList);
baseMapper.batchInsertUser(insertList);
}
}
List<SearchResultEntry> entryList = ldapUtil.getAllPersonNamesWithTraditionalWay();
......@@ -455,38 +454,55 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
userId = dn.substring(4, dn.indexOf(",", 1));
dn = dn.substring(dn.indexOf(",", 1) + 1);
}
List<String> saveDnList = Arrays.stream(dn.split(",")).filter(e -> (e.contains("ou=") && !e.equals("ou=wanxin"))).collect(Collectors.toList());
List<String> saveDnList = Arrays.asList(dn.split(",")).stream().filter(e -> (e.contains("ou=") && !e.equals("ou=wanxin"))).collect(Collectors.toList());
String deptName = saveDnList.get(0).replace("ou=", "");
int size = saveDnList.size();
if (size == 1) {
SysDept sysDept = sysDeptMapper.selectOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
SysDept sysDept = sysDeptMapper.selectDeptDn(dn);
if (null == sysDept) {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(0L);
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
if (StringUtils.isEmpty(userId)) {
SysDept ins = sysDeptMapper.selectCountId(Long.valueOf(entry.getAttributeValue("x-ouid")));
if (Common.isNotNull(ins)) {
ins.setName(deptName);
ins.setDeptDn(dn);
sysDeptMapper.updateDeptById(ins);
} else {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(0L);
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
}
sysDeptMapper.insert(insertSysDept);
}
}
sysDeptMapper.insert(insertSysDept);
} else {
sysDept.setName(deptName);
sysDeptMapper.updateById(sysDept);
sysDeptMapper.updateDeptById(sysDept);
}
} else {
SysDept sysDept = sysDeptMapper.selectOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn.substring(dn.indexOf("ou=", 2), dn.length())));
if (null != sysDept) {
SysDept sysDeptCount = sysDeptMapper.selectOne(Wrappers.<SysDept>query().lambda().eq(SysDept::getDeptDn, dn));
SysDept sysDeptCount = sysDeptMapper.selectDeptDn(dn);
if (null == sysDeptCount) {
if (StringUtils.isEmpty(userId)) {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(sysDept.getDeptId());
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
SysDept ins = sysDeptMapper.selectCountId(Long.valueOf(entry.getAttributeValue("x-ouid")));
if (Common.isNotNull(ins)) {
ins.setName(deptName);
ins.setDeptDn(dn);
ins.setParentId(sysDept.getDeptId());
sysDeptMapper.updateDeptById(ins);
} else {
SysDept insertSysDept = new SysDept();
insertSysDept.setName(deptName);
insertSysDept.setParentId(sysDept.getDeptId());
insertSysDept.setDeptDn(dn);
if (Common.isNotNull(entry.getAttributeValue("x-ouid"))) {
insertSysDept.setDeptId(Long.valueOf(entry.getAttributeValue("x-ouid")));
}
sysDeptMapper.insert(insertSysDept);
}
sysDeptMapper.insert(insertSysDept);
}
} else {
if (!StringUtils.isEmpty(userId)) {
......@@ -497,15 +513,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
updUserList.add(map);
}else {
sysDeptCount.setName(deptName);
sysDeptCount.setDeptDn(dn);
sysDeptCount.setParentId(sysDept.getDeptId());
sysDeptMapper.updateById(sysDeptCount);
sysDeptMapper.updateDeptById(sysDeptCount);
}
}
}
}
}
//更新用户信息
sysUserMapper.updateUser(updUserList);
if (!updUserList.isEmpty()) {
baseMapper.updateUser(updUserList);
}
}catch (Exception e) {
log.info("用户部门信息同步异常:" + e.getMessage());
return R.failed("用户部门信息同步异常!");
......@@ -518,8 +537,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* @return R
*/
@Override
public R<Boolean> loginAuthentication(String userName, String password) {
if (ldapUtil.authenticate(userName,password)) {
public R<Boolean> loginAuthentication(String userName, String password) throws NoSuchAlgorithmException {
if (Boolean.TRUE.equals(ldapUtil.authenticate(userName,password))) {
return R.ok();
}
return R.failed("验证不通过");
......
......@@ -38,4 +38,33 @@
WHERE a.del_flag = 0
AND a.dept_dn IS NOT NULL
</select>
<select id="selectCountId" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept">
SELECT
*
from sys_dept a
<where>
a.dept_id = #{deptId}
</where>
</select>
<select id="selectDeptDn" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept">
SELECT
*
from sys_dept a
<where>
a.dept_dn = #{deptDn}
</where>
</select>
<update id="updateDeptById">
update sys_dept
<trim prefix="set" suffixOverrides=",">
<if test="dept.name != null">name=#{dept.name},</if>
<if test="dept.parentId != null">parent_id=#{dept.parentId},</if>
<if test="dept.deptDn != null">dept_dn=#{dept.deptDn},</if>
update_time = now()
</trim>
WHERE dept_id=#{dept.deptId}
</update>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment