use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class PmphLoginController method ssoLogin.
/**
* <pre>
* 功能描述:SSO登陆
* 使用示范:
*
* @param request
* @return
* </pre>
*/
@ResponseBody
@RequestMapping(value = "/sso", method = RequestMethod.GET)
public ResponseBean ssoLogin(HttpServletRequest request, HttpServletResponse response) {
String sessionId = CookiesUtil.getSessionId(request);
PmphUser pmUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
Map<String, Object> resultMap = new HashMap<String, Object>();
HttpSingleSignOnService service = new HttpSingleSignOnService();
// String url = service.getSingleSignOnURL();
try {
Principal principal = service.singleSignOn(request);
String userName = principal.getName();
PmphUser pmphUser = pmphUserService.login(userName, null);
if (ObjectUtil.isNull(pmphUser)) {
// 为空就新建一个用户
pmphUser = pmphUserService.add(new PmphUser(userName, "888888", userName, "DEFAULT"));
// 添加默认权限
pmphRoleService.addUserRole(pmphUser.getId(), 2L);
}
pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
}
// 根据用户Id查询对应角色(是否为管理员)
List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
List<Long> roleIds = new ArrayList<Long>(pmphRoles.size());
for (PmphRole pmphRole : pmphRoles) {
roleIds.add(pmphRole.getId());
if (ObjectUtil.notNull(pmphRole)) {
if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
pmphUser.setIsAdmin(true);
} else {
pmphUser.setIsAdmin(false);
}
}
if (Const.TRUE == pmphUser.getIsAdmin()) {
break;
}
}
// 根据用户Id查询对应权限Id
List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
// 验证成功在Session中保存用户信息
request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
// 验证成功在Session中保存用户Token信息
request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(userName, userName).enpsw);
// pmphUserSessionId
resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(userName, userName).enpsw);
resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
return new ResponseBean(resultMap);
} catch (SingleSignOnException e) {
return new ResponseBean(e);
}
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class WriterLoginController method login.
/**
* <pre>
* 功能描述:登陆
* 使用示范:
*
* @param user
* @param model
* @return
* </pre>
*/
@ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam("username") String username, @RequestParam("password") String password, HttpServletRequest request) {
logger.info("username => " + username);
logger.info("password => " + password);
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
WriterUser writerUser = writerUserService.login(username, new DesRun("", password).enpsw);
writerUser.setLoginType(Const.LOGIN_TYPE_WRITER);
if (!RouteUtil.DEFAULT_USER_AVATAR.equals(writerUser.getAvatar())) {
writerUser.setAvatar(RouteUtil.userAvatar(writerUser.getAvatar()));
}
// 根据用户Id查询对应权限Id
List<Long> writerUserPermissionIds = writerUserService.getWriterUserPermissionByUserId(writerUser.getId());
// 验证成功在Session中保存用户信息
request.getSession().setAttribute(Const.SESSION_WRITER_USER, writerUser);
// 验证成功在Session中保存用户Token信息
request.getSession().setAttribute(Const.SEESION_WRITER_USER_TOKEN, new DesRun(password, username).enpsw);
resultMap.put(Const.USER_SEESION_ID, new DesRun("", request.getSession().getId()).enpsw);
resultMap.put(Const.SESSION_WRITER_USER, writerUser);
resultMap.put(Const.SEESION_WRITER_USER_TOKEN, new DesRun(password, username).enpsw);
resultMap.put("writerUserPermissionIds", writerUserPermissionIds);
return new ResponseBean(resultMap);
} catch (CheckedServiceException cException) {
return new ResponseBean(cException);
}
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class OrgUserServiceImpl method addOrgUserAndOrgOfBack.
@Override
public Object addOrgUserAndOrgOfBack(OrgUser orgUser, Org org) {
if (orgUserDao.getOrgUsername(orgUser.getUsername()).size() > 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "该机构代码已被使用,请重新输入");
}
if (StringUtil.isEmpty(orgUser.getUsername())) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "机构代码不能为空");
}
if (StringUtil.strLength(orgUser.getUsername()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "机构代码不能超过20个字符");
}
if (!StringUtil.isEmpty(orgUser.getNote())) {
if (StringUtil.strLength(orgUser.getNote()) > 100) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "备注不能超过100个字符");
}
}
if (ObjectUtil.isNull(org)) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
// }
if (StringUtil.isEmpty(org.getOrgName())) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "机构名称为空");
}
if (StringUtil.strLength(org.getOrgName()) > 20) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "机构名称过长");
}
if (orgDao.getOrgByOrgName(org.getOrgName()).size() > 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.ILLEGAL_PARAM, "该机构名称已被使用,请重新输入");
}
if (ObjectUtil.isNull(org.getOrgTypeId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.NULL_PARAM, "机构类型不能为空");
}
if (ObjectUtil.isNull(org.getAreaId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.NULL_PARAM, "所属区域不能为空");
}
// if (null == org.getContactPerson()) {
// throw new CheckedServiceException(CheckedExceptionBusiness.ORG,
// CheckedExceptionResult.NULL_PARAM,
// "机构联系人不能为空");
// }
// if (null == org.getContactPhone()) {
// throw new CheckedServiceException(CheckedExceptionBusiness.ORG,
// CheckedExceptionResult.NULL_PARAM,
// "机构联系电话不能为空");
// }
orgDao.addOrg(org);
if (StringUtil.isEmpty(orgUser.getRealname())) {
orgUser.setRealname(orgUser.getUsername());
}
// 默认机构用户头像路径
orgUser.setAvatar(RouteUtil.DEFAULT_USER_AVATAR);
orgUser.setOrgId(orgDao.getOrgid(org.getOrgName()));
// 后台添加用户设置默认密码为123456
orgUser.setPassword(new DesRun("", Const.DEFAULT_PASSWORD).enpsw);
SsoHelper ssoHelper = context.getBean(SsoHelper.class);
String result = ssoHelper.createSSOAccount(orgUser);
if (!result.equals("success")) {
throw new CheckedServiceException(CheckedExceptionBusiness.ORG, CheckedExceptionResult.FAILURE_SSO_CALLBACK, result);
}
// 返回的影响行数,如果不是影响0行就是添加成功
int num = orgUserDao.addOrgUser(orgUser);
result = "FAIL";
if (num > 0) {
result = "SUCCESS";
}
return result;
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class WeChatLoginController method load.
/**
* <pre>
* 功能描述:加载个人信息,此处添加了@OAuthRequired注解
* 使用示范:
*
* @param request
* @param model
* @return
* </pre>
*/
@RequestMapping(value = { "/wechatUserInfo" })
@OAuthRequired
public Object load(HttpServletRequest request, Model model) {
// System.out.println("Load a User!");
HttpSession session = request.getSession();
// 判断是否从企业微信App登陆
model.addAttribute("Userid", session.getAttribute("UserId"));
String userAgent = request.getHeader("user-agent").toLowerCase();
Boolean isTrue = userAgent == null || userAgent.indexOf("micromessenger") == -1 ? false : true;
if (isTrue) {
String wechatUserId = (String) session.getAttribute("UserId");
if (StringUtil.isEmpty(wechatUserId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "网络异常,请重新再试!");
}
PmphUserWechat pmphUserWechat = pmphUserWechatService.getPmphUserWechatByWechatId(wechatUserId);
if (ObjectUtil.isNull(pmphUserWechat)) {
model.addAttribute("isLogin", "0");
} else {
PmphUser pu = pmphUserService.getPmphUserByUsername(pmphUserWechat.getUsername());
if (ObjectUtil.notNull(pu)) {
String username = new DesRun(null, pmphUserWechat.getUsername()).enpsw;
String password = pu.getPassword();
model.addAttribute(Const.PMPH_WECHAT_USER_TOKEN, new DesRun(password, username + password + wechatUserId + "<pmpheep>").enpsw);
model.addAttribute("username", username);
model.addAttribute("password", password);
model.addAttribute("isLogin", "1");
}
}
}
return "wechat";
}
use of com.bc.pmpheep.back.util.DesRun in project pmph by BCSquad.
the class WriterUserServiceImpl method resetPassword.
@Override
public String resetPassword(Long id) throws CheckedServiceException {
if (null == id) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
String password = "888888";
WriterUser user = writerUserDao.get(id);
DesRun desRun = new DesRun(user.getUsername(), password);
user.setPassword(desRun.enpsw);
writerUserDao.update(user);
return password;
}
Aggregations