瀏覽代碼

添加软件许可证功能

szjbdgzl 2 年之前
父節點
當前提交
631cd92a58

+ 5 - 1
ibps-oauth-root/modules/oauth-base/src/main/java/com/lc/ibps/cloud/oauth/server/service/ITokenService.java

@@ -22,6 +22,8 @@ import com.lc.ibps.cloud.oauth.entity.TokenEntity;
 import com.lc.ibps.cloud.oauth.entity.TokenParamVo;
 import com.lc.ibps.cloud.oauth.entity.TokenVo;
 
+import java.util.Map;
+
 @Validated
 @RestController
 @RequestMapping(value = "/authentication")
@@ -52,5 +54,7 @@ public interface ITokenService {
 	public APIResult<Void> remove(
 			@RequestHeader(name = ParameterKey.HEADER_AUTHORIZATION, required = true) String accessToken,
 			@RequestBody(required = true) TokenParamVo tokenParamVo);
-	
+
+	@RequestMapping(value = "/updateLicense", method = RequestMethod.POST)
+	public APIResult<Void> updateLicense(@RequestBody(required = true)Map<String,Object> map);
 }

+ 8 - 11
ibps-oauth-root/modules/oauth-server2-default/src/main/java/com/lc/ibps/cloud/oauth/server/provider/BaseProvider.java

@@ -6,11 +6,13 @@ import java.util.concurrent.TimeUnit;
 
 import javax.annotation.Resource;
 
+import com.lc.ibps.base.framework.table.ICommonDao;
 import com.lc.ibps.cloud.oauth.exception.*;
 import com.lc.ibps.cloud.oauth.server.util.LicUtil;
 import com.lc.ibps.org.auth.persistence.entity.LoginLogPo;
 import com.lc.ibps.org.auth.persistence.entity.LoginLogTbl;
 import com.lc.ibps.org.auth.repository.LoginLogRepository;
+import com.lc.ibps.org.party.repository.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -52,15 +54,6 @@ import com.lc.ibps.org.auth.persistence.entity.UserSecurityPo;
 import com.lc.ibps.org.auth.repository.UserSecurityRepository;
 import com.lc.ibps.org.party.persistence.entity.DefaultPartyUserPo;
 import com.lc.ibps.org.party.persistence.entity.PartyUserPo;
-import com.lc.ibps.org.party.repository.DefaultPartyRoleRepository;
-import com.lc.ibps.org.party.repository.DefaultPartyUserRepository;
-import com.lc.ibps.org.party.repository.PartyEmployeeRepository;
-import com.lc.ibps.org.party.repository.PartyGroupRepository;
-import com.lc.ibps.org.party.repository.PartyOrgRepository;
-import com.lc.ibps.org.party.repository.PartyPositionRepository;
-import com.lc.ibps.org.party.repository.PartyUserGroupRepository;
-import com.lc.ibps.org.party.repository.PartyUserLimitRepository;
-import com.lc.ibps.org.party.repository.PartyUserRepository;
 import com.lc.ibps.org.spi.SpiUserService;
 import com.lc.ibps.org.spi.SpiUserServiceUtil;
 import com.lc.ibps.register.constants.RegDBConstants;
