Commit 1a2dc33e by Java-张振楠

单点登录

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