提交 7985582a 编写于 作者: sq3536's avatar sq3536

密码重置

上级 8f77418f
......@@ -3,15 +3,21 @@ package cn.ibizlab.core.extensions.aspect;
import cn.ibizlab.core.extensions.mapping.IBZEmp2UserMapping;
import cn.ibizlab.core.extensions.service.OUModelService;
import cn.ibizlab.core.ou.domain.IBZEmployee;
import cn.ibizlab.core.ou.service.IIBZEmployeeService;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.service.IBZUSERService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import java.util.List;
......@@ -29,6 +35,21 @@ public class IBZEmp2UserAspect
@Lazy
private IBZEmp2UserMapping ibzEmp2UserMapping;
@Value("${ibiz.auth.pwencrymode:0}")
private int pwencrymode;
@Value("${ibiz.auth.defaultpasswd:123456}")
private String defaultPasswd;
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
public void BeforeCreateEmp(JoinPoint point) throws Exception {
prepareEmp(point);
}
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.updat*(..))")
public void BeforeUpdateEmp(JoinPoint point) throws Exception {
prepareEmp(point);
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
public void AfterCreateEmp(JoinPoint point) throws Exception {
saveUser(point);
......@@ -49,7 +70,69 @@ public class IBZEmp2UserAspect
public void AfterSaveEmp(JoinPoint point) throws Exception {
saveUser(point);
}
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.initPwd(..))")
public void AfterInitPwd(JoinPoint point) throws Exception {
initPwd(point);
}
private void prepareEmp(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if(obj instanceof IBZEmployee)
{
IBZEmployee emp= ((IBZEmployee)obj);
String userName=emp.getUsername();
if(StringUtils.isEmpty(userName))
{
if(!StringUtils.isEmpty(emp.getDomains()))
userName= emp.getLoginname()+"|"+emp.getDomains();
else
userName = emp.getLoginname();
emp.setUsername(userName);
}
String password = emp.getPassword();
if(StringUtils.isEmpty(password))
{
password=defaultPasswd;
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", userName, password).getBytes());
emp.setPassword(password);
}
}
else if (obj instanceof List)
{
List<IBZEmployee> list=(List<IBZEmployee>)obj;
for(IBZEmployee emp:list)
{
String userName=emp.getUsername();
if(StringUtils.isEmpty(userName))
{
if(!StringUtils.isEmpty(emp.getDomains()))
userName= emp.getLoginname()+"|"+emp.getDomains();
else
userName = emp.getLoginname();
emp.setUsername(userName);
}
String password = emp.getPassword();
if(StringUtils.isEmpty(password))
{
password=defaultPasswd;
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", userName, password).getBytes());
emp.setPassword(password);
}
}
}
}
}
private void saveUser(JoinPoint point)
{
......@@ -85,4 +168,33 @@ public class IBZEmp2UserAspect
}
}
@Autowired
private IIBZEmployeeService iibzEmployeeService;
public void initPwd(JoinPoint point) {
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if (obj instanceof IBZEmployee)
{
IBZEmployee emp= ((IBZEmployee)obj);
if(StringUtils.isEmpty(emp.getUserid()))
throw new BadRequestAlertException("没有找到要初始化密码的用户","IBZEMP","");
IBZEmployee oldEmp=iibzEmployeeService.get(emp.getUserid());
if(StringUtils.isEmpty(oldEmp.getUsername()))
throw new BadRequestAlertException("没有找到要初始化密码的用户","IBZEMP","");
String password=defaultPasswd;
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", oldEmp.getUsername(), password).getBytes());
emp.setPassword(password);
this.iibzEmployeeService.update(emp);
}
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册