get token
This commit is contained in:
parent
852705bff1
commit
17c4508aad
|
|
@ -9,14 +9,19 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.bonus.canteen.core.auth.oauth.util.OAuthUtil;
|
import com.bonus.canteen.core.auth.oauth.util.OAuthUtil;
|
||||||
|
import com.bonus.canteen.core.auth.oauth.vo.OpenApiLoginVo;
|
||||||
import com.bonus.canteen.core.auth.user.dto.UserLoginDTO;
|
import com.bonus.canteen.core.auth.user.dto.UserLoginDTO;
|
||||||
import com.bonus.canteen.core.config.AccessToken;
|
import com.bonus.canteen.core.common.utils.TenantContextHolder;
|
||||||
import com.bonus.canteen.core.config.SecureProperties;
|
import com.bonus.canteen.core.config.*;
|
||||||
import com.bonus.canteen.core.config.SmUtils;
|
|
||||||
import com.bonus.canteen.core.config.WebContext;
|
|
||||||
import com.bonus.canteen.core.customer.model.PigxUser;
|
import com.bonus.canteen.core.customer.model.PigxUser;
|
||||||
import com.bonus.canteen.core.device.mq.MacMessageService;
|
import com.bonus.canteen.core.device.mq.MacMessageService;
|
||||||
|
import com.bonus.canteen.core.merchant.entity.MercMerchant;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.constants.CheckEnum;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.model.OpenApp;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.service.OpenAppService;
|
||||||
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.common.houqin.constant.LeConstants;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
@ -66,35 +71,33 @@ public class AuthController {
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// @Lazy
|
// @Lazy
|
||||||
// BackDeviceApi backDeviceApi;
|
// BackDeviceApi backDeviceApi;
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private OpenAppService openAppService;
|
private OpenAppService openAppService;
|
||||||
|
|
||||||
// @RequireVerifyCode
|
@PostMapping({"/web/token"})
|
||||||
// @PostMapping({"/web/token"})
|
@ApiOperation("web登陆")
|
||||||
// @RequiresGuest
|
public AjaxResult webLogin(@RequestParam String content) {
|
||||||
// @ApiOperation("web登陆")
|
UserLoginDTO loginDTO = (UserLoginDTO)JSON.parseObject(content, UserLoginDTO.class);
|
||||||
// public LeResponse<JSONObject> webLogin(@RequestParam String content) {
|
|
||||||
// MgrUserLoginDTO loginDTO = (MgrUserLoginDTO)JSON.parseObject(content, MgrUserLoginDTO.class);
|
JSONObject object;
|
||||||
//
|
try {
|
||||||
// JSONObject object;
|
PigxUser user = new PigxUser(); //this.mgrUserService.login(loginDTO);
|
||||||
// try {
|
object = JSON.parseObject(JSON.toJSONString(user));
|
||||||
// PigxUser user = this.mgrUserService.login(loginDTO);
|
if (ObjectUtil.isNotNull(user.getMerchantId())) {
|
||||||
// object = JSON.parseObject(JSON.toJSONString(user));
|
TenantContextHolder.setTenantId(user.getMerchantId());
|
||||||
// if (ObjectUtil.isNotNull(user.getMerchantId())) {
|
MercMerchant mercMerchant = this.mercMerchantApi.getMerchant();
|
||||||
// TenantContextHolder.setTenantId(user.getMerchantId());
|
object.put("merchantName", mercMerchant.getMerchantName());
|
||||||
// MercMerchant mercMerchant = this.mercMerchantApi.getMerchant();
|
}
|
||||||
// object.put("merchantName", mercMerchant.getMerchantName());
|
|
||||||
// }
|
if (WebContext.get().getAccessToken().isPresent()) {
|
||||||
//
|
object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId()));
|
||||||
// if (WebContext.get().getAccessToken().isPresent()) {
|
}
|
||||||
// object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId()));
|
} catch (Exception var6) {
|
||||||
// }
|
return AjaxResult.error(var6.getMessage());
|
||||||
// } catch (LeCheckedException var6) {
|
}
|
||||||
// return LeResponse.fail(var6.getMessage());
|
|
||||||
// }
|
return AjaxResult.success(object);
|
||||||
//
|
}
|
||||||
// return LeResponse.succ(object);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@PostMapping({"/token"})
|
@PostMapping({"/token"})
|
||||||
@ApiOperation("设备登陆接口登陆")
|
@ApiOperation("设备登陆接口登陆")
|
||||||
|
|
@ -117,18 +120,13 @@ public class AuthController {
|
||||||
return AjaxResult.success(object);
|
return AjaxResult.success(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @DeleteMapping({"/logOut"})
|
@DeleteMapping({"/logOut"})
|
||||||
// @RequiresAuthentication
|
@ApiOperation("退出登陆")
|
||||||
// @ApiOperation("退出登陆")
|
public AjaxResult logOut() {
|
||||||
// @AnLogRecord(
|
SecureManager.logout();
|
||||||
// value = "退出登录",
|
return AjaxResult.success("操作成功");
|
||||||
// type = LogRecordOperTypeEnum.SIGN_OUT
|
}
|
||||||
// )
|
|
||||||
// public LeResponse<String> logOut() {
|
|
||||||
// SecureManager.logout();
|
|
||||||
// return LeResponse.succ("操作成功");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @PostMapping({"/public/login"})
|
// @PostMapping({"/public/login"})
|
||||||
// @RequiresGuest
|
// @RequiresGuest
|
||||||
// @ApiOperation("采购库存公众号登陆接口")
|
// @ApiOperation("采购库存公众号登陆接口")
|
||||||
|
|
@ -158,7 +156,6 @@ public class AuthController {
|
||||||
//
|
//
|
||||||
// @ApiOperation("web-单点登陆")
|
// @ApiOperation("web-单点登陆")
|
||||||
// @PostMapping({"/web/single-sign-on"})
|
// @PostMapping({"/web/single-sign-on"})
|
||||||
// @RequiresGuest
|
|
||||||
// public PigxUser webSingleSignOn(@RequestParam("tenantId") Long tenantId, @RequestBody LeRequest<MgrUserSsoDTO> request) {
|
// public PigxUser webSingleSignOn(@RequestParam("tenantId") Long tenantId, @RequestBody LeRequest<MgrUserSsoDTO> request) {
|
||||||
// return this.mgrUserService.webSingleSignOn(tenantId, (MgrUserSsoDTO)request.getContent());
|
// return this.mgrUserService.webSingleSignOn(tenantId, (MgrUserSsoDTO)request.getContent());
|
||||||
// }
|
// }
|
||||||
|
|
@ -232,44 +229,42 @@ public class AuthController {
|
||||||
return SmUtils.signAuthTokenBySm3(paramMap, clientKey);
|
return SmUtils.signAuthTokenBySm3(paramMap, clientKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ApiOperation("openapi认证")
|
@ApiOperation("openapi认证")
|
||||||
// @PostMapping({"/openapi/login"})
|
@PostMapping({"/openapi/login"})
|
||||||
// @RequiresGuest
|
public OpenApiLoginVo openApiLogin(@RequestHeader Map<String, String> header, @RequestBody Map<String, String> content) {
|
||||||
// @ResponseWrapperByPass
|
String appIdEncrypt = (String)content.get("content");
|
||||||
// public OpenApiLoginVo openApiLogin(@RequestHeader Map<String, String> header, @RequestBody Map<String, String> content) {
|
if (ObjectUtil.isNull(appIdEncrypt)) {
|
||||||
// String appIdEncrypt = (String)content.get("content");
|
throw new ServiceException(CheckEnum.VALID_APPID_MISS.getCode() + CheckEnum.VALID_APPID_MISS.getErrorMsg());
|
||||||
// if (ObjectUtil.isNull(appIdEncrypt)) {
|
} else {
|
||||||
// throw new LeException(CheckEnum.VALID_APPID_MISS.getCode(), CheckEnum.VALID_APPID_MISS.getErrorMsg());
|
String appIdStr = SmUtils.decryptBySm2(appIdEncrypt);
|
||||||
// } else {
|
if (!NumberUtil.isLong(appIdStr)) {
|
||||||
// String appIdStr = SmUtils.decryptBySm2(appIdEncrypt);
|
throw new ServiceException(CheckEnum.VALID_APPID_FORMAT_ERROR.getCode() + CheckEnum.VALID_APPID_FORMAT_ERROR.getErrorMsg());
|
||||||
// if (!NumberUtil.isLong(appIdStr)) {
|
} else {
|
||||||
// throw new LeException(CheckEnum.VALID_APPID_FORMAT_ERROR.getCode(), CheckEnum.VALID_APPID_FORMAT_ERROR.getErrorMsg());
|
Long appid = Long.parseLong(appIdStr);
|
||||||
// } else {
|
OpenApp app = this.openAppService.getAppInfoByAppId(appid);
|
||||||
// Long appid = Long.parseLong(appIdStr);
|
if (ObjectUtil.isNull(app)) {
|
||||||
// OpenApp app = this.openAppService.getAppInfoByAppId(appid);
|
throw new ServiceException(CheckEnum.VALID_APPID_ERROR.getCode() + CheckEnum.VALID_APPID_ERROR.getErrorMsg());
|
||||||
// if (ObjectUtil.isNull(app)) {
|
} else if (ObjectUtil.equals(app.getDisable(), LeConstants.COMMON_YES)) {
|
||||||
// throw new LeException(CheckEnum.VALID_APPID_ERROR.getCode(), CheckEnum.VALID_APPID_ERROR.getErrorMsg());
|
throw new ServiceException(CheckEnum.VALID_APPID_DISABLE.getCode() + CheckEnum.VALID_APPID_DISABLE.getErrorMsg());
|
||||||
// } else if (ObjectUtil.equals(app.getDisable(), LeConstants.COMMON_YES)) {
|
} else {
|
||||||
// throw new LeException(CheckEnum.VALID_APPID_DISABLE.getCode(), CheckEnum.VALID_APPID_DISABLE.getErrorMsg());
|
LocalDateTime startTime = app.getStartTime();
|
||||||
// } else {
|
LocalDateTime endTime = app.getEndTime();
|
||||||
// LocalDateTime startTime = app.getStartTime();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
// LocalDateTime endTime = app.getEndTime();
|
if (ObjectUtil.isNotNull(startTime) && now.isBefore(startTime)) {
|
||||||
// LocalDateTime now = LocalDateTime.now();
|
throw new ServiceException(CheckEnum.VALID_APPID_BEFORE.getCode() + CheckEnum.VALID_APPID_BEFORE.getErrorMsg());
|
||||||
// if (ObjectUtil.isNotNull(startTime) && now.isBefore(startTime)) {
|
} else if (ObjectUtil.isNotNull(endTime) && now.isAfter(endTime)) {
|
||||||
// throw new LeException(CheckEnum.VALID_APPID_BEFORE.getCode(), CheckEnum.VALID_APPID_BEFORE.getErrorMsg());
|
throw new ServiceException(CheckEnum.VALID_APPID_EXPIRED.getCode() + CheckEnum.VALID_APPID_EXPIRED.getErrorMsg());
|
||||||
// } else if (ObjectUtil.isNotNull(endTime) && now.isAfter(endTime)) {
|
} else {
|
||||||
// throw new LeException(CheckEnum.VALID_APPID_EXPIRED.getCode(), CheckEnum.VALID_APPID_EXPIRED.getErrorMsg());
|
String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName());
|
||||||
// } else {
|
String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey);
|
||||||
// String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName());
|
String token = this.generatorToken(String.valueOf(appid), clientKey, app.getTenantId());
|
||||||
// String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey);
|
OpenApiLoginVo loginVo = new OpenApiLoginVo();
|
||||||
// String token = this.generatorToken(String.valueOf(appid), clientKey, app.getTenantId());
|
loginVo.setToken(token).setTenantId(app.getTenantId()).setSecurityTokenSign(OAuthUtil.responseSetSecurityTokenSign(app.getTenantId(), token)).setAppName(app.getAppName());
|
||||||
// OpenApiLoginVo loginVo = new OpenApiLoginVo();
|
return loginVo;
|
||||||
// loginVo.setToken(token).setTenantId(app.getTenantId()).setSecurityTokenSign(OAuthUtil.responseSetSecurityTokenSign(app.getTenantId(), token)).setAppName(app.getAppName());
|
}
|
||||||
// return loginVo;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.bonus.canteen.core.auth.oauth.vo;
|
||||||
|
|
||||||
|
public class OpenApiLoginVo {
|
||||||
|
private Long tenantId;
|
||||||
|
private String securityTokenSign;
|
||||||
|
private String token;
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
public Long getTenantId() {
|
||||||
|
return this.tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecurityTokenSign() {
|
||||||
|
return this.securityTokenSign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToken() {
|
||||||
|
return this.token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppName() {
|
||||||
|
return this.appName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApiLoginVo setTenantId(final Long tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApiLoginVo setSecurityTokenSign(final String securityTokenSign) {
|
||||||
|
this.securityTokenSign = securityTokenSign;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApiLoginVo setToken(final String token) {
|
||||||
|
this.token = token;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApiLoginVo setAppName(final String appName) {
|
||||||
|
this.appName = appName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
Long var10000 = this.getTenantId();
|
||||||
|
return "OpenApiLoginVo(tenantId=" + var10000 + ", securityTokenSign=" + this.getSecurityTokenSign() + ", token=" + this.getToken() + ", appName=" + this.getAppName() + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
package com.bonus.canteen.core.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import com.bonus.canteen.core.customer.service.AuthorizingService;
|
||||||
|
import com.bonus.canteen.core.secure.PmsCache;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.collections4.ListUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.redis.core.BoundHashOperations;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class SecureManager {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(SecureManager.class);
|
||||||
|
private static SecureProperties secureProperties;
|
||||||
|
private static StringRedisTemplate redisTemplate;
|
||||||
|
private static AuthorizingService authorizingService;
|
||||||
|
private static ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private SecureManager() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSecureProperties(SecureProperties secureProperties) {
|
||||||
|
if (SecureManager.secureProperties == null) {
|
||||||
|
SecureManager.secureProperties = secureProperties;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setRedisTemplate(StringRedisTemplate redisTemplate) {
|
||||||
|
if (SecureManager.redisTemplate == null) {
|
||||||
|
SecureManager.redisTemplate = redisTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAuthorizingService(AuthorizingService authorizingService) {
|
||||||
|
if (SecureManager.authorizingService == null) {
|
||||||
|
SecureManager.authorizingService = authorizingService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setObjectMapper(ObjectMapper objectMapper) {
|
||||||
|
if (SecureManager.objectMapper == null) {
|
||||||
|
SecureManager.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPmsKey(long subjectId) {
|
||||||
|
return "permissions:subject_id:" + subjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRoleKey(long subjectId) {
|
||||||
|
return "roles:subject_id:" + subjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearAllRoleAndPermission() {
|
||||||
|
redisTemplate.delete(secureProperties.getPermissionKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearRoleAndPermission(long subjectId) {
|
||||||
|
redisTemplate.boundHashOps(secureProperties.getPermissionKey()).delete(new Object[]{getRoleKey(subjectId), getPmsKey(subjectId)});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearRole(long subjectId) {
|
||||||
|
redisTemplate.boundHashOps(secureProperties.getPermissionKey()).delete(new Object[]{getRoleKey(subjectId)});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearPermission(long subjectId) {
|
||||||
|
redisTemplate.boundHashOps(secureProperties.getPermissionKey()).delete(new Object[]{getPmsKey(subjectId)});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isLogin() {
|
||||||
|
return (Boolean)WebContext.get().getAccessToken().map(AccessToken::isAuthenticated).orElse(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<Long> getSubjectId() {
|
||||||
|
return WebContext.get().getAccessToken().map(AccessToken::getSubjectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<String> getSubjectName() {
|
||||||
|
return WebContext.get().getAccessToken().map(AccessToken::getSubjectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> getSubjectData() {
|
||||||
|
return (Map)WebContext.get().getAccessToken().map(AccessToken::getSubjectData).orElse(Maps.newHashMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> attachData(Map<String, String> data) {
|
||||||
|
try {
|
||||||
|
if (MapUtil.isEmpty(data)) {
|
||||||
|
return Maps.newHashMapWithExpectedSize(0);
|
||||||
|
} else {
|
||||||
|
AccessToken accessToken = (AccessToken)WebContext.get().getAccessToken().orElse(AccessToken.create());
|
||||||
|
Objects.requireNonNull(accessToken);
|
||||||
|
data.forEach(accessToken::setData);
|
||||||
|
accessToken.bind().store();
|
||||||
|
return accessToken.getSubjectData();
|
||||||
|
}
|
||||||
|
} catch (Throwable var2) {
|
||||||
|
throw var2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> attachData(String key, String value) {
|
||||||
|
try {
|
||||||
|
return attachData(Collections.singletonMap(key, value));
|
||||||
|
} catch (Throwable var3) {
|
||||||
|
throw var3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void logout() {
|
||||||
|
WebContext.get().getAccessToken().ifPresent(AccessToken::clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void revokeAuthenticate() {
|
||||||
|
WebContext.get().getAccessToken().ifPresent((accessToken) -> {
|
||||||
|
accessToken.revokeAuthenticate().store();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void revokeAuthenticate(long subjectId, int reservedRecentNum) {
|
||||||
|
StringRedisTemplate var10000 = redisTemplate;
|
||||||
|
String var10001 = secureProperties.getServer().getSubjectRefTokenKey();
|
||||||
|
Set<String> keys = var10000.keys(var10001 + ":" + subjectId + ":*");
|
||||||
|
if (CollectionUtils.size(keys) > reservedRecentNum) {
|
||||||
|
assert keys != null;
|
||||||
|
|
||||||
|
Map<Long, List<String>> createTimeAsc_keys = (Map)keys.stream().collect(Collectors.groupingBy((key) -> {
|
||||||
|
return Long.parseLong(key.split(":")[4]);
|
||||||
|
}, TreeMap::new, Collectors.toList()));
|
||||||
|
List<String> keysAsc = createTimeAsc_keys.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||||
|
List<String> beDeleteRefKeys = keysAsc.subList(0, keysAsc.size() - reservedRecentNum);
|
||||||
|
List<String> beDeleteTokenKeys = beDeleteRefKeys.stream().map((dk) -> {
|
||||||
|
String var100001 = secureProperties.getServer().getStoreKey();
|
||||||
|
return var100001 + ":" + dk.split(":")[3];
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
redisTemplate.delete(ListUtils.sum(beDeleteRefKeys, beDeleteTokenKeys));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "SecureManager()";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.bonus.canteen.core.open.modules.auth.constants;
|
||||||
|
|
||||||
|
public enum CheckEnum {
|
||||||
|
VALID_ERROR_PARAMS(100010, "参数不正确"),
|
||||||
|
VALID_TIMESTAMP_MISS(100011, "未提供请求时间戳"),
|
||||||
|
VALID_TIMESTAMP_ERROR(100012, "时间戳格式错误"),
|
||||||
|
VALID_TIMESTAMP_TIMEOUT(100013, "请求超出有效时间"),
|
||||||
|
VALID_APPID_MISS(100021, "未提供应用ID"),
|
||||||
|
VALID_APPID_EXPIRED(100022, "应用授权过期或未生效"),
|
||||||
|
VALID_APPID_BEFORE(100023, "应用授权还未生效"),
|
||||||
|
VALID_APPID_ERROR(100024, "应用ID错误"),
|
||||||
|
VALID_APPID_URL_MISS(100025, "URL不存在或未授权"),
|
||||||
|
VALID_APPID_DISABLE(100026, "应用未启用"),
|
||||||
|
VALID_APPID_FORMAT_ERROR(100027, "应用ID格式不正确"),
|
||||||
|
VALID_NONCE_MISS(100031, "未提供请求随机数"),
|
||||||
|
VALID_NONCE_REPEAT(100032, "不允许重复请求"),
|
||||||
|
VALID_NONCE_LENGTH(100033, "随机数长度有误"),
|
||||||
|
VALID_SIGN_MISS(100041, "未提供签名"),
|
||||||
|
VALID_SIGN_ERROR(100042, "签名错误"),
|
||||||
|
VALID_SIGNTYPE_ERROR(100043, "签名方法错误"),
|
||||||
|
VALID_URL_ERROR(100051, "URL不存在"),
|
||||||
|
VALID_URL_BUSY(100052, "资源繁忙"),
|
||||||
|
VALID_MERCHANTID_ERROR(100061, "商户号不存在"),
|
||||||
|
VALID_TOKEN_ERROR(100062, "token无效"),
|
||||||
|
VALID_TOKEN(100063, "token 过期"),
|
||||||
|
VALID_TIMESTAMP_FORMAT_ERROR(100014, "APP-ID格式不正确"),
|
||||||
|
VALID_TIMESTAMP_MERCHANTID_FORMAT_ERROR(100015, "商户号格式不正确"),
|
||||||
|
VALID_TIMESTAMP_MERCHANTID_ERROR(100016, "商户号不正确");
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
private final String errorMsg;
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorMsg() {
|
||||||
|
return this.errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CheckEnum(final Integer code, final String errorMsg) {
|
||||||
|
this.code = code;
|
||||||
|
this.errorMsg = errorMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.bonus.canteen.core.open.modules.auth.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.model.OpenApp;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OpenAppMapper extends BaseMapper<OpenApp> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,187 @@
|
||||||
|
package com.bonus.canteen.core.open.modules.auth.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@TableName("open_app")
|
||||||
|
@ApiModel("接入应用")
|
||||||
|
public class OpenApp extends Model<OpenApp> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@TableId
|
||||||
|
@ApiModelProperty("主键")
|
||||||
|
private Long appId;
|
||||||
|
@ApiModelProperty("应用秘钥")
|
||||||
|
private String appSecret;
|
||||||
|
@ApiModelProperty("应用名称")
|
||||||
|
private String appName;
|
||||||
|
@ApiModelProperty("商户id")
|
||||||
|
private Long tenantId;
|
||||||
|
@TableField(
|
||||||
|
updateStrategy = FieldStrategy.IGNORED
|
||||||
|
)
|
||||||
|
@ApiModelProperty("有效起始时间")
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
@TableField(
|
||||||
|
updateStrategy = FieldStrategy.IGNORED
|
||||||
|
)
|
||||||
|
@ApiModelProperty("有效结束时间")
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
@TableField(
|
||||||
|
updateStrategy = FieldStrategy.IGNORED
|
||||||
|
)
|
||||||
|
@ApiModelProperty("备注")
|
||||||
|
private String remark;
|
||||||
|
@ApiModelProperty("是否禁用")
|
||||||
|
private Integer disable;
|
||||||
|
@ApiModelProperty("删除标志")
|
||||||
|
private Integer delFlag;
|
||||||
|
@TableField(
|
||||||
|
value = "crby",
|
||||||
|
fill = FieldFill.INSERT
|
||||||
|
)
|
||||||
|
@ApiModelProperty("创建人")
|
||||||
|
private String crby;
|
||||||
|
@TableField(
|
||||||
|
value = "crtime",
|
||||||
|
fill = FieldFill.INSERT
|
||||||
|
)
|
||||||
|
@ApiModelProperty("创建时间")
|
||||||
|
private LocalDateTime crtime;
|
||||||
|
@TableField(
|
||||||
|
value = "upby",
|
||||||
|
fill = FieldFill.UPDATE
|
||||||
|
)
|
||||||
|
@ApiModelProperty("更新人")
|
||||||
|
private String upby;
|
||||||
|
@TableField(
|
||||||
|
value = "uptime",
|
||||||
|
fill = FieldFill.UPDATE
|
||||||
|
)
|
||||||
|
@ApiModelProperty("更新时间")
|
||||||
|
private LocalDateTime uptime;
|
||||||
|
|
||||||
|
public Long getAppId() {
|
||||||
|
return this.appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppSecret() {
|
||||||
|
return this.appSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppName() {
|
||||||
|
return this.appName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTenantId() {
|
||||||
|
return this.tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTime() {
|
||||||
|
return this.startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTime() {
|
||||||
|
return this.endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return this.remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDisable() {
|
||||||
|
return this.disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDelFlag() {
|
||||||
|
return this.delFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCrby() {
|
||||||
|
return this.crby;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getCrtime() {
|
||||||
|
return this.crtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpby() {
|
||||||
|
return this.upby;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getUptime() {
|
||||||
|
return this.uptime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setAppId(final Long appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setAppSecret(final String appSecret) {
|
||||||
|
this.appSecret = appSecret;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setAppName(final String appName) {
|
||||||
|
this.appName = appName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setTenantId(final Long tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setStartTime(final LocalDateTime startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setEndTime(final LocalDateTime endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setRemark(final String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setDisable(final Integer disable) {
|
||||||
|
this.disable = disable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setDelFlag(final Integer delFlag) {
|
||||||
|
this.delFlag = delFlag;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setCrby(final String crby) {
|
||||||
|
this.crby = crby;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setCrtime(final LocalDateTime crtime) {
|
||||||
|
this.crtime = crtime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setUpby(final String upby) {
|
||||||
|
this.upby = upby;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenApp setUptime(final LocalDateTime uptime) {
|
||||||
|
this.uptime = uptime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
Long var10000 = this.getAppId();
|
||||||
|
return "OpenApp(appId=" + var10000 + ", appSecret=" + this.getAppSecret() + ", appName=" + this.getAppName() + ", tenantId=" + this.getTenantId() + ", startTime=" + String.valueOf(this.getStartTime()) + ", endTime=" + String.valueOf(this.getEndTime()) + ", remark=" + this.getRemark() + ", disable=" + this.getDisable() + ", delFlag=" + this.getDelFlag() + ", crby=" + this.getCrby() + ", crtime=" + String.valueOf(this.getCrtime()) + ", upby=" + this.getUpby() + ", uptime=" + String.valueOf(this.getUptime()) + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.bonus.canteen.core.open.modules.auth.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.model.OpenApp;
|
||||||
|
|
||||||
|
|
||||||
|
public interface OpenAppService extends IService<OpenApp> {
|
||||||
|
// Page<OpenApp> page(OpenAppSearchVO searchVO);
|
||||||
|
//
|
||||||
|
// void add(OpenAppEditVO openAppEditVO);
|
||||||
|
//
|
||||||
|
// void update(OpenAppEditVO openAppEditVO);
|
||||||
|
|
||||||
|
// void remove(Long appId);
|
||||||
|
//
|
||||||
|
// void disable(Long appId);
|
||||||
|
//
|
||||||
|
// void enable(Long appId);
|
||||||
|
|
||||||
|
OpenApp getAppInfoByAppId(Long appId);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.bonus.canteen.core.open.modules.auth.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.mapper.OpenAppMapper;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.model.OpenApp;
|
||||||
|
import com.bonus.canteen.core.open.modules.auth.service.OpenAppService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.lang.invoke.SerializedLambda;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OpenAppServiceImpl extends ServiceImpl<OpenAppMapper, OpenApp> implements OpenAppService {
|
||||||
|
// public Page<OpenApp> page(OpenAppSearchVO searchVO) {
|
||||||
|
// return (Page)this.page(searchVO.getPage(), (Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery().and(Objects.nonNull(searchVO.getKeyword()), (e) -> {
|
||||||
|
// ((LambdaQueryWrapper)((LambdaQueryWrapper)e.like(OpenApp::getAppName, searchVO.getKeyword())).or()).like(OpenApp::getRemark, searchVO.getKeyword());
|
||||||
|
// })).eq(Objects.nonNull(searchVO.getTenantId()), OpenApp::getTenantId, searchVO.getTenantId())).eq(Objects.nonNull(searchVO.getDisable()), OpenApp::getDisable, searchVO.getDisable())).eq(OpenApp::getDelFlag, LeConstants.COMMON_NO)).orderByDesc(OpenApp::getCrtime));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void add(OpenAppEditVO openAppEditVO) {
|
||||||
|
// OpenApp openApp = (OpenApp)BeanUtil.copyProperties(openAppEditVO, OpenApp.class, new String[0]);
|
||||||
|
// openApp.setAppId(Id.next()).setAppSecret(IdUtil.fastSimpleUUID());
|
||||||
|
// this.save(openApp);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void update(OpenAppEditVO openAppEditVO) {
|
||||||
|
// OpenApp openApp = (OpenApp)BeanUtil.copyProperties(openAppEditVO, OpenApp.class, new String[0]);
|
||||||
|
// this.updateById(openApp);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public void remove(Long appId) {
|
||||||
|
// this.update((Wrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate().eq(OpenApp::getAppId, appId)).set(OpenApp::getDelFlag, LeConstants.COMMON_YES));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void disable(Long appId) {
|
||||||
|
// this.update((Wrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate().eq(OpenApp::getAppId, appId)).set(OpenApp::getDisable, LeConstants.COMMON_YES));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void enable(Long appId) {
|
||||||
|
// this.update((Wrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate().eq(OpenApp::getAppId, appId)).set(OpenApp::getDisable, LeConstants.COMMON_NO));
|
||||||
|
// }
|
||||||
|
|
||||||
|
public OpenApp getAppInfoByAppId(Long appId) {
|
||||||
|
return (OpenApp)this.getById(appId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue