|
@@ -5,6 +5,7 @@ import com.ui.User.MD5Util; |
|
@@ -5,6 +5,7 @@ import com.ui.User.MD5Util; |
5
|
import com.ui.User.UserAuthLocal;
|
5
|
import com.ui.User.UserAuthLocal;
|
6
|
import com.ui.contants.HttpUriContants;
|
6
|
import com.ui.contants.HttpUriContants;
|
7
|
import com.ui.http.HttpRestClient;
|
7
|
import com.ui.http.HttpRestClient;
|
|
|
8
|
+import com.ui.ldaputil.LdapAuthUtil;
|
8
|
import com.ui.model.BaseResponse;
|
9
|
import com.ui.model.BaseResponse;
|
9
|
import com.ui.model.Directional;
|
10
|
import com.ui.model.Directional;
|
10
|
import com.ui.model.req.AuthModule;
|
11
|
import com.ui.model.req.AuthModule;
|
|
@@ -45,6 +46,9 @@ public class UserCtrl { |
|
@@ -45,6 +46,9 @@ public class UserCtrl { |
45
|
@Autowired
|
46
|
@Autowired
|
46
|
UserAuthLocal userAuthLocal;
|
47
|
UserAuthLocal userAuthLocal;
|
47
|
|
48
|
|
|
|
49
|
+ @Autowired
|
|
|
50
|
+ private LdapAuthUtil ldapAuthenticate;
|
|
|
51
|
+
|
48
|
@RequestMapping("/toLogin")
|
52
|
@RequestMapping("/toLogin")
|
49
|
public ModelAndView toLogin() {
|
53
|
public ModelAndView toLogin() {
|
50
|
return new ModelAndView("user/login");
|
54
|
return new ModelAndView("user/login");
|
|
@@ -66,13 +70,50 @@ public class UserCtrl { |
|
@@ -66,13 +70,50 @@ public class UserCtrl { |
66
|
|
70
|
|
67
|
}
|
71
|
}
|
68
|
|
72
|
|
69
|
- User u = userAuthLocal.getUserByname(user.getName());
|
73
|
+ boolean ldapFlag=false;
|
|
|
74
|
+ // 给admin留一个后门,防止ldap不能验证
|
|
|
75
|
+ if(!"admin".equals(user.getName())){
|
|
|
76
|
+ ldapFlag=true;
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ User u =null;
|
|
|
80
|
+ if(ldapFlag){
|
|
|
81
|
+ //走ldap统一认证接口
|
|
|
82
|
+ //认证
|
|
|
83
|
+ //认证不通过,提示
|
|
|
84
|
+ if(!ldapAuthenticate.login(user.getName(),user.getPwd())){
|
|
|
85
|
+ model.addAttribute("message", "请使用你的OA账户登陆,登录名或者密码错误");
|
|
|
86
|
+ return new ModelAndView("user/login");
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ //认证通过
|
|
|
90
|
+ u = userAuthLocal.getUserByLdapName(user.getName());
|
|
|
91
|
+
|
70
|
if (u == null) {
|
92
|
if (u == null) {
|
71
|
- model.addAttribute("message", "用户名不存在");
|
93
|
+ //创建默认的用户
|
|
|
94
|
+ model.addAttribute("message", "用户名不存在,如有需要请联系管理员添加用户");
|
72
|
return new ModelAndView("user/login");
|
95
|
return new ModelAndView("user/login");
|
73
|
}
|
96
|
}
|
74
|
- if (u.getPwd().equals(MD5Util.encryption(user.getPwd()))) {
|
97
|
+
|
|
|
98
|
+
|
|
|
99
|
+ }else{
|
|
|
100
|
+ u = userAuthLocal.getUserByname(user.getName());
|
|
|
101
|
+
|
|
|
102
|
+ if (u == null) {
|
|
|
103
|
+ model.addAttribute("message", "用户名不存在,如有需要请联系管理员添加用户");
|
|
|
104
|
+ return new ModelAndView("user/login");
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ if (!u.getPwd().equals(MD5Util.encryption(user.getPwd()))) {
|
|
|
108
|
+ model.addAttribute("message", "密码错误");
|
|
|
109
|
+ return new ModelAndView("user/login");
|
|
|
110
|
+ }
|
|
|
111
|
+
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
|
114
|
+ //用户放到session
|
75
|
session.setAttribute("user", u);
|
115
|
session.setAttribute("user", u);
|
|
|
116
|
+
|
76
|
if(StringUtils.isBlank(Directional.getInstance().getLoginTargetUrl())){
|
117
|
if(StringUtils.isBlank(Directional.getInstance().getLoginTargetUrl())){
|
77
|
return new ModelAndView("dashBoard/dashBoard");
|
118
|
return new ModelAndView("dashBoard/dashBoard");
|
78
|
}else{
|
119
|
}else{
|
|
@@ -84,10 +125,6 @@ public class UserCtrl { |
|
@@ -84,10 +125,6 @@ public class UserCtrl { |
84
|
}
|
125
|
}
|
85
|
return null;
|
126
|
return null;
|
86
|
}
|
127
|
}
|
87
|
- } else {
|
|
|
88
|
- model.addAttribute("message", "密码错误");
|
|
|
89
|
- return new ModelAndView("user/login");
|
|
|
90
|
- }
|
|
|
91
|
|
128
|
|
92
|
}
|
129
|
}
|
93
|
|
130
|
|