企通学单点
This commit is contained in:
parent
24485eff0d
commit
bb68a3bc7a
|
|
@ -0,0 +1,13 @@
|
|||
package com.api.organization.web;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 2:34 PM
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Path("/bs/hrmorganization/config")
|
||||
public class ConfigController extends com.engine.organization.web.ConfigController {
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.engine.organization.entity.config.params;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 3:38 PM
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class QTXConfigParam {
|
||||
|
||||
public QTXConfigParam() {
|
||||
this.type = "1";
|
||||
this.domainIndex = "0";
|
||||
this.whole = "0";
|
||||
}
|
||||
|
||||
private String loginId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String domainIndex;
|
||||
|
||||
private String whole;
|
||||
|
||||
private String userAgent;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.engine.organization.entity.config.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 3:34 PM
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QTXConfigPO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String appSecret;
|
||||
|
||||
private String url;
|
||||
|
||||
private String pcAddress;
|
||||
|
||||
private String mobileAddress;
|
||||
|
||||
private String secondUrl;
|
||||
|
||||
private Integer creator;
|
||||
|
||||
private String createDate;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.engine.organization.enums;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 4:29 PM
|
||||
* @Description: 移动端类型
|
||||
* @Version 1.0
|
||||
*/
|
||||
public enum MobileTerminalEnum {
|
||||
Android,
|
||||
iPhone,
|
||||
iPad,
|
||||
Mobile;
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串是否包含某个枚举值
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean containsEnumValue(String str) {
|
||||
for (MobileTerminalEnum myEnum : MobileTerminalEnum.values()) {
|
||||
if (str.contains(myEnum.toString())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.engine.organization.mapper.config;
|
||||
|
||||
|
||||
import com.engine.organization.entity.config.po.QTXConfigPO;
|
||||
|
||||
/**
|
||||
* 企通学配置Mapper
|
||||
*/
|
||||
public interface ConfigMapper {
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 获取配置信息
|
||||
* @Author: liang.cheng
|
||||
* @Date: 2023/8/18 5:01 PM
|
||||
* @param: []
|
||||
* @return: com.engine.organization.entity.config.po.QTXConfigPO
|
||||
*/
|
||||
QTXConfigPO selectConfigInfo();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.engine.organization.mapper.config.ConfigMapper">
|
||||
<resultMap id="BaseResultMap" type="com.engine.organization.entity.config.po.QTXConfigPO">
|
||||
<result column="id" property="id"/>
|
||||
<result column="app_secret" property="appSecret"/>
|
||||
<result column="url" property="url"/>
|
||||
<result column="pc_address" property="pcAddress"/>
|
||||
<result column="mobile_address" property="mobileAddress"/>
|
||||
<result column="second_url" property="secondUrl"/>
|
||||
<result column="creator" property="creator"/>
|
||||
<result column="create_date" property="createDate"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<!-- 表字段 -->
|
||||
<sql id="baseColumns">
|
||||
t.id
|
||||
, t.app_secret
|
||||
, t.url
|
||||
, t.pc_address
|
||||
, t.mobile_address
|
||||
, t.second_url
|
||||
, t.creator
|
||||
, t.create_date
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectConfigInfo" parameterType="com.engine.organization.entity.config.po.QTXConfigPO"
|
||||
resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="baseColumns"/>
|
||||
from JCL_ORG_QTXCONFIG t
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.engine.organization.service;
|
||||
|
||||
import com.engine.organization.entity.config.params.QTXConfigParam;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 2:35 PM
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface ConfigService {
|
||||
|
||||
/**
|
||||
* @Description: 企通学单点地址
|
||||
* @Author: liang.cheng
|
||||
* @Date: 2023/8/18 4:06 PM
|
||||
* @param: [qtxConfigParam]
|
||||
* @return: java.lang.String
|
||||
*/
|
||||
String ssoLogin(QTXConfigParam qtxConfigParam) throws UnsupportedEncodingException;
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.engine.organization.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.entity.config.params.QTXConfigParam;
|
||||
import com.engine.organization.entity.config.po.QTXConfigPO;
|
||||
import com.engine.organization.enums.MobileTerminalEnum;
|
||||
import com.engine.organization.mapper.config.ConfigMapper;
|
||||
import com.engine.organization.service.ConfigService;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import weaver.general.BaseBean;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 2:38 PM
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class ConfigServiceImpl extends Service implements ConfigService {
|
||||
|
||||
private static ConfigMapper getConfigMapper() {
|
||||
return MapperProxyFactory.getProxy(ConfigMapper.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String ssoLogin(QTXConfigParam qtx) throws UnsupportedEncodingException {
|
||||
String hkUrl;
|
||||
BaseBean bb = new BaseBean();
|
||||
String enable = bb.getPropValue("qtx_sso_login", "enable");
|
||||
String userAgent = qtx.getUserAgent();
|
||||
boolean termianal = MobileTerminalEnum.containsEnumValue(userAgent);
|
||||
if (Boolean.parseBoolean(enable)) {
|
||||
QTXConfigPO qtxConfig = getConfigMapper().selectConfigInfo();
|
||||
String domain = "0".equals(qtx.getDomainIndex()) ? qtxConfig.getUrl() : qtxConfig.getSecondUrl();
|
||||
String address = termianal ? qtxConfig.getMobileAddress() : qtxConfig.getPcAddress();
|
||||
String accessKey = URLEncoder.encode(getAccessKey(qtxConfig.getAppSecret()),"utf-8");
|
||||
hkUrl = StrUtil.format("{}/{}?accessKey={}&type={}&username={}&whole={}",domain,address,accessKey,qtx.getType(),qtx.getLoginId(),qtx.getWhole());
|
||||
}else {
|
||||
String accessKey = URLEncoder.encode(getAccessKey(bb.getPropValue("qtx_sso_login", "app_secret")),"utf-8");
|
||||
String domain = "0".equals(qtx.getDomainIndex()) ? bb.getPropValue("qtx_sso_login","url") : bb.getPropValue("qtx_sso_login","url1");
|
||||
String address = termianal ? bb.getPropValue("qtx_sso_login","h5address") : bb.getPropValue("qtx_sso_login","pcaddress");
|
||||
hkUrl = StrUtil.format("{}/{}?accessKey={}&type={}&username={}&whole={}",domain,address,accessKey,qtx.getType(),qtx.getLoginId(),qtx.getWhole());
|
||||
}
|
||||
return hkUrl;
|
||||
}
|
||||
|
||||
private static String getAccessKey(String appSecret) {
|
||||
String data = System.currentTimeMillis() + "||" + appSecret;
|
||||
String IV = appSecret.substring(appSecret.length() - 16);
|
||||
String keys = appSecret.substring(0, 16);
|
||||
return encryptData(data, keys, IV);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: AES加密
|
||||
* @Author: liang.cheng
|
||||
* @Date: 2023/8/18 4:45 PM
|
||||
* @param: [data, key, IV]
|
||||
* @return: java.lang.String
|
||||
*/
|
||||
private static String encryptData(String data, String key, String IV) {
|
||||
try {
|
||||
//算法/模式/填充模式 AES/CBC/PKCS5Padding
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
|
||||
int plaintextLength = dataBytes.length;
|
||||
byte[] plaintext = new byte[plaintextLength];
|
||||
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
|
||||
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
|
||||
IvParameterSpec ivspec = new IvParameterSpec(IV.getBytes());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
|
||||
byte[] encrypted = cipher.doFinal(plaintext);
|
||||
//输出内容,Base64处理
|
||||
return new String(Base64.encodeBase64(encrypted));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.engine.organization.web;
|
||||
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.organization.entity.config.params.QTXConfigParam;
|
||||
import com.engine.organization.service.ConfigService;
|
||||
import com.engine.organization.service.impl.ConfigServiceImpl;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/8/18 2:29 PM
|
||||
* @Description: 配置入口
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class ConfigController {
|
||||
|
||||
|
||||
public ConfigService getConfigService(User user) {
|
||||
return ServiceUtil.getService(ConfigServiceImpl.class,user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/ssoLogin")
|
||||
public void ssoLogin(@Context HttpServletRequest request, @Context HttpServletResponse response,
|
||||
@QueryParam("type") String type,@QueryParam("domainIndex") String domainIndex,@QueryParam("whole") String whole) throws IOException {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
QTXConfigParam qtxConfigParam = QTXConfigParam.builder().loginId(user.getLoginid()).type(type).domainIndex(domainIndex).whole(whole)
|
||||
.userAgent(request.getHeader("user-agent")).build();
|
||||
String url = getConfigService(user).ssoLogin(qtxConfigParam);
|
||||
response.sendRedirect(url);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue