...
|
...
|
@@ -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.req.AuthModule;
|
|
|
import com.ui.model.req.User;
|
...
|
...
|
@@ -39,6 +40,9 @@ public class UserCtrl { |
|
|
@Autowired
|
|
|
UserAuthLocal userAuthLocal;
|
|
|
|
|
|
@Autowired
|
|
|
private LdapAuthUtil ldapAuthenticate;
|
|
|
|
|
|
@RequestMapping("/toLogin")
|
|
|
public ModelAndView toLogin(String loginTargetUrl, Model model) {
|
|
|
if(StringUtils.isNotBlank(loginTargetUrl)){
|
...
|
...
|
@@ -63,27 +67,60 @@ public class UserCtrl { |
|
|
|
|
|
}
|
|
|
|
|
|
User u = userAuthLocal.getUserByname(user.getName());
|
|
|
if (u == null) {
|
|
|
model.addAttribute("message", "用户名不存在");
|
|
|
return new ModelAndView("user/login");
|
|
|
boolean ldapFlag=false;
|
|
|
BaseResponse ldapFlagResp=httpRestClient.defaultGet(HttpUriContants.USER_LDAP_FLAG,BaseResponse.class);
|
|
|
if(ldapFlagResp!=null&&ldapFlagResp.getCode()==200&&ldapFlagResp.getData()!=null&&"1".equals(String.valueOf(ldapFlagResp.getData()))){
|
|
|
ldapFlag=true;
|
|
|
}
|
|
|
if (u.getPwd().equals(MD5Util.encryption(user.getPwd()))) {
|
|
|
session.setAttribute("user", u);
|
|
|
if(StringUtils.isBlank(user.getLoginTargetUrl())){
|
|
|
return new ModelAndView("dashBoard/dashBoard");
|
|
|
}else{
|
|
|
try {
|
|
|
//直接跳转到初始的请求页面
|
|
|
response.sendRedirect(user.getLoginTargetUrl());
|
|
|
} catch (IOException e) {
|
|
|
return new ModelAndView("dashBoard/dashBoard");
|
|
|
}
|
|
|
return null;
|
|
|
|
|
|
User u =null;
|
|
|
if(ldapFlag){
|
|
|
//走ldap统一认证接口
|
|
|
//认证
|
|
|
//认证不通过,提示
|
|
|
if(!ldapAuthenticate.login(user.getName(),user.getPwd())){
|
|
|
model.addAttribute("message", "请使用你的OA账户登陆,登录名或者密码错误");
|
|
|
return new ModelAndView("user/login");
|
|
|
}
|
|
|
} else {
|
|
|
model.addAttribute("message", "密码错误");
|
|
|
return new ModelAndView("user/login");
|
|
|
|
|
|
//认证通过
|
|
|
u = userAuthLocal.getUserByLdapName(user.getName());
|
|
|
|
|
|
if (u == null) {
|
|
|
//创建默认的用户
|
|
|
model.addAttribute("message", "用户名不存在,如有需要请联系管理员添加用户");
|
|
|
return new ModelAndView("user/login");
|
|
|
}
|
|
|
|
|
|
|
|
|
}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(user.getLoginTargetUrl())){
|
|
|
return new ModelAndView("dashBoard/dashBoard");
|
|
|
}else{
|
|
|
try {
|
|
|
//直接跳转到初始的请求页面
|
|
|
response.sendRedirect(user.getLoginTargetUrl());
|
|
|
} catch (IOException e) {
|
|
|
return new ModelAndView("dashBoard/dashBoard");
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
|