...
|
...
|
@@ -10,6 +10,11 @@ package com.agent.controller.system; |
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
import com.agent.entity.system.FunctionEntity;
|
|
|
import com.agent.vo.MenuVo;
|
|
|
import com.framework.util.PropertiesLoader;
|
|
|
import com.framework.util.StringUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authc.IncorrectCredentialsException;
|
|
|
import org.apache.shiro.authc.LockedAccountException;
|
...
|
...
|
@@ -18,6 +23,7 @@ import org.apache.shiro.authc.UsernamePasswordToken; |
|
|
import org.apache.shiro.subject.Subject;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
...
|
...
|
@@ -39,6 +45,9 @@ import com.framework.util.MD5Tools; |
|
|
import login.FLogin;
|
|
|
import login.LoginData;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
public class LoginController {
|
|
|
|
...
|
...
|
@@ -57,7 +66,7 @@ public class LoginController { |
|
|
|
|
|
/**
|
|
|
* 登录页面
|
|
|
*
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/login", method = RequestMethod.GET)
|
...
|
...
|
@@ -72,7 +81,7 @@ public class LoginController { |
|
|
|
|
|
/**
|
|
|
* 查看用户名
|
|
|
*
|
|
|
*
|
|
|
* @param userName
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -93,7 +102,7 @@ public class LoginController { |
|
|
|
|
|
/**
|
|
|
* 验证验证码是否正确
|
|
|
*
|
|
|
*
|
|
|
* @param confirmCaptcha
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -127,7 +136,7 @@ public class LoginController { |
|
|
|
|
|
/**
|
|
|
* 找回密码页面
|
|
|
*
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/retrieve/list")
|
...
|
...
|
@@ -137,20 +146,22 @@ public class LoginController { |
|
|
|
|
|
/**
|
|
|
* 处理登录操作
|
|
|
*
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
@RequestMapping(value = "/doLogin", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public ResponseModel doLogin(String loginAccount, String password, String captcha) {
|
|
|
|
|
|
SessionUtil.putKey(Constants.CAPTCHA, "");
|
|
|
ResponseModel rm = new ResponseModel(200, "", null);
|
|
|
|
|
|
UserEntity user = new UserEntity();
|
|
|
user.setLoginaccount(loginAccount);
|
|
|
user.setPassword(password);
|
|
|
if (!loginAccount.equals("admin")) {
|
|
|
|
|
|
if (!loginAccount.equals("admin") && "true".equals(PropertiesLoader.getLogin("openRemoteLogin"))) {
|
|
|
// 远程登录
|
|
|
// 用户数据
|
|
|
LoginData login = FLogin.login(user);
|
...
|
...
|
@@ -234,99 +245,65 @@ public class LoginController { |
|
|
|
|
|
return rm;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 登录操作api
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/loginApi", method = RequestMethod.POST)
|
|
|
public String loginApi(HttpServletRequest request) {
|
|
|
ResponseModel rm = new ResponseModel(200, "", null);
|
|
|
HttpUtil util=new HttpUtil();
|
|
|
|
|
|
String url="http://10.5.13.25/services/rest/token/verifySAMLResponse";
|
|
|
String SAMLResponse=request.getParameter("SAMLResponse");
|
|
|
String providerId=request.getParameter("providerId");
|
|
|
System.out.println("providerId----->"+providerId);
|
|
|
|
|
|
String result=util.sendData(url,SAMLResponse,providerId);
|
|
|
|
|
|
System.out.println("result----->"+result);
|
|
|
System.out.print("SAMLResponse------>"+SAMLResponse);
|
|
|
JSONObject j = JSONObject.parseObject(result);
|
|
|
|
|
|
if(request!=null){
|
|
|
if("0x0000".equals(j.get("status"))){
|
|
|
|
|
|
UserEntity user = new UserEntity();
|
|
|
user.setLoginaccount(j.get("appLoginID").toString());
|
|
|
user.setPassword(j.get("appLoginPass").toString());
|
|
|
if (!j.get("appLoginID").toString().equals("admin")) {}
|
|
|
// 远程登录
|
|
|
// 用户数据
|
|
|
LoginData login = FLogin.login(user);
|
|
|
// 登录成功!
|
|
|
if (login.getCode() == 20000) {
|
|
|
// 往数据库中插入数据
|
|
|
UserEntity ue = userService.findByLoginaccount(user.getLoginaccount());
|
|
|
// 用户存在
|
|
|
if (ue != null) {
|
|
|
// 修改密码
|
|
|
userService.updatePassword(ue.getLoginaccount(), MD5Tools.MD5(j.get("appLoginPass").toString()));
|
|
|
} else {
|
|
|
// 用户不存在,插入数据
|
|
|
BasicAgentEntity agent = new BasicAgentEntity();
|
|
|
agent.setContact(login.getInfodata().getContact());
|
|
|
agent.setNameCn(login.getInfodata().getCompany());
|
|
|
agent.setCountryCode("CN");
|
|
|
agent.setAddress(login.getInfodata().getAddress());
|
|
|
int agent_id = agentSerive.save2(agent);
|
|
|
|
|
|
ue = new UserEntity();
|
|
|
ue.setLoginaccount(j.get("appLoginID").toString());
|
|
|
// 设置用户名密码
|
|
|
ue.setPassword(MD5Tools.MD5(j.get("appLoginPass").toString()));
|
|
|
ue.setRealName(login.getInfodata().getContact());
|
|
|
ue.setMobile(login.getInfodata().getMobile());
|
|
|
ue.setStatus(0);
|
|
|
ue.setAgent(new Long(agent_id));
|
|
|
RoleEntity re = new RoleEntity();
|
|
|
re.setId(new Long(1));
|
|
|
ue.setRole(re);
|
|
|
// 删除密码
|
|
|
userService.save(ue);
|
|
|
}
|
|
|
|
|
|
// 登录用户
|
|
|
Subject subject = SecurityUtils.getSubject();
|
|
|
subject.getSession().setAttribute("user", user);
|
|
|
UsernamePasswordToken token = null;
|
|
|
token = new UsernamePasswordToken(j.get("appLoginID").toString(), MD5Tools.MD5(j.get("appLoginPass").toString()));
|
|
|
|
|
|
try {
|
|
|
subject.login(token);
|
|
|
subject.getSession().setAttribute("permission", roleService
|
|
|
.findAllFunctionByRole(((UserEntity) subject.getSession().getAttribute("user")).getRole()));
|
|
|
subject.getSession().setAttribute("all_function", functionService.findAll());
|
|
|
return "redirect:/index";
|
|
|
} catch (UnknownAccountException e) {
|
|
|
e.printStackTrace();
|
|
|
rm.setStatus(500);
|
|
|
rm.setMsg("账号不存在");
|
|
|
} catch (IncorrectCredentialsException e) {
|
|
|
e.printStackTrace();
|
|
|
rm.setStatus(500);
|
|
|
rm.setMsg("密码错误");
|
|
|
} catch (LockedAccountException e) {
|
|
|
e.printStackTrace();
|
|
|
rm.setStatus(500);
|
|
|
rm.setMsg("账号被锁定");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return "login";
|
|
|
}
|
|
|
* 登录操作api
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/loginApi", method = RequestMethod.POST)
|
|
|
public String loginApi(HttpServletRequest request) {
|
|
|
ResponseModel rm = new ResponseModel(200, "", null);
|
|
|
HttpUtil util=new HttpUtil();
|
|
|
|
|
|
String url="http://10.5.13.25/services/rest/token/verifySAMLResponse";
|
|
|
String SAMLResponse=request.getParameter("SAMLResponse");
|
|
|
String providerId=request.getParameter("providerId");
|
|
|
System.out.println("providerId----->"+providerId);
|
|
|
|
|
|
String result=util.sendData(url,SAMLResponse,providerId);
|
|
|
|
|
|
System.out.println("result----->"+result);
|
|
|
System.out.print("SAMLResponse------>"+SAMLResponse);
|
|
|
JSONObject j = JSONObject.parseObject(result);
|
|
|
|
|
|
if(request!=null){
|
|
|
if("0x0000".equals(j.get("status"))){
|
|
|
|
|
|
UserEntity user = new UserEntity();
|
|
|
user.setLoginaccount(j.get("appLoginID").toString());
|
|
|
user.setPassword(j.get("appLoginPass").toString());
|
|
|
|
|
|
// 登录用户
|
|
|
Subject subject = SecurityUtils.getSubject();
|
|
|
subject.getSession().setAttribute("user", user);
|
|
|
UsernamePasswordToken token = null;
|
|
|
token = new UsernamePasswordToken(j.get("appLoginID").toString(), MD5Tools.MD5(j.get("appLoginPass").toString()));
|
|
|
|
|
|
try {
|
|
|
subject.login(token);
|
|
|
subject.getSession().setAttribute("permission", roleService
|
|
|
.findAllFunctionByRole(((UserEntity) subject.getSession().getAttribute("user")).getRole()));
|
|
|
subject.getSession().setAttribute("all_function", functionService.findAll());
|
|
|
return "redirect:/index";
|
|
|
} catch (UnknownAccountException e) {
|
|
|
e.printStackTrace();
|
|
|
rm.setStatus(500);
|
|
|
rm.setMsg("账号不存在");
|
|
|
} catch (IncorrectCredentialsException e) {
|
|
|
e.printStackTrace();
|
|
|
rm.setStatus(500);
|
|
|
rm.setMsg("密码错误");
|
|
|
} catch (LockedAccountException e) {
|
|
|
e.printStackTrace();
|
|
|
rm.setStatus(500);
|
|
|
rm.setMsg("账号被锁定");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return "login";
|
|
|
}
|
|
|
} |
...
|
...
|
|