作者 shenhailong

添加 远程登录

@@ -10,6 +10,11 @@ package com.agent.controller.system; @@ -10,6 +10,11 @@ package com.agent.controller.system;
10 import javax.annotation.Resource; 10 import javax.annotation.Resource;
11 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletRequest;
12 12
  13 +
  14 +import com.agent.entity.system.FunctionEntity;
  15 +import com.agent.vo.MenuVo;
  16 +import com.framework.util.PropertiesLoader;
  17 +import com.framework.util.StringUtils;
13 import org.apache.shiro.SecurityUtils; 18 import org.apache.shiro.SecurityUtils;
14 import org.apache.shiro.authc.IncorrectCredentialsException; 19 import org.apache.shiro.authc.IncorrectCredentialsException;
15 import org.apache.shiro.authc.LockedAccountException; 20 import org.apache.shiro.authc.LockedAccountException;
@@ -18,6 +23,7 @@ import org.apache.shiro.authc.UsernamePasswordToken; @@ -18,6 +23,7 @@ import org.apache.shiro.authc.UsernamePasswordToken;
18 import org.apache.shiro.subject.Subject; 23 import org.apache.shiro.subject.Subject;
19 import org.springframework.stereotype.Controller; 24 import org.springframework.stereotype.Controller;
20 import org.springframework.transaction.annotation.Transactional; 25 import org.springframework.transaction.annotation.Transactional;
  26 +import org.springframework.web.bind.annotation.RequestBody;
21 import org.springframework.web.bind.annotation.RequestMapping; 27 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.bind.annotation.RequestMethod; 28 import org.springframework.web.bind.annotation.RequestMethod;
23 import org.springframework.web.bind.annotation.ResponseBody; 29 import org.springframework.web.bind.annotation.ResponseBody;
@@ -39,6 +45,9 @@ import com.framework.util.MD5Tools; @@ -39,6 +45,9 @@ import com.framework.util.MD5Tools;
39 import login.FLogin; 45 import login.FLogin;
40 import login.LoginData; 46 import login.LoginData;
41 47
  48 +import java.util.List;
  49 +import java.util.Map;
  50 +
