|
|
@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
import com.auth0.jwt.JWT; |
|
|
|
|
|
|
|
import com.auth0.jwt.interfaces.DecodedJWT; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.dxhy.itax.annotation.SysLog; |
|
|
|
import com.dxhy.itax.annotation.SysLog; |
|
|
|
import com.dxhy.itax.config.*; |
|
|
|
import com.dxhy.itax.config.*; |
|
|
@ -16,8 +18,10 @@ import com.dxhy.itax.dto.response.QsTypeResponse; |
|
|
|
import com.dxhy.itax.dto.response.TabInfoResponse; |
|
|
|
import com.dxhy.itax.dto.response.TabInfoResponse; |
|
|
|
import com.dxhy.itax.dto.response.XxTabinfoResponse; |
|
|
|
import com.dxhy.itax.dto.response.XxTabinfoResponse; |
|
|
|
import com.dxhy.itax.entity.CountItemConfig; |
|
|
|
import com.dxhy.itax.entity.CountItemConfig; |
|
|
|
|
|
|
|
import com.dxhy.itax.entity.SysUserEntity; |
|
|
|
import com.dxhy.itax.entity.SystenConfiguration; |
|
|
|
import com.dxhy.itax.entity.SystenConfiguration; |
|
|
|
import com.dxhy.itax.enums.*; |
|
|
|
import com.dxhy.itax.enums.*; |
|
|
|
|
|
|
|
import com.dxhy.itax.model.JwtToken; |
|
|
|
import com.dxhy.itax.model.LoginModel; |
|
|
|
import com.dxhy.itax.model.LoginModel; |
|
|
|
import com.dxhy.itax.model.UserInfo; |
|
|
|
import com.dxhy.itax.model.UserInfo; |
|
|
|
import com.dxhy.itax.openapi.model.ShortMessageRequest; |
|
|
|
import com.dxhy.itax.openapi.model.ShortMessageRequest; |
|
|
@ -40,6 +44,7 @@ import io.swagger.annotations.ApiOperation; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.ui.Model; |
|
|
|
import org.springframework.ui.Model; |
|
|
@ -49,7 +54,10 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
import java.net.MalformedURLException; |
|
|
|
|
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -104,6 +112,12 @@ public class WebController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ItaxAdminConfig itaxAdminConfig; |
|
|
|
private ItaxAdminConfig itaxAdminConfig; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private OATokenService oaTokenService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${oauth.whitelist}") |
|
|
|
|
|
|
|
private String whitelist; |
|
|
|
|
|
|
|
|
|
|
|
private Set<String> urlSet = new HashSet<String>(); |
|
|
|
private Set<String> urlSet = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
private final String firCount = "1"; |
|
|
|
private final String firCount = "1"; |
|
|
@ -156,6 +170,211 @@ public class WebController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@RequestMapping("/otherLogin") |
|
|
|
|
|
|
|
public void otherLogin(LoginModel loginModel,HttpServletResponse response) throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始执行登录
|
|
|
|
|
|
|
|
String username = AESUtil.aesDecrypt(loginModel.getDxhyu()); |
|
|
|
|
|
|
|
log.info("用户{},登录开始", username); |
|
|
|
|
|
|
|
ReturnT<UserInfo> result = userService.findUser(loginModel.getDxhyu(), loginModel.getDxhyp()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("用户{},登录结果:{}", username, JSON.toJSONString(result)); |
|
|
|
|
|
|
|
if (result.getCode() != SUCCESS_CODE){ |
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
response.getWriter().write(result.getMsg()); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
boolean ifRem = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SsoUser xxlUser = new SsoUser(); |
|
|
|
|
|
|
|
xxlUser.setUserId(result.getData().getUserid()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserInfoRequestDto userInfoRequestDto = new UserInfoRequestDto(); |
|
|
|
|
|
|
|
userInfoRequestDto.setUserId(result.getData().getUserid()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Result result1 = userService.queryUserInfo(userInfoRequestDto); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (result1.get("code").equals("0000")) { |
|
|
|
|
|
|
|
xxlUser = JsonUtils.getInstance().parseObject(result1.get("data").toString(), SsoUser.class); |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(xxlUser.getTaxplayercodeDeptList())){ |
|
|
|
|
|
|
|
xxlUser.setCurrentDeptId(xxlUser.getTaxplayercodeDeptList().get(0).getDeptId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("获取到的用户信息{},{}", xxlUser.getUserId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
|
|
|
log.info("获取菜单异常" + JSONObject.toJSONString(ex)); |
|
|
|
|
|
|
|
log.info("用户{},登录失败", username); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xxlUser.setUsername(username); |
|
|
|
|
|
|
|
xxlUser.setVersion(UUID.randomUUID().toString().replaceAll("-", "")); |
|
|
|
|
|
|
|
xxlUser.setExpireMinite(SsoLoginStore.getRedisExpireMinite()); |
|
|
|
|
|
|
|
xxlUser.setExpireFreshTime(System.currentTimeMillis()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2、make session id
|
|
|
|
|
|
|
|
String sessionId = SsoSessionIdHelper.makeSessionId(xxlUser); |
|
|
|
|
|
|
|
log.info("存储的用户信息{},{}", xxlUser.getUserId()); |
|
|
|
|
|
|
|
// 3、login, store storeKey + cookie sessionId
|
|
|
|
|
|
|
|
SsoWebLoginHelper.login(response, sessionId, xxlUser, ifRem); |
|
|
|
|
|
|
|
log.info("用户{},登录成功,sessionID是{}", username, sessionId); |
|
|
|
|
|
|
|
//4.更新last_login_time
|
|
|
|
|
|
|
|
userService.updateLastLoginTime(xxlUser.getUserId()); |
|
|
|
|
|
|
|
String url = itaxAdminConfig.getItaxbenchfront(); |
|
|
|
|
|
|
|
log.info("外放登陆跳转地址:{}", url); |
|
|
|
|
|
|
|
response.sendRedirect(url); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/singleLogin") |
|
|
|
|
|
|
|
public void reOA(@RequestParam Map<String,Object> params,HttpServletResponse response) throws IOException { |
|
|
|
|
|
|
|
Object code = params.get("code"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(code==null){ |
|
|
|
|
|
|
|
log.info("单电登陆code为空"); |
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
response.getWriter().write("<!DOCTYPE html> \n" + |
|
|
|
|
|
|
|
"<html lang=\"zh-CN\"> \n" + |
|
|
|
|
|
|
|
"<head> \n" + |
|
|
|
|
|
|
|
" <meta charset=\"UTF-8\"> \n" + |
|
|
|
|
|
|
|
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> \n" + |
|
|
|
|
|
|
|
" <title>发票系统单点登陆结果</title> \n" + |
|
|
|
|
|
|
|
" <style> \n" + |
|
|
|
|
|
|
|
" body { \n" + |
|
|
|
|
|
|
|
" font-family: Arial, sans-serif; \n" + |
|
|
|
|
|
|
|
" margin: 40px; \n" + |
|
|
|
|
|
|
|
" padding: 20px; \n" + |
|
|
|
|
|
|
|
" background-color: #f4f4f4; \n" + |
|
|
|
|
|
|
|
" color: #333; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" .container { \n" + |
|
|
|
|
|
|
|
" background-color: #fff; \n" + |
|
|
|
|
|
|
|
" padding: 20px; \n" + |
|
|
|
|
|
|
|
" border-radius: 8px; \n" + |
|
|
|
|
|
|
|
" box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" h2 { \n" + |
|
|
|
|
|
|
|
" color: #5cb85c; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" /* 添加这个类来指定查询结果提示的颜色为红色 */ \n" + |
|
|
|
|
|
|
|
" .result-error { \n" + |
|
|
|
|
|
|
|
" color: red; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" p { \n" + |
|
|
|
|
|
|
|
" margin: 10px 0; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" </style> \n" + |
|
|
|
|
|
|
|
"</head> \n" + |
|
|
|
|
|
|
|
"<body> \n" + |
|
|
|
|
|
|
|
" <div class=\"container\"> \n" + |
|
|
|
|
|
|
|
" <h2 class=\"result-error\">单点登陆失败</h2>\n" + |
|
|
|
|
|
|
|
" <!-- 使用新的类名来指定颜色 --> \n" + |
|
|
|
|
|
|
|
" <p>罗欣统一认证系统未返回发票系统有效参数</p>\n" + |
|
|
|
|
|
|
|
" <p>请尝试以下解决方案:</p> \n" + |
|
|
|
|
|
|
|
" <ul> \n" + |
|
|
|
|
|
|
|
" <li>联系运维人员,排查相关问题。</li>\n" + |
|
|
|
|
|
|
|
" </ul> \n" + |
|
|
|
|
|
|
|
" </div> \n" + |
|
|
|
|
|
|
|
"</body> \n" + |
|
|
|
|
|
|
|
"</html>"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("单点登陆code"+code.toString()); |
|
|
|
|
|
|
|
JwtToken jwt = oaTokenService.getOauth2Token(code.toString()); |
|
|
|
|
|
|
|
DecodedJWT decode = JWT.decode(jwt.getAccessToken()); |
|
|
|
|
|
|
|
String username = decode.getClaim("preferred_username").asString(); |
|
|
|
|
|
|
|
log.debug("单电登陆解析accessToken:{}",JSON.toJSONString(decode)); |
|
|
|
|
|
|
|
//开始执行登录
|
|
|
|
|
|
|
|
log.info("用户{},登录开始", username); |
|
|
|
|
|
|
|
boolean ifRem = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysUserEntity user = userService.findUserByName(username); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("用户查询结果{}",JSON.toJSONString(user)); |
|
|
|
|
|
|
|
if (user == null){ |
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
PrintWriter writer = response.getWriter(); |
|
|
|
|
|
|
|
writer.write("<!DOCTYPE html> \n" + |
|
|
|
|
|
|
|
"<html lang=\"zh-CN\"> \n" + |
|
|
|
|
|
|
|
"<head> \n" + |
|
|
|
|
|
|
|
" <meta charset=\"UTF-8\"> \n" + |
|
|
|
|
|
|
|
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> \n" + |
|
|
|
|
|
|
|
" <title>发票系统单点登陆结果</title> \n" + |
|
|
|
|
|
|
|
" <style> \n" + |
|
|
|
|
|
|
|
" body { \n" + |
|
|
|
|
|
|
|
" font-family: Arial, sans-serif; \n" + |
|
|
|
|
|
|
|
" margin: 40px; \n" + |
|
|
|
|
|
|
|
" padding: 20px; \n" + |
|
|
|
|
|
|
|
" background-color: #f4f4f4; \n" + |
|
|
|
|
|
|
|
" color: #333; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" .container { \n" + |
|
|
|
|
|
|
|
" background-color: #fff; \n" + |
|
|
|
|
|
|
|
" padding: 20px; \n" + |
|
|
|
|
|
|
|
" border-radius: 8px; \n" + |
|
|
|
|
|
|
|
" box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" h2 { \n" + |
|
|
|
|
|
|
|
" color: #5cb85c; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" /* 添加这个类来指定查询结果提示的颜色为红色 */ \n" + |
|
|
|
|
|
|
|
" .result-error { \n" + |
|
|
|
|
|
|
|
" color: red; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" p { \n" + |
|
|
|
|
|
|
|
" margin: 10px 0; \n" + |
|
|
|
|
|
|
|
" } \n" + |
|
|
|
|
|
|
|
" </style> \n" + |
|
|
|
|
|
|
|
"</head> \n" + |
|
|
|
|
|
|
|
"<body> \n" + |
|
|
|
|
|
|
|
" <div class=\"container\"> \n" + |
|
|
|
|
|
|
|
" <h2 class=\"result-error\">单点登陆失败</h2>\n" + |
|
|
|
|
|
|
|
" <!-- 使用新的类名来指定颜色 --> \n" + |
|
|
|
|
|
|
|
" <p>您在发票系统中的信息未找到。</p>\n" + |
|
|
|
|
|
|
|
" <p>请尝试以下解决方案:</p> \n" + |
|
|
|
|
|
|
|
" <ul> \n" + |
|
|
|
|
|
|
|
" <li>联系运维人员,请求配置相关信息。</li>\n" + |
|
|
|
|
|
|
|
" </ul> \n" + |
|
|
|
|
|
|
|
" </div> \n" + |
|
|
|
|
|
|
|
"</body> \n" + |
|
|
|
|
|
|
|
"</html>"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SsoUser xxlUser = new SsoUser(); |
|
|
|
|
|
|
|
xxlUser.setUserId(user.getUserId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserInfoRequestDto userInfoRequestDto = new UserInfoRequestDto(); |
|
|
|
|
|
|
|
userInfoRequestDto.setUserId(user.getUserId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Result result1 = userService.queryUserInfo(userInfoRequestDto); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (result1.get("code").equals("0000")) { |
|
|
|
|
|
|
|
xxlUser = JsonUtils.getInstance().parseObject(result1.get("data").toString(), SsoUser.class); |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(xxlUser.getTaxplayercodeDeptList())){ |
|
|
|
|
|
|
|
xxlUser.setCurrentDeptId(xxlUser.getTaxplayercodeDeptList().get(0).getDeptId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("获取到的用户信息{},{}", xxlUser.getUserId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
|
|
|
log.info("获取菜单异常" + JSONObject.toJSONString(ex)); |
|
|
|
|
|
|
|
log.info("用户{},登录失败", username); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xxlUser.setUsername(user.getUsername()); |
|
|
|
|
|
|
|
xxlUser.setVersion(UUID.randomUUID().toString().replaceAll("-", "")); |
|
|
|
|
|
|
|
xxlUser.setExpireMinite(SsoLoginStore.getRedisExpireMinite()); |
|
|
|
|
|
|
|
xxlUser.setExpireFreshTime(System.currentTimeMillis()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2、make session id
|
|
|
|
|
|
|
|
String sessionId = SsoSessionIdHelper.makeSessionId(xxlUser); |
|
|
|
|
|
|
|
log.info("存储的用户信息{},{}", xxlUser.getUserId()); |
|
|
|
|
|
|
|
// 3、login, store storeKey + cookie sessionId
|
|
|
|
|
|
|
|
SsoWebLoginHelper.login(response, sessionId, xxlUser, ifRem); |
|
|
|
|
|
|
|
log.info("用户{},登录成功,sessionID是{}", username, sessionId); |
|
|
|
|
|
|
|
//4.更新last_login_time
|
|
|
|
|
|
|
|
userService.updateLastLoginTime(xxlUser.getUserId()); |
|
|
|
|
|
|
|
String url = itaxAdminConfig.getItaxbenchfront(); |
|
|
|
|
|
|
|
log.info("单点登陆跳转地址:{}", url); |
|
|
|
|
|
|
|
response.sendRedirect(url); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Login |
|
|
|
* Login |
|
|
|
* 实现单点登录并进行跳转方法 |
|
|
|
* 实现单点登录并进行跳转方法 |
|
|
|