@@ -88,6 +81,8 @@ public class BaseProvider extends GenericProvider {
 	@Autowired
 	protected PartyEmployeeRepository partyEmployeeRepository;
 	@Autowired
+	protected PartyEntityRepository partyEntityRepository;
+	@Autowired
 	protected AuthClientRepository authClientRepository;
 	@Autowired
 	protected PartyUserLimitRepository partyUserLimitRepository;
@@ -110,6 +105,9 @@ public class BaseProvider extends GenericProvider {
 	protected RegDataRepository regDataRepository;
 	@Resource
 	protected ITenantQueryService tenantQueryService;
+
+	@Resource
+	protected ICommonDao<?> commonDao;
 	
 	@Autowired
 	protected TokenConfig tokenConfig;
@@ -540,8 +538,7 @@ public class BaseProvider extends GenericProvider {
 		RedisUtil.redisTemplateString.delete(key);
 	}
 
-	protected String checkLicense() {
-		String licText = "XnRn48Yl78WS0OWZ0100t2IjyMx0E5Yx0tDz3M1FuubuD25X5aOEKkpWYpYI7p7Md364I7yM2kFIO4c2PYRefWoV06Bypu41QAdKHjEYnS7ml9KPit73JlQ0Zm1OrbADaJF8ezDURnIrFjyr9bMyxaTcfm0THWBHhhnRBZxCmfF0WdMrSmDj76rSqLkZHl3tlSKjwKmjlxcIuSZGZIWiET7+kzLB8FiGMoxw00YWhXBjIpuNkv63CFbU6iOCPN7e7jfUl2medTSj7oyX3vABRFmbCtgBVT7CjWq+Mzb+3B+lJ9R5s0ax+o1rWWL13wbY0+/lylhtKPhIQMMPukx38d80eU8q8bkGoAuOfXjCkLU2QqU28orGQQtxJlJRmStodmqotPD8ETqU4MFq8qIikK3foed+1tOcMw5epFjMuE4v/0Cps8wWARO543quzy8=";
+	protected String checkLicense(String licText) {
 		String licJson = null;
 		try {
 			licJson = LicUtil.checkLic(licText, pubKey);

+ 43 - 6
ibps-oauth-root/modules/oauth-server2-default/src/main/java/com/lc/ibps/cloud/oauth/server/provider/TokenProvider.java

@@ -1,12 +1,12 @@
 package com.lc.ibps.cloud.oauth.server.provider;
 
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 import com.lc.ibps.cloud.oauth.exception.*;
+import com.lc.ibps.org.party.persistence.entity.PartyEmployeePo;
+import com.lc.ibps.org.party.persistence.entity.PartyEntityPo;
+import org.springframework.context.annotation.Bean;
 import org.springframework.data.redis.connection.DataType;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
@@ -51,6 +51,8 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 
+import javax.validation.Valid;
+
 /** 
  * auth2.0 访问令牌控制器
  * <pre> 
@@ -152,7 +154,12 @@ public class TokenProvider extends BaseProvider implements ITokenService {
 			String refreshToken = accessTokenVo.getRefresh_token();
 			String authorizeCode = accessTokenVo.getAuthorize_code();
 			String redirectUri = accessTokenVo.getRedirect_uri();
-			String licJson = checkLicense();
+
+			String org = getOrgByAccount(username);
+			Map<String, Object> lcMap = commonDao.queryOne("select zheng_shu_bian_ma from t_ipcc WHERE org_ = '" + org + "' ");
+			String licText = lcMap.get("zheng_shu_bian_ma").toString();
+
+			String licJson = checkLicense(licText);
 			TokenEntity token = new TokenEntity();
 			logger.debug("grant type is {}", grantType);
 			if(GrantType.AUTHORIZATION_CODE.equalsIgnoreCase(grantType)){
@@ -1132,5 +1139,35 @@ public class TokenProvider extends BaseProvider implements ITokenService {
 		
 		return tokenList;
 	}
-	
+
+	@Override
+	public APIResult<Void> updateLicense(Map<String,Object> map) {
+		APIResult<Void> result = new APIResult<>();
+		try{
+			String username = map.get("username").toString();
+			String licText = map.get("license").toString();
+			String licJson = checkLicense(licText);
+			if (BeanUtils.isNotEmpty(licJson)){
+				String org = getOrgByAccount(username);
+				commonDao.execute("UPDATE t_ipcc set zheng_shu_bian_ma = '" + licText + "' where org_ = '" + org + "' ");
+			}
+			result.getVariables().put("licJson",licJson);
+		} catch(Exception e) {
+			if(StateEnum.SUCCESS.getCode() == result.getState()){
+				result.setState(StateEnum.ILLEGAL_REQUEST.getCode());
+			}
+			result.setCause(ExceptionUtil.analysisCause(e));
+			logger.error("access token failed:", e);
+		}
+		return result;
+	}
+
+	public String getOrgByAccount(String username){
+		PartyUserPo userPo = partyUserRepository.getByAccount(username);
+		PartyEmployeePo employeePo = partyEmployeeRepository.get(userPo.getUserId());
+		String position = employeePo.getPositions().split(",")[0];
+		PartyEntityPo entityPo = partyEntityRepository.get(position);
+		String org = entityPo.getPath().split("\\.")[0];
+		return org;
+	}
 }