Authored by qinchao

对接ldap

... ... @@ -5,6 +5,7 @@ import com.ui.User.MD5Util;
import com.ui.User.UserAuthLocal;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.ldaputil.LdapAuthUtil;
import com.ui.model.BaseResponse;
import com.ui.model.Directional;
import com.ui.model.req.AuthModule;
... ... @@ -45,6 +46,9 @@ public class UserCtrl {
@Autowired
UserAuthLocal userAuthLocal;
@Autowired
private LdapAuthUtil ldapAuthenticate;
@RequestMapping("/toLogin")
public ModelAndView toLogin() {
return new ModelAndView("user/login");
... ... @@ -66,13 +70,50 @@ public class UserCtrl {
}
User u = userAuthLocal.getUserByname(user.getName());
boolean ldapFlag=false;
// 给admin留一个后门,防止ldap不能验证
if(!"admin".equals(user.getName())){
ldapFlag=true;
}
User u =null;
if(ldapFlag){
//走ldap统一认证接口
//认证
//认证不通过,提示
if(!ldapAuthenticate.login(user.getName(),user.getPwd())){
model.addAttribute("message", "请使用你的OA账户登陆,登录名或者密码错误");
return new ModelAndView("user/login");
}
//认证通过
u = userAuthLocal.getUserByLdapName(user.getName());
if (u == null) {
model.addAttribute("message", "用户名不存在");
//创建默认的用户
model.addAttribute("message", "用户名不存在,如有需要请联系管理员添加用户");
return new ModelAndView("user/login");
}
if (u.getPwd().equals(MD5Util.encryption(user.getPwd()))) {
}else{
u = userAuthLocal.getUserByname(user.getName());
if (u == null) {
model.addAttribute("message", "用户名不存在,如有需要请联系管理员添加用户");
return new ModelAndView("user/login");
}
if (!u.getPwd().equals(MD5Util.encryption(user.getPwd()))) {
model.addAttribute("message", "密码错误");
return new ModelAndView("user/login");
}
}
//用户放到session
session.setAttribute("user", u);
if(StringUtils.isBlank(Directional.getInstance().getLoginTargetUrl())){
return new ModelAndView("dashBoard/dashBoard");
}else{
... ... @@ -84,10 +125,6 @@ public class UserCtrl {
}
return null;
}
} else {
model.addAttribute("message", "密码错误");
return new ModelAndView("user/login");
}
}
... ...
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ldapContextSource" class="com.ui.ldaputil.YhLdapContextSource">
<!--test ldaps://yoho01.local:636 -->
<!--formal ldaps://ldap.yoho.cn:2018 -->
<property name="url" value="ldaps://ldap.yoho.cn:2018"/>
<property name="base" value="dc=yoho01,dc=local"/>
<property name="userDn" value="tech@yoho01.local"/>
<property name="password" value="3nIiz2Ov38NU"/>
<property name="referral" value="follow"></property>
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<property name="contextSource" ref="ldapContextSource"/>
<property name="ignorePartialResultException" value="true"/>
</bean>
</beans>
... ...
... ... @@ -28,10 +28,10 @@
<img src="<%=basePath %>img/yoho.jpg" alt="Yoho Ops" >
</div>
<br />
<h4 class="text-center mb5">Still not a user?</h4>
<h4 class="text-center mb5" style="color:red">请使用OA账户登录</h4>
<p class="text-center">Please connect with the admin.</p>
<div class="mb30"></div>
<div class="mb30" style="color:red">${message}</div>
<form id="loginform" action="<%=basePath %>user/login" method="post">
<div class="input-group mb15">
... ...