42 @Controller 51 @Controller
43 public class LoginController { 52 public class LoginController {
44 53
@@ -57,7 +66,7 @@ public class LoginController { @@ -57,7 +66,7 @@ public class LoginController {
57 66
58 /** 67 /**
59 * 登录页面 68 * 登录页面
60 - * 69 + *
61 * @return 70 * @return
62 */ 71 */
63 @RequestMapping(value = "/login", method = RequestMethod.GET) 72 @RequestMapping(value = "/login", method = RequestMethod.GET)
@@ -72,7 +81,7 @@ public class LoginController { @@ -72,7 +81,7 @@ public class LoginController {
72 81
73 /** 82 /**
74 * 查看用户名 83 * 查看用户名
75 - * 84 + *
76 * @param userName 85 * @param userName
77 * @return 86 * @return
78 */ 87 */
@@ -93,7 +102,7 @@ public class LoginController { @@ -93,7 +102,7 @@ public class LoginController {
93 102
94 /** 103 /**
95 * 验证验证码是否正确 104 * 验证验证码是否正确
96 - * 105 + *
97 * @param confirmCaptcha 106 * @param confirmCaptcha
98 * @return 107 * @return
99 */ 108 */
@@ -127,7 +136,7 @@ public class LoginController { @@ -127,7 +136,7 @@ public class LoginController {
127 136
128 /** 137 /**
129 * 找回密码页面 138 * 找回密码页面
130 - * 139 + *
131 * @return 140 * @return
132 */ 141 */
133 @RequestMapping(value = "/retrieve/list") 142 @RequestMapping(value = "/retrieve/list")
@@ -137,20 +146,22 @@ public class LoginController { @@ -137,20 +146,22 @@ public class LoginController {
137 146
138 /** 147 /**
139 * 处理登录操作 148 * 处理登录操作
140 - * 149 + *
141 * @return 150 * @return
142 */ 151 */
143 @Transactional 152 @Transactional
144 @RequestMapping(value = "/doLogin", method = RequestMethod.POST) 153 @RequestMapping(value = "/doLogin", method = RequestMethod.POST)
145 @ResponseBody 154 @ResponseBody
146 public ResponseModel doLogin(String loginAccount, String password, String captcha) { 155 public ResponseModel doLogin(String loginAccount, String password, String captcha) {
  156 +
147 SessionUtil.putKey(Constants.CAPTCHA, ""); 157 SessionUtil.putKey(Constants.CAPTCHA, "");
148 ResponseModel rm = new ResponseModel(200, "", null); 158 ResponseModel rm = new ResponseModel(200, "", null);
149 159
150 UserEntity user = new UserEntity(); 160 UserEntity user = new UserEntity();
151 user.setLoginaccount(loginAccount); 161 user.setLoginaccount(loginAccount);
152 user.setPassword(password); 162 user.setPassword(password);
153 - if (!loginAccount.equals("admin")) { 163 +
  164 + if (!loginAccount.equals("admin") && "true".equals(PropertiesLoader.getLogin("openRemoteLogin"))) {
154 // 远程登录 165 // 远程登录
155 // 用户数据 166 // 用户数据
156 LoginData login = FLogin.login(user); 167 LoginData login = FLogin.login(user);
@@ -234,99 +245,65 @@ public class LoginController { @@ -234,99 +245,65 @@ public class LoginController {
234 245
235 return rm; 246 return rm;
236 } 247 }
237 - 248 +
  249 +
238 /** 250 /**
239 - * 登录操作api  
240 - *  
241 - * @return  
242 - */  
243 - @RequestMapping(value = "/loginApi", method = RequestMethod.POST)  
244 - public String loginApi(HttpServletRequest request) {  
245 - ResponseModel rm = new ResponseModel(200, "", null);  
246 - HttpUtil util=new HttpUtil();  
247 -  
248 - String url="http://10.5.13.25/services/rest/token/verifySAMLResponse";  
249 - String SAMLResponse=request.getParameter("SAMLResponse");  
250 - String providerId=request.getParameter("providerId");  
251 - System.out.println("providerId----->"+providerId);  
252 -  
253 - String result=util.sendData(url,SAMLResponse,providerId);  
254 -  
255 - System.out.println("result----->"+result);  
256 - System.out.print("SAMLResponse------>"+SAMLResponse);  
257 - JSONObject j = JSONObject.parseObject(result);  
258 -  
259 - if(request!=null){  
260 - if("0x0000".equals(j.get("status"))){  
261 -  
262 - UserEntity user = new UserEntity();  
263 - user.setLoginaccount(j.get("appLoginID").toString());  
264 - user.setPassword(j.get("appLoginPass").toString());  
265 - if (!j.get("appLoginID").toString().equals("admin")) {}  
266 - // 远程登录  
267 - // 用户数据  
268 - LoginData login = FLogin.login(user);  
269 - // 登录成功!  
270 - if (login.getCode() == 20000) {  
271 - // 往数据库中插入数据  
272 - UserEntity ue = userService.findByLoginaccount(user.getLoginaccount());  
273 - // 用户存在  
274 - if (ue != null) {  
275 - // 修改密码  
276 - userService.updatePassword(ue.getLoginaccount(), MD5Tools.MD5(j.get("appLoginPass").toString()));  
277 - } else {  
278 - // 用户不存在,插入数据  
279 - BasicAgentEntity agent = new BasicAgentEntity();  
280 - agent.setContact(login.getInfodata().getContact());  
281 - agent.setNameCn(login.getInfodata().getCompany());  
282 - agent.setCountryCode("CN");  
283 - agent.setAddress(login.getInfodata().getAddress());  
284 - int agent_id = agentSerive.save2(agent);  
285 -  
286 - ue = new UserEntity();  
287 - ue.setLoginaccount(j.get("appLoginID").toString());  
288 - // 设置用户名密码  
289 - ue.setPassword(MD5Tools.MD5(j.get("appLoginPass").toString()));  
290 - ue.setRealName(login.getInfodata().getContact());  
291 - ue.setMobile(login.getInfodata().getMobile());  
292 - ue.setStatus(0);  
293 - ue.setAgent(new Long(agent_id));  
294 - RoleEntity re = new RoleEntity();  
295 - re.setId(new Long(1));  
296 - ue.setRole(re);  
297 - // 删除密码  
298 - userService.save(ue);  
299 - }  
300 -  
301 - // 登录用户  
302 - Subject subject = SecurityUtils.getSubject();  
303 - subject.getSession().setAttribute("user", user);  
304 - UsernamePasswordToken token = null;  
305 - token = new UsernamePasswordToken(j.get("appLoginID").toString(), MD5Tools.MD5(j.get("appLoginPass").toString()));  
306 -  
307 - try {  
308 - subject.login(token);  
309 - subject.getSession().setAttribute("permission", roleService  
310 - .findAllFunctionByRole(((UserEntity) subject.getSession().getAttribute("user")).getRole()));  
311 - subject.getSession().setAttribute("all_function", functionService.findAll());  
312 - return "redirect:/index";  
313 - } catch (UnknownAccountException e) {  
314 - e.printStackTrace();  
315 - rm.setStatus(500);  
316 - rm.setMsg("账号不存在");  
317 - } catch (IncorrectCredentialsException e) {  
318 - e.printStackTrace();  
319 - rm.setStatus(500);  
320 - rm.setMsg("密码错误");  
321 - } catch (LockedAccountException e) {  
322 - e.printStackTrace();  
323 - rm.setStatus(500);  
324 - rm.setMsg("账号被锁定");  
325 - }  
326 - }  
327 - }  
328 -  
329 - }  
330 - return "login";  
331 - } 251 + * 登录操作api
  252 + *
  253 + * @return
  254 + */
  255 + @RequestMapping(value = "/loginApi", method = RequestMethod.POST)
  256 + public String loginApi(HttpServletRequest request) {
  257 + ResponseModel rm = new ResponseModel(200, "", null);
  258 + HttpUtil util=new HttpUtil();
  259 +
  260 + String url="http://10.5.13.25/services/rest/token/verifySAMLResponse";
  261 + String SAMLResponse=request.getParameter("SAMLResponse");
  262 + String providerId=request.getParameter("providerId");
  263 + System.out.println("providerId----->"+providerId);
  264 +
  265 + String result=util.sendData(url,SAMLResponse,providerId);
  266 +
  267 + System.out.println("result----->"+result);
  268 + System.out.print("SAMLResponse------>"+SAMLResponse);
  269 + JSONObject j = JSONObject.parseObject(result);
  270 +
  271 + if(request!=null){
  272 + if("0x0000".equals(j.get("status"))){
  273 +
  274 + UserEntity user = new UserEntity();
  275 + user.setLoginaccount(j.get("appLoginID").toString());
  276 + user.setPassword(j.get("appLoginPass").toString());
  277 +
  278 + // 登录用户
  279 + Subject subject = SecurityUtils.getSubject();
  280 + subject.getSession().setAttribute("user", user);
  281 + UsernamePasswordToken token = null;
  282 + token = new UsernamePasswordToken(j.get("appLoginID").toString(), MD5Tools.MD5(j.get("appLoginPass").toString()));
  283 +
  284 + try {
  285 + subject.login(token);
  286 + subject.getSession().setAttribute("permission", roleService
  287 + .findAllFunctionByRole(((UserEntity) subject.getSession().getAttribute("user")).getRole()));
  288 + subject.getSession().setAttribute("all_function", functionService.findAll());
  289 + return "redirect:/index";
  290 + } catch (UnknownAccountException e) {
  291 + e.printStackTrace();
  292 + rm.setStatus(500);
  293 + rm.setMsg("账号不存在");
  294 + } catch (IncorrectCredentialsException e) {
  295 + e.printStackTrace();
  296 + rm.setStatus(500);
  297 + rm.setMsg("密码错误");
  298 + } catch (LockedAccountException e) {
  299 + e.printStackTrace();
  300 + rm.setStatus(500);
  301 + rm.setMsg("账号被锁定");
  302 + }
  303 + }
  304 + }
  305 +
  306 +
  307 + return "login";
  308 + }
332 } 309 }
  1 +#远程登录 开关
  2 +openRemoteLogin = true