...
|
...
|
@@ -6,12 +6,22 @@ import javax.annotation.Resource; |
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import com.agent.entity.system.*;
|
|
|
import com.agent.service.system.FunctionService;
|
|
|
import com.agent.util.HttpClientUtil;
|
|
|
import com.google.gson.Gson;
|
|
|
import jdk.nashorn.internal.runtime.regexp.RegExp;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authc.UnknownAccountException;
|
|
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
|
|
import org.apache.shiro.subject.Subject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
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;
|
...
|
...
|
@@ -32,6 +42,21 @@ import com.plugin.easyui.EasyPage; |
|
|
@RequestMapping({"/system/user" })
|
|
|
public class UserController extends BasicController {
|
|
|
|
|
|
/**
|
|
|
* 验证服务票据响应属性名
|
|
|
*/
|
|
|
private static final String SERVICE_RESPONESE = "serviceResponse";
|
|
|
private static final String AUTHENTICATION_SUCCESS = "authenticationSuccess";
|
|
|
private static final String LOGIN_NAME = "LOGIN_NAME";
|
|
|
private static final String ATTRIBUTES = "attributes";
|
|
|
private static final String USER_ID = "USER_ID";
|
|
|
|
|
|
@Value("${ger.req-url}")
|
|
|
private String requestUrl;
|
|
|
|
|
|
@Value("${ger.res-url}")
|
|
|
private String responseUrl;
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
|
|
|
|
|
|
@Resource
|
...
|
...
|
@@ -43,6 +68,9 @@ public class UserController extends BasicController { |
|
|
@Resource
|
|
|
private BasicAgentService agentService;
|
|
|
|
|
|
@Resource
|
|
|
private FunctionService functionService;
|
|
|
|
|
|
/**
|
|
|
* 用户账号管理
|
|
|
* @return
|
...
|
...
|
@@ -246,62 +274,137 @@ public class UserController extends BasicController { |
|
|
return model;
|
|
|
}
|
|
|
|
|
|
// /**
|
|
|
// * 资源同步
|
|
|
// */
|
|
|
// @RequestMapping(value = "/userSynchronization")
|
|
|
// @ResponseBody
|
|
|
// public ResultMessage userSynchronization(@RequestBody UAM uam) throws Exception {
|
|
|
// if ("user".equals(uam.getResType())){
|
|
|
// List<UserData> data = uam.getData();
|
|
|
// // 判断该用户是否存在
|
|
|
// int i = 0;
|
|
|
// for (UserData userData: data){
|
|
|
// if (userService.countLonginName(userData.getLOGIN_NAME()) > 0){
|
|
|
/**
|
|
|
* 资源同步
|
|
|
*/
|
|
|
@RequestMapping(value = "/userSynchronization", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public ResultMessage userSynchronization(@RequestBody UAM uam) throws Exception {
|
|
|
if ("user".equals(uam.getResType())){
|
|
|
List<UserData> data = uam.getData();
|
|
|
// 判断该用户是否存在
|
|
|
int i = 0;
|
|
|
for (UserData userData: data){
|
|
|
if (userService.findLoginaccount(userData.getLOGIN_NAME()) != null){
|
|
|
// log.info("通过账号为条件更新");
|
|
|
// i = userService.updateSyncUserLoginName(userData);
|
|
|
// }else {
|
|
|
// if (kakoUserMapperl.findLonginName("", userDate.getUSER_ID()) != null){
|
|
|
// KakoUser kakoUser = new KakoUser();
|
|
|
// kakoUser.setLoginName(userDate.getLOGIN_NAME());
|
|
|
// kakoUser.setPassword(userDate.getPWD());
|
|
|
// kakoUser.setUserSyncId(userDate.getUSER_ID());
|
|
|
// kakoUser.setMobile(userDate.getMOBILE());
|
|
|
// kakoUser.setEmail(userDate.getEMAIL());
|
|
|
// kakoUser.setDelFlag("0");
|
|
|
// kakoUser.setName(userDate.getUSER_NAME());
|
|
|
// kakoUser.setCompanyId("1");
|
|
|
// kakoUser.setOfficeId("5e95a0f081c64fce9f85d59e18cfdc5f");
|
|
|
// kakoUser.setUpdateBy("tyrz");
|
|
|
// kakoUser.setLoginFlag("1");
|
|
|
// kakoUser.setUpdateDate(new Date());
|
|
|
i = userService.updateSyncUserLoginName(userData);
|
|
|
}else {
|
|
|
if (userService.findUamId(userData.getUSER_ID()) != null){
|
|
|
// log.info("账号不存在用过统一认证id更新");
|
|
|
// i = kakoUserMapperl.updateSyncUserId(kakoUser);
|
|
|
// }else {
|
|
|
// KakoUser kakoUser = new KakoUser();
|
|
|
// kakoUser.setId(UUID.randomUUID().toString());
|
|
|
// kakoUser.setLoginName(userDate.getLOGIN_NAME());
|
|
|
// kakoUser.setPassword(userDate.getPWD());
|
|
|
// kakoUser.setUserSyncId(userDate.getUSER_ID());
|
|
|
// kakoUser.setMobile(userDate.getMOBILE());
|
|
|
// kakoUser.setEmail(userDate.getEMAIL());
|
|
|
// kakoUser.setName(userDate.getUSER_NAME());
|
|
|
// kakoUser.setCompanyId("1");
|
|
|
// kakoUser.setOfficeId("5e95a0f081c64fce9f85d59e18cfdc5f");
|
|
|
// kakoUser.setLoginFlag("1");
|
|
|
// kakoUser.setCreateBy("tyrz");
|
|
|
// kakoUser.setUpdateBy("tyrz");
|
|
|
// kakoUser.setCreateDate(new Date());
|
|
|
// kakoUser.setUpdateDate(new Date());
|
|
|
i = userService.updateSyncUserId(userData);
|
|
|
}else {
|
|
|
// log.info("账号统一认证id都不在 新增");
|
|
|
// i = kakoUserMapperl.insertSelective(kakoUser);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// return i > 0 ? new ResultMessage("200","资源同步成功"):new ResultMessage("202", "资源同步失败");
|
|
|
// }
|
|
|
// return new ResultMessage("201","不是用户信息");
|
|
|
// }
|
|
|
UserEntity userEntity = new UserEntity();
|
|
|
userEntity.setPassword(userData.getPWD());
|
|
|
userEntity.setLoginaccount(userData.getLOGIN_NAME());
|
|
|
userEntity.setRealName(userData.getUSER_NAME());
|
|
|
userEntity.setMobile(userData.getMOBILE());
|
|
|
userEntity.setUamId(userData.getUSER_ID());
|
|
|
userEntity.setStatus(0);
|
|
|
userEntity.setLoginerror(0);
|
|
|
if (userService.save(userEntity)!=null){
|
|
|
i = 1;
|
|
|
}else {
|
|
|
i = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return i > 0 ? new ResultMessage("200","资源同步成功"):new ResultMessage("202", "资源同步失败");
|
|
|
}
|
|
|
return new ResultMessage("201","不是用户信息");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 转发致ssoLoginjsp页面
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/uamJump")
|
|
|
public String ssoLoginJsp(){
|
|
|
return "ssoLogin";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 验证票据
|
|
|
* @param ticket
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@RequestMapping (value = "/ssoLogin")
|
|
|
@ResponseBody
|
|
|
public ResponseModel ssoLogin(String ticket) throws Exception {
|
|
|
ResponseModel responseModel = new ResponseModel();
|
|
|
try {
|
|
|
// log.info("票据接受:{}", ticket);
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(ticket)){
|
|
|
// log.info("开始验证票据");
|
|
|
String result = HttpClientUtil.httpGet("http://10.5.14.103:27080/sso/p3/serviceValidate?format=json&service="+"http://10.50.3.73:8003/sso/ssoLogin.html"+"&ticket="+ticket, "UTF-8");
|
|
|
// log.info("验证票据返回值:{}", result);
|
|
|
Map<String, Object> userInfo = resolveUserInfo(result);
|
|
|
if (userInfo != null){
|
|
|
UserEntity user = userService.findLoginaccount(userInfo.get("loginName").toString());
|
|
|
// log.info("查询用户信息:{}", user);
|
|
|
if (user != null){
|
|
|
// 登录用户
|
|
|
Subject subject = SecurityUtils.getSubject();
|
|
|
subject.getSession().setAttribute("user", user);
|
|
|
UsernamePasswordToken token = new UsernamePasswordToken(user.getLoginaccount(), user.getPassword());
|
|
|
try {
|
|
|
subject.login(token);
|
|
|
subject.getSession().setAttribute("permission", roleService
|
|
|
.findAllFunctionByRole(((UserEntity) subject.getSession().getAttribute("user")).getRole()));
|
|
|
subject.getSession().setAttribute("all_function", functionService.findAll());
|
|
|
//登录成功 请空失败次数
|
|
|
userService.emptyLoginerror(user.getLoginaccount());
|
|
|
responseModel.setStatus(200);
|
|
|
return responseModel;
|
|
|
} catch (UnknownAccountException e) {
|
|
|
responseModel.setStatus(500);
|
|
|
responseModel.setMsg("1");
|
|
|
}
|
|
|
}else {
|
|
|
responseModel.setStatus(204);
|
|
|
responseModel.setMsg("该用户不存在本系统,请先去同步信息");
|
|
|
return responseModel;
|
|
|
}
|
|
|
}else {
|
|
|
responseModel.setStatus(203);
|
|
|
responseModel.setMsg("远程获取用户信息失败"+result);
|
|
|
return responseModel;
|
|
|
}
|
|
|
}else {
|
|
|
responseModel.setStatus(202);
|
|
|
responseModel.setMsg("票据为空,获取失败");
|
|
|
return responseModel;
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
responseModel.setStatus(201);
|
|
|
responseModel.setMsg(e.toString());
|
|
|
return responseModel;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> resolveUserInfo(String result){
|
|
|
// result="{\"serviceResponse\":{\"authenticationSuccess\":{\"user\":\"shenhl\",\"attributes\":{\"isFromNewLogin\":[false],\"authenticationDate\":[1630484829.010000000],\"successfulAuthenticationHandlers\":[\"pwd\"],\"USER_ID\":\"1338722569884504064\",\"USER_NAME\":\"申海龙\",\"extend\":[],\"credentialType\":\"UsernamePasswordCredential\",\"samlAuthenticationStatementAuthMethod\":\"urn:oasis:names:tc:SAML:1.0:am:password\",\"ipTerritory\":\"\",\"authenticationMethod\":\"pwd\",\"equipType\":\"pc\",\"clientIp\":\"172.19.0.1\",\"isDefaultPwd\":\"false\",\"longTermAuthenticationRequestTokenUsed\":[false],\"LOGIN_NAME\":\"shenhl\",\"MOBILE\":\"17600319854\"}}}}";
|
|
|
//认证成功,解析用户信息
|
|
|
Gson gson = new Gson();
|
|
|
Map resultMap = gson.fromJson(result, Map.class);
|
|
|
Object serviceResponse = resultMap.get(SERVICE_RESPONESE);
|
|
|
if(serviceResponse != null && serviceResponse instanceof Map){
|
|
|
Object authenticationSuccess = ((Map) serviceResponse).get(AUTHENTICATION_SUCCESS);
|
|
|
if(authenticationSuccess != null && authenticationSuccess instanceof Map){
|
|
|
Map<String, Object> userInfo = new HashMap<>();
|
|
|
userInfo.put("attributes", ((Map) authenticationSuccess).get(ATTRIBUTES));
|
|
|
Object attributes = ((Map) authenticationSuccess).get("attributes");
|
|
|
userInfo.put("loginName", ((Map) attributes).get(LOGIN_NAME));
|
|
|
userInfo.put("userId", ((Map) attributes).get(USER_ID));
|
|
|
return userInfo;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|