Commit 1a2dc33e by Java-张振楠

单点登录

parent 5f12e018
...@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* Created by lenovo on 2017/9/7. * Created by zhangzn on 2017/9/7.
*/ */
@RestController @RestController
......
...@@ -66,7 +66,7 @@ public class LoginController extends BaseController{ ...@@ -66,7 +66,7 @@ public class LoginController extends BaseController{
@RequestMapping(value = "${adminPath}/login", method = RequestMethod.GET) @RequestMapping(value = "${adminPath}/login", method = RequestMethod.GET)
public String login(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException { public String login(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
Principal principal = UserUtils.getPrincipal(); Principal principal = UserUtils.getPrincipal();
String token=request.getParameter("Token"); String token=request.getParameter("token");
// 单点登录 // 单点登录
if(StringUtils.isNoneBlank(token)){ if(StringUtils.isNoneBlank(token)){
...@@ -75,7 +75,7 @@ public class LoginController extends BaseController{ ...@@ -75,7 +75,7 @@ public class LoginController extends BaseController{
Resource resource = resourceLoader.getResource("LtpaToken.properties"); Resource resource = resourceLoader.getResource("LtpaToken.properties");
// String filePath =getClass().getResource("/LtpaToken.properties").getPath(); // String filePath =getClass().getResource("/LtpaToken.properties").getPath();
String filePath =resource.getURL().getPath(); String filePath =resource.getURL().getPath();
LtpaTokenManager.loadConfig(filePath); LtpaTokenManager.loadConfig(URLDecoder.decode(URLDecoder.decode(filePath)));
token = URLDecoder.decode(token); token = URLDecoder.decode(token);
token = URLDecoder.decode(token); token = URLDecoder.decode(token);
if (LtpaTokenManager.isValid(token)) {//验证Token是否合法有效 if (LtpaTokenManager.isValid(token)) {//验证Token是否合法有效
...@@ -91,112 +91,112 @@ public class LoginController extends BaseController{ ...@@ -91,112 +91,112 @@ public class LoginController extends BaseController{
String captcha= DigestUtils.md5Hex(userName+token); String captcha= DigestUtils.md5Hex(userName+token);
logger.info(".............captcha:" + captcha); logger.info(".............captcha:" + captcha);
upt.setCaptcha(captcha); upt.setCaptcha(captcha);
LDAPUtil util = new LDAPUtil(); // LDAPUtil util = new LDAPUtil();
util.connectLdap();//链接IDM // util.connectLdap();//链接IDM
try { try {
// 获取用户组织 // // 获取用户组织
String orgDisplayName = util.GetUserInfo(userName, "ORGDISPLAYNAME"); // String orgDisplayName = util.GetUserInfo(userName, "ORGDISPLAYNAME");
if(StringUtils.isNoneBlank(orgDisplayName) && !orgDisplayName.contains(GConstants.ORG_DISPLAY_NAME)) { // if(StringUtils.isNoneBlank(orgDisplayName) && !orgDisplayName.contains(GConstants.ORG_DISPLAY_NAME)) {
logger.info("..................\"非\" + GConstants.ORG_DISPLAY_NAME + \"区域人员,不能登录系统!\""); // logger.info("..................\"非\" + GConstants.ORG_DISPLAY_NAME + \"区域人员,不能登录系统!\"");
throw new NullPointerException("非" + GConstants.ORG_DISPLAY_NAME + "区域人员,不能登录系统!"); // throw new NullPointerException("非" + GConstants.ORG_DISPLAY_NAME + "区域人员,不能登录系统!");
} // }
User user= systemService.getUserByLoginName(userName); User user= systemService.getUserByLoginName(userName);
logger.info(".....................user:" + user); logger.info(".....................user:" + user);
if(user==null){ // 从接口获取用户信息 // if(user==null){ // 从接口获取用户信息
logger.info("..................数据库没有用户信息。"); // logger.info("..................数据库没有用户信息。");
// HCFetcher fetcher = HCFetcher.getInstance(); // // HCFetcher fetcher = HCFetcher.getInstance();
// String content="{\"versionName\": \"1.0\",\"platform\": \"Android\",\"appCode\": \"30005\",\"language\": \"zh_CN\",\"deviceToken\": \"\",\"appkey\": \"\"," + // // String content="{\"versionName\": \"1.0\",\"platform\": \"Android\",\"appCode\": \"30005\",\"language\": \"zh_CN\",\"deviceToken\": \"\",\"appkey\": \"\"," +
// "\"loginName\":\"" +userName + "\"}"; // // "\"loginName\":\"" +userName + "\"}";
// String url=GConstants.FAQ_BASE_API+"/api/user/getUserLoginName?sign=sign&content="+content; // // String url=GConstants.FAQ_BASE_API+"/api/user/getUserLoginName?sign=sign&content="+content;
// System.out.print(url); // // System.out.print(url);
// // //
// List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>(); // // List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
// 添加参数 // // 添加参数
// params.add(new BasicNameValuePair("content", content)); // // params.add(new BasicNameValuePair("content", content));
// params.add(new BasicNameValuePair("sign", "sign")); // // params.add(new BasicNameValuePair("sign", "sign"));
// FetchEntity entity = fetcher.post(GConstants.FAQ_BASE_API+"/api/user/getUserLoginName",params ,null); // // FetchEntity entity = fetcher.post(GConstants.FAQ_BASE_API+"/api/user/getUserLoginName",params ,null);
// FetchEntity entity = fetcher.post(GConstants.FAQ_BASE_API+"/api/user/getUserLoginName?sign=sign&content="+content, null); // // FetchEntity entity = fetcher.post(GConstants.FAQ_BASE_API+"/api/user/getUserLoginName?sign=sign&content="+content, null);
logger.info("..................从core中查到的数据entity:" + JSON.toJSONString(entity)); // logger.info("..................从core中查到的数据entity:" + JSON.toJSONString(entity));
// if(entity.isSuccess()){ // // if(entity.isSuccess()){
logger.info("..................从融创查到了用户信息1。"); // logger.info("..................从融创查到了用户信息1。");
// String resultStr = entity.getContent("utf-8"); // // String resultStr = entity.getContent("utf-8");
// if (resultStr != null) {// 成功获取数据 // // if (resultStr != null) {// 成功获取数据
logger.info("..................从融创查到了用户信息2。"); // logger.info("..................从融创查到了用户信息2。");
// ResponseBean requestBean= JSON.parseObject(resultStr, ResponseBean.class); // // ResponseBean requestBean= JSON.parseObject(resultStr, ResponseBean.class);
// if(!"2000".equals(requestBean.getStatus())){ // // if(!"2000".equals(requestBean.getStatus())){
// logger.info("..................找不到此用户的部门或组织!"); // // logger.info("..................找不到此用户的部门或组织!");
// throw new NullPointerException("找不到此用户的部门或组织!"); // // throw new NullPointerException("找不到此用户的部门或组织!");
// } // // }
// requestBean.getData(); // // requestBean.getData();
// UserInfoEntity userInfo = JSON.parseObject(requestBean.getData().toString(), UserInfoEntity.class); // // UserInfoEntity userInfo = JSON.parseObject(requestBean.getData().toString(), UserInfoEntity.class);
//
// if(userInfo!=null){ // // if(userInfo!=null){
logger.info("..................从融创查到了用户信息3。"); // logger.info("..................从融创查到了用户信息3。");
user= new User(); // user= new User();
user.setId(IdWorker.getNextId("U")); // user.setId(IdWorker.getNextId("U"));
user.setLoginName(userName); // user.setLoginName(userName);
//
String name = util.GetUserInfo(userName, "cn"); // String name = util.GetUserInfo(userName, "cn");
user.setName(name); // user.setName(name);
//
user.setPassword(systemService.entryptPassword(token)); // user.setPassword(systemService.entryptPassword(token));
user.setLoginFlag("1"); // user.setLoginFlag("1");
user.setDelFlag("0"); // user.setDelFlag("0");
user.setRemarks(systemService.entryptPassword("同步用户")); // user.setRemarks(systemService.entryptPassword("同步用户"));
Date createDate = new Date(); // Date createDate = new Date();
user.setCreateBy(user); // user.setCreateBy(user);
user.setCreateDate(createDate); // user.setCreateDate(createDate);
user.setUpdateBy(user); // user.setUpdateBy(user);
user.setUpdateDate(createDate); // user.setUpdateDate(createDate);
//
// Office office = officeService.findByOfficeName(userInfo.getDepartName()); // // Office office = officeService.findByOfficeName(userInfo.getDepartName());
// if(office==null){ // // if(office==null){
// office=new Office(); // // office=new Office();
// office.preInsert(); // // office.preInsert();
// office.setName(userInfo.getDepartName()); // // office.setName(userInfo.getDepartName());
// office.setParent(officeService.getCompany()); // // office.setParent(officeService.getCompany());
// // //
// office.setParentIds("0,1,"+office.getParentId()); // // office.setParentIds("0,1,"+office.getParentId());
// office.setType(""); // // office.setType("");
// office.setGrade(""); // // office.setGrade("");
// office.setCreateBy(user); // // office.setCreateBy(user);
// office.setUpdateBy(user); // // office.setUpdateBy(user);
// office.setSort(0); // // office.setSort(0);
// Area area=new Area(); // // Area area=new Area();
// area.setId(""); // // area.setId("");
// office.setArea(area); // // office.setArea(area);
// officeService.insert(office); // // officeService.insert(office);
// } // // }
// user.setOffice(office); // // user.setOffice(office);
List<Role> listRole=new ArrayList<>(); // List<Role> listRole=new ArrayList<>();
Role r=new Role(); // Role r=new Role();
r.setId("3"); // r.setId("3");
listRole.add(r); // listRole.add(r);
user.setRoleList(listRole); // user.setRoleList(listRole);
//
// if(StringUtils.isNoneBlank(userInfo.getLongName())){ // // if(StringUtils.isNoneBlank(userInfo.getLongName())){
// String[] offs=userInfo.getLongName().split("_"); // // String[] offs=userInfo.getLongName().split("_");
// // //
// if(offs.length>3){ // // if(offs.length>3){
// List<String> list=new ArrayList<String>(); // // List<String> list=new ArrayList<String>();
// for(int i=3;i<offs.length;i++){ // // for(int i=3;i<offs.length;i++){
// list.add(offs[i]); // // list.add(offs[i]);
// // //
// } // // }
// user.setOfficeName(StringUtils.join(list.toArray(),"_")); // // user.setOfficeName(StringUtils.join(list.toArray(),"_"));
// // //
// } // // }
// } // // }
systemService.insertUser(user); // systemService.insertUser(user);
logger.info("..................向数据库中添加用户信息成功。"); // logger.info("..................向数据库中添加用户信息成功。");
// } // // }
// } // // }
// } // // }
} // }
}catch (Exception e){ }catch (Exception e){
throw new AuthenticationException(e.getMessage()); throw new AuthenticationException(e.getMessage());
}finally { }finally {
util.closeLdap(); // util.closeLdap();
} }
UserUtils.getSubject().login(upt); UserUtils.getSubject().login(upt);
return "redirect:" + adminPath; return "redirect:" + adminPath;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment