diff --git a/.gitignore b/.gitignore
index 151918b6..9b5353fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
# Log file
*.log
/log
+/logs
# BlueJ files
*.ctxt
diff --git a/ad-platform-common/.gitignore b/ad-platform-common/.gitignore
deleted file mode 100644
index efb4aab2..00000000
--- a/ad-platform-common/.gitignore
+++ /dev/null
@@ -1,46 +0,0 @@
-### Java template
-# Compiled class file
-*.class
-
-# Log file
-*.log
-
-# BlueJ files
-*.ctxt
-
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.nar
-*.ear
-*.zip
-*.tar.gz
-*.rar
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-
-### Maven template
-target/
-pom.xml.tag
-pom.xml.releaseBackup
-pom.xml.versionsBackup
-pom.xml.next
-release.properties
-dependency-reduced-pom.xml
-buildNumber.properties
-.mvn/timing.properties
-# https://github.com/takari/maven-wrapper#usage-without-binary-jar
-.mvn/wrapper/maven-wrapper.jar
-
-### Example user template template
-### Example user template
-
-# IntelliJ project files
-.idea
-*.iml
-out
-gen
diff --git a/ad-platform-common/ad-platform-common-auth/pom.xml b/ad-platform-common/ad-platform-common-auth/pom.xml
new file mode 100644
index 00000000..f7340e7e
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/pom.xml
@@ -0,0 +1,64 @@
+
+
+ 4.0.0
+
+ ad-platform
+ com.baiye
+ 1.0-SNAPSHOT
+ ../../pom.xml
+
+ com.baiye
+ ad-platform-common-auth
+ 1.0-SNAPSHOT
+ ad-platform-common-auth
+ ad-platform-common-auth
+
+ 1.8
+
+
+
+
+ com.baiye
+ ad-platform-common-core
+ 1.0-SNAPSHOT
+
+
+
+ com.baiye
+ ad-platform-pojo
+ 1.0-SNAPSHOT
+
+
+
+
+ io.jsonwebtoken
+ jjwt-api
+
+
+
+ io.jsonwebtoken
+ jjwt-impl
+
+
+
+ io.jsonwebtoken
+ jjwt-jackson
+
+
+
+ com.github.whvcse
+ easy-captcha
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+
+
+
+
+
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/aspect/SecurityInnerAspect.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/aspect/SecurityInnerAspect.java
new file mode 100644
index 00000000..1090ce70
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/aspect/SecurityInnerAspect.java
@@ -0,0 +1,49 @@
+package com.baiye.aspect;
+
+import cn.hutool.core.util.StrUtil;
+import com.baiye.annotation.Inner;
+import com.baiye.constant.SecurityConstants;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.security.access.AccessDeniedException;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/11
+ */
+@Slf4j
+@Aspect
+@RequiredArgsConstructor
+public class SecurityInnerAspect implements Ordered {
+
+ private final HttpServletRequest request;
+
+ @SneakyThrows
+ @Around("@within(inner) || @annotation(inner)")
+ public Object around(ProceedingJoinPoint point, Inner inner) {
+ // 实际注入的inner实体由表达式后一个注解决定,即是方法上的@Inner注解实体,若方法上无@Inner注解,则获取类上的
+ if (inner == null) {
+ Class> clazz = point.getTarget().getClass();
+ inner = AnnotationUtils.findAnnotation(clazz, Inner.class);
+ }
+ String header = request.getHeader(SecurityConstants.FROM);
+ if (inner.value() && !StrUtil.equals(SecurityConstants.FROM_IN, header)) {
+ log.warn("访问接口 {} 没有权限", point.getSignature().getName());
+ throw new AccessDeniedException("Access is denied");
+ }
+ return point.proceed();
+ }
+
+ @Override
+ public int getOrder() {
+ return Ordered.HIGHEST_PRECEDENCE + 1;
+ }
+}
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/ConfigBeanConfiguration.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ConfigBeanConfiguration.java
similarity index 77%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/ConfigBeanConfiguration.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ConfigBeanConfiguration.java
index 4bd8e7cd..aafb822a 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/ConfigBeanConfiguration.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ConfigBeanConfiguration.java
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.baiye.modules.security.config;
+package com.baiye.config;
-import com.baiye.modules.security.config.bean.LoginProperties;
-import com.baiye.modules.security.config.bean.SecurityProperties;
+import com.baiye.properties.bean.LoginProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -35,9 +34,5 @@ public class ConfigBeanConfiguration {
return new LoginProperties();
}
- @Bean
- @ConfigurationProperties(prefix = "jwt")
- public SecurityProperties securityProperties() {
- return new SecurityProperties();
- }
+
}
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/CustomAuthorityDeserializer.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/CustomAuthorityDeserializer.java
new file mode 100644
index 00000000..173c43e6
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/CustomAuthorityDeserializer.java
@@ -0,0 +1,35 @@
+package com.baiye.config;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/11
+ */
+public class CustomAuthorityDeserializer extends JsonDeserializer {
+ @Override
+ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
+ ObjectMapper mapper = (ObjectMapper) p.getCodec();
+ JsonNode jsonNode = mapper.readTree(p);
+ LinkedList grantedAuthorities = new LinkedList<>();
+ Iterator elements = jsonNode.elements();
+ while (elements.hasNext()) {
+ JsonNode next = elements.next();
+ JsonNode authority = next.get("authority");
+ //将得到的值放入链表 最终返回该链表
+ grantedAuthorities.add(new SimpleGrantedAuthority(authority.asText()));
+ }
+ return grantedAuthorities;
+ }
+}
diff --git a/ad-platform-common/src/main/java/com/baiye/config/ElPermissionConfig.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ElPermissionConfig.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/config/ElPermissionConfig.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/config/ElPermissionConfig.java
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/feign/RemoteUserService.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/feign/RemoteUserService.java
new file mode 100644
index 00000000..1b7a16f5
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/feign/RemoteUserService.java
@@ -0,0 +1,43 @@
+package com.baiye.feign;
+
+import com.baiye.model.dto.UserDto;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/11
+ */
+@FeignClient(contextId = "remoteUserService", value = "ad-platform-management")
+public interface RemoteUserService {
+
+ /**
+ * 用户名查找名称
+ * @param username
+ * @return
+ */
+ @GetMapping("/api/users/info/findByName")
+ UserDto findByName(@RequestParam("username") String username);
+
+ /**
+ * 查找组长
+ * @param user
+ * @return
+ */
+ @PostMapping("/api/users/info/deptIds")
+ List getDeptIds(@RequestBody UserDto user);
+
+ /**
+ * 账号权限
+ * @param user
+ * @return
+ */
+ @PostMapping("/api/roles/user/authority")
+ Set mapToGrantedAuthorities(@RequestBody UserDto user);
+}
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/SecurityProperties.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/SecurityProperties.java
similarity index 85%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/SecurityProperties.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/SecurityProperties.java
index 06c3dded..46964738 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/SecurityProperties.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/SecurityProperties.java
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.baiye.modules.security.config.bean;
+package com.baiye.properties;
-import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
/**
* Jwt参数配置
@@ -23,7 +26,10 @@ import lombok.Data;
* @author Zheng Jie
* @date 2019年11月28日
*/
-@Data
+@Getter
+@Setter
+@Component
+@ConfigurationProperties(prefix = "jwt")
public class SecurityProperties {
/**
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCode.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCode.java
similarity index 96%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCode.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCode.java
index ea1b9bd6..c4613b82 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCode.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCode.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.baiye.modules.security.config.bean;
+package com.baiye.properties.bean;
import lombok.Data;
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCodeEnum.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCodeEnum.java
similarity index 95%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCodeEnum.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCodeEnum.java
index 8e886c75..57c63eb6 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginCodeEnum.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginCodeEnum.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.baiye.modules.security.config.bean;
+package com.baiye.properties.bean;
/**
* 验证码配置枚举
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginProperties.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginProperties.java
similarity index 84%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginProperties.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginProperties.java
index f85699a9..6d3b06e1 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/config/bean/LoginProperties.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/properties/bean/LoginProperties.java
@@ -1,19 +1,4 @@
-/*
- * Copyright 2019-2020 the original author or authors.
- *
- * Licensed under the Apache License, Version loginCode.length.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-loginCode.length.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baiye.modules.security.config.bean;
+package com.baiye.properties.bean;
import com.baiye.exception.BadConfigurationException;
import com.wf.captcha.*;
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/DefaultHandshakeHandler.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/DefaultHandshakeHandler.java
new file mode 100644
index 00000000..7f4a06a6
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/DefaultHandshakeHandler.java
@@ -0,0 +1,49 @@
+package com.baiye.security;
+
+import com.baiye.constant.SecurityConstants;
+import com.baiye.security.TokenProvider;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.http.server.ServerHttpRequest;
+import org.springframework.http.server.ServerHttpResponse;
+import org.springframework.http.server.ServletServerHttpRequest;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Component;
+import org.springframework.web.socket.WebSocketHandler;
+import org.springframework.web.socket.server.HandshakeInterceptor;
+
+import java.util.Map;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/12
+ */
+@Slf4j
+@Component
+@RequiredArgsConstructor
+class PrincipalHandshakeHandler implements HandshakeInterceptor {
+ private final TokenProvider tokenProvider;
+
+
+ @Override
+ public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map attributes) throws Exception {
+ ServletServerHttpRequest serverHttpRequest = (ServletServerHttpRequest) request;
+
+ //获取参数
+ String token = serverHttpRequest.getServletRequest().getParameter(SecurityConstants.AUTHORIZATION);
+ attributes.put("token", token);
+ if (StringUtils.isNotBlank(token)) {
+ Authentication authentication = tokenProvider.getAuthentication(token);
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+
+ @Override
+ public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
+
+ }
+}
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/SocketTokenFilter.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/SocketTokenFilter.java
new file mode 100644
index 00000000..c34835bb
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/SocketTokenFilter.java
@@ -0,0 +1,108 @@
+package com.baiye.security;
+
+import com.baiye.properties.SecurityProperties;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+import reactor.util.annotation.NonNull;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/11
+ */
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class SocketTokenFilter extends OncePerRequestFilter {
+
+ private final SecurityProperties securityProperties;
+
+ private final TokenProvider tokenProvider;
+
+
+ @Override
+ protected void doFilterInternal(HttpServletRequest request, @NonNull HttpServletResponse httpServletResponse, @NonNull FilterChain filterChain)
+ throws ServletException, IOException {
+ // http连接时,客户端应该是在头信息中携带令牌
+ String authorizationHeader = request.getHeader(securityProperties.getHeader());
+ if (StringUtils.isBlank(authorizationHeader)) {
+ // websocket连接时,令牌放在url参数上,以后重构
+ authorizationHeader = request.getParameter(securityProperties.getHeader());
+ }
+
+
+ String token = null;
+ if (!StringUtils.isEmpty(authorizationHeader) && authorizationHeader.startsWith(securityProperties.getTokenStartWith())) {
+ token = authorizationHeader.replace(securityProperties.getTokenStartWith(), "");
+ }
+ //验证token
+ if (StringUtils.isNotBlank(token)) {
+ Authentication authentication = tokenProvider.getAuthentication(token);
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ // TODO 修改权限传递token
+ /* TokenFilter.ModifyParametersWrapper mParametersWrapper = new TokenFilter.ModifyParametersWrapper((HttpServletRequest) request);
+ mParametersWrapper.putHeader(SecurityConstants.AUTHORIZATION, authorizationHeader);
+ filterChain.doFilter(mParametersWrapper, httpServletResponse);*/
+ log.debug("set Authentication to security context for '{}', uri: {}", authentication.getName(), request.getRequestURI());
+ }
+ filterChain.doFilter(request, httpServletResponse);
+ }
+
+
+ /**
+ * 继承HttpServletRequestWrapper,创建装饰类,以达到修改HttpServletRequest参数的目的
+ */
+ private static class ModifyParametersWrapper extends HttpServletRequestWrapper {
+ private final Map customHeaders;
+
+ ModifyParametersWrapper(HttpServletRequest request) {
+ super(request);
+ this.customHeaders = new HashMap<>();
+ }
+
+ void putHeader(String name, String value) {
+ this.customHeaders.put(name, value);
+ }
+
+ @Override
+ public String getHeader(String name) {
+ // check the custom headers first
+ String headerValue = customHeaders.get(name);
+
+ if (headerValue != null) {
+ return headerValue;
+ }
+ // else return from into the original wrapped object
+ return ((HttpServletRequest) getRequest()).getHeader(name);
+ }
+
+ @Override
+ public Enumeration getHeaderNames() {
+ // create a set of the custom header names
+ Set set = new HashSet<>(customHeaders.keySet());
+
+ // now add the headers from the wrapped request object
+ Enumeration e = ((HttpServletRequest) getRequest()).getHeaderNames();
+ while (e.hasMoreElements()) {
+ // add the names of the request headers into the list
+ String n = e.nextElement();
+ set.add(n);
+ }
+
+ // create an enumeration from the set and return
+ return Collections.enumeration(set);
+ }
+ }
+}
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenProvider.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/TokenProvider.java
similarity index 94%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenProvider.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/TokenProvider.java
index b03ba6c5..66386913 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/security/TokenProvider.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/security/TokenProvider.java
@@ -13,18 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.baiye.modules.security.security;
+package com.baiye.security;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
-import com.baiye.modules.security.config.bean.SecurityProperties;
+import com.baiye.properties.SecurityProperties;
import com.baiye.util.RedisUtils;
import io.jsonwebtoken.*;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import lombok.extern.slf4j.Slf4j;
-
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@@ -88,7 +87,7 @@ public class TokenProvider implements InitializingBean {
* @param token /
* @return /
*/
- Authentication getAuthentication(String token) {
+ public Authentication getAuthentication(String token) {
Claims claims = getClaims(token);
User principal = new User(claims.getSubject(), "******", new ArrayList<>());
return new UsernamePasswordAuthenticationToken(principal, token, new ArrayList<>());
@@ -103,7 +102,7 @@ public class TokenProvider implements InitializingBean {
/**
* @param token 需要检查的token
*/
- public void checkRenewal(String token) {
+ public boolean checkRenewal(String token) {
// 判断是否续期token,计算token的过期时间
long time = redisUtils.getExpire(properties.getOnlineKey() + token) * 1000;
Date expireDate = DateUtil.offset(new Date(), DateField.MILLISECOND, (int) time);
@@ -113,7 +112,9 @@ public class TokenProvider implements InitializingBean {
if (differ <= properties.getDetect()) {
long renew = time + properties.getRenew();
redisUtils.expire(properties.getOnlineKey() + token, renew, TimeUnit.MILLISECONDS);
+ return true;
}
+ return false;
}
public String getToken(HttpServletRequest request) {
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserCacheClean.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserCacheClean.java
similarity index 97%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserCacheClean.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserCacheClean.java
index 57d8d720..68a1397d 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserCacheClean.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserCacheClean.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.baiye.modules.security.service;
+package com.baiye.service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserDetailsServiceImpl.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserDetailsServiceImpl.java
similarity index 81%
rename from manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserDetailsServiceImpl.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserDetailsServiceImpl.java
index 36550e55..16c3060c 100644
--- a/manage/ad-platform-management/src/main/java/com/baiye/modules/security/service/UserDetailsServiceImpl.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/service/UserDetailsServiceImpl.java
@@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.baiye.modules.security.service;
+package com.baiye.service;
import com.baiye.exception.BadRequestException;
-import com.baiye.modules.security.config.bean.LoginProperties;
-import com.baiye.modules.security.service.dto.JwtUserDto;
-import com.baiye.modules.system.service.DataService;
-import com.baiye.modules.system.service.RoleService;
-import com.baiye.modules.system.service.UserService;
-import com.baiye.modules.system.service.dto.UserDto;
+import com.baiye.feign.RemoteUserService;
+import com.baiye.model.dto.JwtUserDto;
+import com.baiye.model.dto.UserDto;
+import com.baiye.properties.bean.LoginProperties;
import lombok.RequiredArgsConstructor;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@@ -30,8 +29,10 @@ import org.springframework.stereotype.Service;
import javax.persistence.EntityNotFoundException;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
/**
* @author Zheng Jie
@@ -40,9 +41,10 @@ import java.util.concurrent.atomic.AtomicInteger;
@RequiredArgsConstructor
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {
- private final UserService userService;
- private final RoleService roleService;
- private final DataService dataService;
+
+
+ private final RemoteUserService remoteUserService;
+
private final LoginProperties loginProperties;
public void setEnableCache(boolean enableCache) {
@@ -51,10 +53,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
/**
* 用户信息缓存
- *
- * @see {@link UserCacheClean}
*/
-
static final Map> USER_DTO_CACHE = new ConcurrentHashMap<>();
public static ExecutorService executor = newThreadPool();
@@ -66,7 +65,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
if (!loginProperties.isCacheEnable()) {
UserDto user;
try {
- user = userService.findByName(username);
+ user = remoteUserService.findByName(username);
} catch (EntityNotFoundException e) {
// SpringSecurity会自动转换UsernameNotFoundException为BadCredentialsException
throw new UsernameNotFoundException("", e);
@@ -77,10 +76,13 @@ public class UserDetailsServiceImpl implements UserDetailsService {
if (!user.getEnabled()) {
throw new BadRequestException("账号未激活!");
}
+ Set strings = remoteUserService.mapToGrantedAuthorities(user);
+
jwtUserDto = new JwtUserDto(
user,
- dataService.getDeptIds(user),
- roleService.mapToGrantedAuthorities(user)
+ remoteUserService.getDeptIds(user),
+ strings.stream().map(SimpleGrantedAuthority::new)
+ .collect(Collectors.toList())
);
}
return jwtUserDto;
@@ -110,7 +112,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
// 检查dataScope是否修改
List dataScopes = jwtUserDto.getDataScopes();
dataScopes.clear();
- dataScopes.addAll(dataService.getDeptIds(jwtUserDto.getUser()));
+ dataScopes.addAll(remoteUserService.getDeptIds(jwtUserDto.getUser()));
}
return jwtUserDto;
@@ -120,7 +122,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
private JwtUserDto getJwtBySearchDb(String username) {
UserDto user;
try {
- user = userService.findByName(username);
+ user = remoteUserService.findByName(username);
} catch (EntityNotFoundException e) {
// SpringSecurity会自动转换UsernameNotFoundException为BadCredentialsException
throw new UsernameNotFoundException("", e);
@@ -131,13 +133,13 @@ public class UserDetailsServiceImpl implements UserDetailsService {
if (!user.getEnabled()) {
throw new BadRequestException("账号未激活!");
}
+ Set strings = remoteUserService.mapToGrantedAuthorities(user);
return new JwtUserDto(
- user,
- dataService.getDeptIds(user),
- roleService.mapToGrantedAuthorities(user)
+ user, remoteUserService.getDeptIds(user),
+ strings.stream().map(SimpleGrantedAuthority::new)
+ .collect(Collectors.toList())
);
}
-
}
public static ExecutorService newThreadPool() {
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/AdUser.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/AdUser.java
new file mode 100644
index 00000000..cf3aef73
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/AdUser.java
@@ -0,0 +1,57 @@
+package com.baiye.util;
+
+import lombok.Getter;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.User;
+
+import java.util.Collection;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/11
+ */
+public class AdUser extends User {
+
+ private static final long serialVersionUID = -66600042157219036L;
+ /**
+ * 用户ID
+ */
+ @Getter
+ private final Integer id;
+
+ /**
+ * 部门ID
+ */
+ @Getter
+ private final Integer deptId;
+
+
+ /**
+ * Construct the User
with the details required by
+ * {@link DaoAuthenticationProvider}.
+ * @param id 用户ID
+ * @param deptId 部门ID
+ * @param username the username presented to the
+ * DaoAuthenticationProvider
+ * @param password the password that should be presented to the
+ * DaoAuthenticationProvider
+ * @param enabled set to true
if the user is enabled
+ * @param accountNonExpired set to true
if the account has not expired
+ * @param credentialsNonExpired set to true
if the credentials have not
+ * expired
+ * @param accountNonLocked set to true
if the account is not locked
+ * @param authorities the authorities that should be granted to the caller if they
+ * presented the correct username and password and the user is enabled. Not null.
+ * @throws IllegalArgumentException if a null
value was passed either as
+ * a parameter or as an element in the GrantedAuthority
collection
+ */
+ public AdUser(Integer id, Integer deptId, String username, String password, boolean enabled,
+ boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked,
+ Collection extends GrantedAuthority> authorities) {
+ super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
+ this.id = id;
+ this.deptId = deptId;
+ }
+
+
+}
diff --git a/ad-platform-common/src/main/java/com/baiye/util/SecurityUtils.java b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/SecurityUtils.java
similarity index 92%
rename from ad-platform-common/src/main/java/com/baiye/util/SecurityUtils.java
rename to ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/SecurityUtils.java
index 51d5068e..afe25220 100644
--- a/ad-platform-common/src/main/java/com/baiye/util/SecurityUtils.java
+++ b/ad-platform-common/ad-platform-common-auth/src/main/java/com/baiye/util/SecurityUtils.java
@@ -20,6 +20,7 @@ import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baiye.exception.BadRequestException;
+import com.baiye.model.dto.JwtUserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
@@ -31,14 +32,19 @@ import java.util.List;
/**
* 获取当前登录的用户
+ *
* @author Zheng Jie
* @date 2019-01-17
*/
@Slf4j
public class SecurityUtils {
+ private SecurityUtils() {
+ }
+
/**
* 获取当前登录的用户
+ *
* @return UserDetails
*/
public static UserDetails getCurrentUser() {
@@ -70,6 +76,7 @@ public class SecurityUtils {
/**
* 获取系统用户ID
+ *
* @return 系统用户ID
*/
public static Long getCurrentUserId() {
@@ -79,20 +86,23 @@ public class SecurityUtils {
/**
* 获取当前用户的数据权限
+ *
* @return /
*/
- public static List getCurrentUserDataScope(){
+ public static List getCurrentUserDataScope() {
UserDetails userDetails = getCurrentUser();
JSONArray array = JSONUtil.parseArray(new JSONObject(userDetails).get("dataScopes"));
- return JSONUtil.toList(array,Long.class);
+ return JSONUtil.toList(array, Long.class);
}
+
/**
* 获取数据权限级别
+ *
* @return 级别
*/
public static String getDataScopeType() {
List dataScopes = getCurrentUserDataScope();
- if(dataScopes.size() != 0){
+ if (dataScopes.size() != 0) {
return "";
}
return "全部的数据权限";
@@ -100,9 +110,10 @@ public class SecurityUtils {
/**
* 获取用户
+ *
* @return 用户
*/
- public static JSONObject getUser(){
+ public static JSONObject getUser() {
UserDetails userDetails = getCurrentUser();
return new JSONObject(new JSONObject(userDetails).get("user"));
}
diff --git a/ad-platform-common/ad-platform-common-auth/src/main/resources/bootstrap.yml b/ad-platform-common/ad-platform-common-auth/src/main/resources/bootstrap.yml
new file mode 100644
index 00000000..2c37c29b
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-auth/src/main/resources/bootstrap.yml
@@ -0,0 +1,17 @@
+#jwt
+jwt:
+ header: Authorization
+ # 令牌前缀
+ token-start-with: Bearer
+ # 必须使用最少88位的Base64对该令牌进行编码
+ base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
+ # 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
+ token-validity-in-seconds: 7200000
+ # 在线用户key
+ online-key: online-token-
+ # 验证码
+ code-key: code-key-
+ # token 续期检查时间范围(默认30分钟,单位默认毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
+ detect: 1800000
+ # 续期时间范围,默认 1小时,这里单位毫秒
+ renew: 3600000
diff --git a/ad-platform-common/pom.xml b/ad-platform-common/ad-platform-common-core/pom.xml
similarity index 74%
rename from ad-platform-common/pom.xml
rename to ad-platform-common/ad-platform-common-core/pom.xml
index b53c3293..3e3c6442 100644
--- a/ad-platform-common/pom.xml
+++ b/ad-platform-common/ad-platform-common-core/pom.xml
@@ -1,22 +1,21 @@
-
+
+
ad-platform
com.baiye
1.0-SNAPSHOT
- ../pom.xml
+ ../../pom.xml
4.0.0
-
- ad-platform-common
-
+ ad-platform-common-core
+ ad-platform-comm-core
+ ad-platform-common-core
8
8
-
com.dangdang
@@ -29,33 +28,13 @@
+
org.springframework.boot
spring-boot-starter-web
-
-
-
-
org.projectlombok
lombok
@@ -122,8 +101,8 @@
org.springframework.security
spring-security-web
+
-
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/AnonymousAccess.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/AnonymousAccess.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/AnonymousAccess.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/AnonymousAccess.java
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/DataPermission.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/DataPermission.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/DataPermission.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/DataPermission.java
diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Inner.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Inner.java
new file mode 100644
index 00000000..22c0e640
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Inner.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.baiye.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * 服务调用不鉴权注解
+ *
+ * @author lengleng
+ * @date 2020-06-14
+ */
+@Target({ ElementType.METHOD, ElementType.TYPE })
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Inner {
+
+ /**
+ * 是否AOP统一处理
+ * @return false, true
+ */
+ boolean value() default true;
+
+ /**
+ * 需要特殊判空的字段(预留)
+ * @return {}
+ */
+ String[] field() default {};
+
+}
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/Query.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Query.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/Query.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/Query.java
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousDeleteMapping.java
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousGetMapping.java
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPatchMapping.java
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPostMapping.java
diff --git a/ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/annotation/rest/AnonymousPutMapping.java
diff --git a/ad-platform-common/src/main/java/com/baiye/config/RedisCacheConfig.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/RedisCacheConfig.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/config/RedisCacheConfig.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/RedisCacheConfig.java
diff --git a/ad-platform-common/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/config/SimpleGrantedAuthorityDeserializer.java
diff --git a/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java
similarity index 96%
rename from ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java
index 6927e7e9..6486ccad 100644
--- a/ad-platform-common/src/main/java/com/baiye/constant/DefaultNumberConstants.java
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/DefaultNumberConstants.java
@@ -11,6 +11,10 @@ public class DefaultNumberConstants {
private DefaultNumberConstants() {
}
+ /**
+ * -2
+ */
+ public static final int MINUS_TWO_NUMBER = -2;
/**
* -1
diff --git a/ad-platform-common/src/main/java/com/baiye/constant/ElAdminConstant.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/ElAdminConstant.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/constant/ElAdminConstant.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/ElAdminConstant.java
diff --git a/ad-platform-common/src/main/java/com/baiye/constant/RoleNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/constant/RoleNumberConstants.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java
diff --git a/ad-platform-common/src/main/java/com/baiye/constant/SecurityConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/SecurityConstants.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/constant/SecurityConstants.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/SecurityConstants.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/BadConfigurationException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadConfigurationException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/BadConfigurationException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadConfigurationException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/BadRequestException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadRequestException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/BadRequestException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/BadRequestException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/CallException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CallException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/CallException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CallException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/CheckedException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CheckedException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/CheckedException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/CheckedException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/ElasticException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/ElasticException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/ElasticException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/ElasticException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/EntityExistException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityExistException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/EntityExistException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityExistException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/EntityNotFoundException.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityNotFoundException.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/EntityNotFoundException.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/EntityNotFoundException.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/handler/ApiError.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/ApiError.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/handler/ApiError.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/ApiError.java
diff --git a/ad-platform-common/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/exception/handler/GlobalExceptionHandler.java
diff --git a/ad-platform-common/src/main/java/com/baiye/http/CommonResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java
similarity index 98%
rename from ad-platform-common/src/main/java/com/baiye/http/CommonResponse.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java
index b959e42f..74687ead 100644
--- a/ad-platform-common/src/main/java/com/baiye/http/CommonResponse.java
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/CommonResponse.java
@@ -1,5 +1,6 @@
package com.baiye.http;
+import cn.hutool.http.HttpStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
diff --git a/ad-platform-common/src/main/java/com/baiye/http/ResponseCode.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/ResponseCode.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/http/ResponseCode.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/ResponseCode.java
diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/WebSocketResponse.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/WebSocketResponse.java
new file mode 100644
index 00000000..039c33de
--- /dev/null
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/http/WebSocketResponse.java
@@ -0,0 +1,119 @@
+package com.baiye.http;
+
+import cn.hutool.http.HttpStatus;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+
+/**
+ * @author
+ * 属性为 空("") 或者为 NULL 都不序列化,则返回的json是没有这个字段的。这样对移动端会更省流量
+ * @param
+ */
+@JsonSerialize
+@Getter
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+@NoArgsConstructor
+public class WebSocketResponse implements Serializable {
+
+
+ private static final long serialVersionUID = -7237947628886320124L;
+
+ /**
+ * 成功还是失败的状态标识 0,成功 1,失败
+ */
+ private int code;
+
+ /**
+ * 返回信息
+ */
+ private String type;
+
+ /**
+ * 返回的结果数据
+ */
+ private T data;
+
+
+ /*
+ 封装所有的构造器为私有的
+ */
+
+ private WebSocketResponse(String type) {
+ this.type = type;
+ }
+
+ private WebSocketResponse(String type, T data) { // ps: 当调用T为String类型时候,会默认调用下面的ServerResponse(int status, String msg)类型的构造器
+ this.type = type;
+ this.data = data;
+ }
+
+ private WebSocketResponse(String type, Integer code, T data) {
+ this.type = type;
+ this.code = code;
+ this.data = data;
+ }
+
+ private WebSocketResponse(String type, Integer code) {
+ this.type = type;
+ this.code = code;
+ }
+
+ /*
+ 对外开放调用的静态方法,用来调用私有构造器,来返回成功结果给前台
+ */
+
+ /**
+ * 返回成功码和默认的成功信息
+ */
+ public static WebSocketResponse createBySuccess() {
+ return new WebSocketResponse<>(ResponseCode.SUCCESS.getDesc(),HttpStatus.HTTP_OK);
+ }
+
+ /**
+ * 返回成功码和默认的成功信息
+ */
+ public static WebSocketResponse createBySuccess(String type) {
+ return new WebSocketResponse<>(type,HttpStatus.HTTP_OK);
+ }
+
+
+
+ /**
+ * 返回成功码和数据
+ */
+ public static WebSocketResponse createBySuccess(String type,T data) {
+ return new WebSocketResponse<>(type, HttpStatus.HTTP_OK, data);
+ }
+
+ /**
+ * 返回成功码和成功信息和数据
+ */
+ public static WebSocketResponse createBySuccess(String type,Integer code, T data) {
+ return new WebSocketResponse<>(type, code, data);
+ }
+
+ /*
+ 对外开放调用的静态方法,用来调用私有构造器,来返回失败结果给前台
+ */
+
+
+
+ /**
+ * 返回错误码和错误信息(传入)
+ */
+ public static WebSocketResponse createByErrorMessage(String errorMessage){
+ return new WebSocketResponse<>(errorMessage, ResponseCode.ERROR.getCode());
+ }
+
+ /**
+ * 返回错误码(传入)和错误信息(传入)
+ */
+ public static WebSocketResponse createByErrorCodeMessage(String type, Integer code){
+ return new WebSocketResponse<>(type, code);
+ }
+}
diff --git a/ad-platform-common/src/main/java/com/baiye/feign/FeignConfiguration.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignConfiguration.java
similarity index 77%
rename from ad-platform-common/src/main/java/com/baiye/feign/FeignConfiguration.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignConfiguration.java
index e2adab58..d3a83a29 100644
--- a/ad-platform-common/src/main/java/com/baiye/feign/FeignConfiguration.java
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignConfiguration.java
@@ -1,8 +1,6 @@
-package com.baiye.feign;
+package com.baiye.socket.filter;
import com.baiye.constant.SecurityConstants;
-import com.baiye.exception.CallException;
-import com.baiye.http.ResponseCode;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
@@ -24,11 +22,10 @@ public class FeignConfiguration implements RequestInterceptor {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
- String uri = request.getRequestURI();
// HeaderConstants.TOKEN_HEADER_NAME 替换为自己的请求头名称,下同
String token = request.getHeader(SecurityConstants.AUTHORIZATION);
- if (token == null && !FeignProvider.getDefaultSkipUrl().contains(uri)) {
- throw new CallException(ResponseCode.ILLEGAL_ARGUMENT.getDesc());
+ if (token == null) {
+ token = request.getParameter(SecurityConstants.AUTHORIZATION);
}
requestTemplate.header(SecurityConstants.AUTHORIZATION, token);
}
diff --git a/ad-platform-common/src/main/java/com/baiye/feign/FeignProvider.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignProvider.java
similarity index 66%
rename from ad-platform-common/src/main/java/com/baiye/feign/FeignProvider.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignProvider.java
index 02ac8fa6..b6e01cda 100644
--- a/ad-platform-common/src/main/java/com/baiye/feign/FeignProvider.java
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/socket/filter/FeignProvider.java
@@ -1,4 +1,4 @@
-package com.baiye.feign;
+package com.baiye.socket.filter;
import java.util.ArrayList;
@@ -15,6 +15,9 @@ public class FeignProvider {
static {
DEFAULT_SKIP_URL.add("/swagger/**");
+ DEFAULT_SKIP_URL.add("/api/users/user/findByName");
+ DEFAULT_SKIP_URL.add("/api/users/user/findByName");
+ DEFAULT_SKIP_URL.add("/api/roles/user/authority");
}
diff --git a/ad-platform-common/src/main/java/com/baiye/util/AESUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/AESUtils.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/AESUtils.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/CacheKey.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/CacheKey.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CacheKey.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/CallBack.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CallBack.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/CallBack.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/CallBack.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/ClassUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/ClassUtils.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/ClassUtils.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/ClassUtils.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/EncryptUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/EncryptUtils.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/EncryptUtils.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/EncryptUtils.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/FileUtil.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/FileUtil.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/FileUtil.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/FileUtil.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/JpaConverterAes.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterAes.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/JpaConverterAes.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterAes.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/JpaConverterListJson.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterListJson.java
similarity index 100%
rename from ad-platform-common/src/main/java/com/baiye/util/JpaConverterListJson.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/JpaConverterListJson.java
diff --git a/ad-platform-common/src/main/java/com/baiye/util/PageUtil.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/PageUtil.java
similarity index 91%
rename from ad-platform-common/src/main/java/com/baiye/util/PageUtil.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/PageUtil.java
index 31ba5a50..d636769a 100644
--- a/ad-platform-common/src/main/java/com/baiye/util/PageUtil.java
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/PageUtil.java
@@ -32,11 +32,11 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
/**
* List 分页
*/
- public static List toPage(int page, int size , List list) {
+ public static List toPage(int page, int size , List list) {
int fromIndex = page * size;
int toIndex = page * size + size;
if(fromIndex > list.size()){
- return new ArrayList();
+ return new ArrayList<>();
} else if(toIndex >= list.size()) {
return list.subList(fromIndex,list.size());
} else {
@@ -47,7 +47,7 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
/**
* Page 数据处理,预防redis反序列化报错
*/
- public static Map toPage(Page page) {
+ public static Map toPage(Page page) {
Map map = new LinkedHashMap<>(2);
map.put("content",page.getContent());
map.put("totalElements",page.getTotalElements());
diff --git a/ad-platform-common/src/main/java/com/baiye/util/RedisUtils.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RedisUtils.java
similarity index 99%
rename from ad-platform-common/src/main/java/com/baiye/util/RedisUtils.java
rename to ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RedisUtils.java
index 258e19a8..6256c3e5 100644
--- a/ad-platform-common/src/main/java/com/baiye/util/RedisUtils.java
+++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/RedisUtils.java
@@ -43,8 +43,6 @@ public class RedisUtils {
private RedisTemplate
\ No newline at end of file
+
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java
index 5ea41091..08e6935a 100644
--- a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java
+++ b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeign.java
@@ -38,12 +38,13 @@ public interface ConnectManageFeign {
/**
* 新增消息服务
+ *
* @param body
* @return
*/
@ApiOperation("新增消息模板")
@PostMapping(API_PREFIX + "/messageNotification/createMessage")
- ResponseEntity createMessage(@RequestBody String body);
+ ResponseEntity createMessage(@RequestParam("body") String body);
/**
@@ -62,6 +63,15 @@ public interface ConnectManageFeign {
* @return
*/
@ApiOperation("修改消息服务")
- @PostMapping(API_PREFIX + "/userMessage/changeMessage")
+ @PostMapping(API_PREFIX + "/userMessage/read")
ResponseEntity userMessageRead(@RequestBody String message);
+
+ /**
+ * 修改消息服务
+ * @param message
+ * @return
+ */
+ @ApiOperation("修改消息服务")
+ @PostMapping(API_PREFIX + "/userMessage/top")
+ ResponseEntity messageTop(String message);
}
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java
index 949c6eaf..d8c2a169 100644
--- a/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java
+++ b/manage/ad-platform-task/src/main/java/com/baiye/feign/ConnectManageFeignFallBack.java
@@ -39,5 +39,10 @@ public class ConnectManageFeignFallBack implements ConnectManageFeign {
return null;
}
+ @Override
+ public ResponseEntity messageTop(String message) {
+ return null;
+ }
+
}
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/filter/WebsocketFilter.java b/manage/ad-platform-task/src/main/java/com/baiye/filter/WebsocketFilter.java
deleted file mode 100644
index ffa57208..00000000
--- a/manage/ad-platform-task/src/main/java/com/baiye/filter/WebsocketFilter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baiye.filter;
-
-import com.baiye.constant.SecurityConstants;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.*;
-import javax.servlet.annotation.WebFilter;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * @author Enzo
- * @date : 2022/1/9
- */
-@Order(1)
-@Component
-@WebFilter(filterName = "WebsocketFilter",urlPatterns = "/task/prosperous")
-public class WebsocketFilter implements Filter {
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- Filter.super.init(filterConfig);
- }
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
- HttpServletResponse response = (HttpServletResponse) servletResponse;
- String token = ((HttpServletRequest) request).getHeader("Sec-WebSocket-Protocol");
- response.setHeader("Sec-WebSocket-Protocol",token);
- if (token != null) {
- request.setAttribute(SecurityConstants.AUTHORIZATION,token);
- }
- chain.doFilter(request, servletResponse);
- }
-
- @Override
- public void destroy() {
-
- }
-}
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java b/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java
index fdc2b00c..a2050047 100644
--- a/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java
+++ b/manage/ad-platform-task/src/main/java/com/baiye/job/WebSocketHeartbeat.java
@@ -1,17 +1,14 @@
package com.baiye.job;
import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.modules.timetask.entity.jobInstance.ElasticSimpleJob;
-import com.baiye.socket.WebSocketServer;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
/**
* @author wujingtao
@@ -22,8 +19,7 @@ import javax.annotation.Resource;
@Component
@ElasticSimpleJob(jobName = "WebSocketHeartbeat", cron = "0 0/1 * * * ?")
public class WebSocketHeartbeat implements SimpleJob {
- @Resource
- private WebSocketServer webSocketServer;
+
private static WebSocketHeartbeat WebSocketHeartbeat;
@PostConstruct
@@ -36,6 +32,6 @@ public class WebSocketHeartbeat implements SimpleJob {
JSONObject jsonObject = new JSONObject();
jsonObject.putOpt("message", "心跳检查");
jsonObject.putOpt("code", DefaultNumberConstants.ONE_NUMBER);
- WebSocketHeartbeat.webSocketServer.broadCastInfo(JSONUtil.toJsonStr(jsonObject));
+ // WebSocketHeartbeat.webSocketServer.broadCastInfo(JSONUtil.toJsonStr(jsonObject));
}
}
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java b/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java
index cea440d9..51b2ca9d 100644
--- a/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java
+++ b/manage/ad-platform-task/src/main/java/com/baiye/modules/timetask/service/impl/AutoReminderServiceImpl.java
@@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONArray;
@@ -16,16 +15,11 @@ import com.baiye.http.CommonResponse;
import com.baiye.modules.timetask.dao.AutoReminderRepository;
import com.baiye.modules.timetask.entity.AutoReminder;
import com.baiye.modules.timetask.service.AutoReminderService;
-import com.baiye.socket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
-import java.sql.Connection;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -38,8 +32,6 @@ public class AutoReminderServiceImpl implements AutoReminderService {
@Resource
private AutoReminderRepository timeTaskRepository;
@Resource
- private WebSocketServer webSocketServer;
- @Resource
private ConnectManageFeign connectManageFeign;
@Override
@@ -83,7 +75,7 @@ public class AutoReminderServiceImpl implements AutoReminderService {
JSONObject jsonObject = forwardMessage(info.getMessage());
webSocketData.putOpt("data", jsonObject);
try {
- webSocketServer.sendMessage(JSONUtil.toJsonStr(webSocketData), String.valueOf(info.getUserId()));
+ // webSocketServer.sendMessage(JSONUtil.toJsonStr(webSocketData), String.valueOf(info.getUserId()));
} catch (Exception e) {
log.info("执行自提醒任务 id:{} 发送websocket失败 {}", info.getId(), e.getMessage());
continue;
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java b/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java
index 79bf25d5..2c9d20be 100644
--- a/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java
+++ b/manage/ad-platform-task/src/main/java/com/baiye/modules/websocket/service/impl/WebSocketServiceImpl.java
@@ -1,17 +1,13 @@
package com.baiye.modules.websocket.service.impl;
import cn.hutool.core.collection.CollUtil;
-import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.http.CommonResponse;
import com.baiye.model.dto.SendWebSocketDTO;
import com.baiye.modules.websocket.service.WebSocketService;
-import com.baiye.socket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
-import javax.annotation.Resource;
-
/**
* @author wujingtao
* @date 2021/12/30
@@ -19,8 +15,8 @@ import javax.annotation.Resource;
@Service
@Slf4j
public class WebSocketServiceImpl implements WebSocketService {
- @Resource
- private WebSocketServer webSocketServer;
+ /* @Resource
+ private WebSocketServer webSocketServer;*/
@Override
public CommonResponse sendWebSocket(SendWebSocketDTO sendWebSocketDTO) {
@@ -28,9 +24,9 @@ public class WebSocketServiceImpl implements WebSocketService {
if (CollUtil.isEmpty(sendWebSocketDTO.getUserIds())) {
SendWebSocketDTO.SendMessage data = sendWebSocketDTO.getData();
data.setCode(DefaultNumberConstants.TWO_HUNDRED);
- webSocketServer.broadCastInfo(JSONUtil.toJsonStr(data));
+ //webSocketServer.broadCastInfo(JSONUtil.toJsonStr(data));
} else {
- webSocketServer.sendMessage(sendWebSocketDTO.getData(), sendWebSocketDTO.getUserIds());
+ // webSocketServer.sendMessage(sendWebSocketDTO.getData(), sendWebSocketDTO.getUserIds());
}
} catch (Exception e) {
log.error("Method 【sendWebSocket】发送 websocket 错误 :{}", e.getMessage());
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/socket/WebSocketServer.java b/manage/ad-platform-task/src/main/java/com/baiye/socket/WebSocketServer.java
deleted file mode 100644
index 83cbc920..00000000
--- a/manage/ad-platform-task/src/main/java/com/baiye/socket/WebSocketServer.java
+++ /dev/null
@@ -1,151 +0,0 @@
-package com.baiye.socket;
-
-import cn.hutool.json.JSONObject;
-import cn.hutool.json.JSONUtil;
-import com.baiye.constant.DefaultNumberConstants;
-import com.baiye.model.dto.SendWebSocketDTO;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import javax.websocket.*;
-import javax.websocket.server.PathParam;
-import javax.websocket.server.ServerEndpoint;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author wjt
- * @date 2021/12/13
- */
-@Slf4j
-@Component
-@ServerEndpoint(value = "/task/prosperous/{userId}")
-public class WebSocketServer {
- private static String user;
-
- @PostConstruct
- public void init() {
- log.info("websocket 加载");
- }
-
- private static final AtomicInteger ONLINE_COUNT = new AtomicInteger(0);
- /**
- * concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。
- */
-// private static final CopyOnWriteArraySet SESSIONS = new CopyOnWriteArraySet<>();
-
- private static ConcurrentHashMap SESSIONS = new ConcurrentHashMap();
-
- /**
- * 连接建立成功调用的方法
- */
- @OnOpen
- public void onOpen(@PathParam(value = "userId") String userId, Session session) {
- SESSIONS.put(userId, session);
- user = userId;
- // 在线数加1
- int cnt = ONLINE_COUNT.incrementAndGet();
- log.info("有连接加入,当前连接用户为 {},当前连接数为:{}", userId, cnt);
- JSONObject jsonObject = new JSONObject();
- jsonObject.putOpt("message", "连接成功");
- jsonObject.putOpt("code", DefaultNumberConstants.TWO_HUNDRED);
- sendMessage(session, JSONUtil.toJsonStr(jsonObject));
- }
-
- /**
- * 连接关闭调用的方法
- */
- @OnClose
- public void onClose(Session session) {
- if (user != null) {
- SESSIONS.remove(user);
- int cnt = ONLINE_COUNT.decrementAndGet();
- log.info("有连接关闭,当前连接数为:{}", cnt);
- }
- }
-
- /**
- * 收到客户端消息后调用的方法
- *
- * @param message 客户端发送过来的消息
- */
- @OnMessage
- public void onMessage(String message, Session session) {
- log.info("来自客户端的消息:{}", message);
- }
-
- /**
- * 出现错误
- *
- * @param session
- * @param error
- */
- @OnError
- public void onError(Session session, Throwable error) {
- log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId());
- error.printStackTrace();
- }
-
- /**
- * 发送消息,实践表明,每次浏览器刷新,session会发生变化。
- *
- * @param session
- * @param message
- */
- public static void sendMessage(Session session, String message) {
- try {
- session.getBasicRemote().sendText(message);
- } catch (IOException e) {
- log.error("发送消息出错:{}", e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * 群发消息
- *
- * @param message
- * @throws IOException
- */
- public void broadCastInfo(String message) {
- for (Session session : SESSIONS.values()) {
- sendMessage(session, message);
- }
- }
-
- /**
- * 指定Session发送消息
- *
- * @param message
- * @param sessionId
- * @throws IOException
- */
- public void sendMessage(String message, String sessionId) throws IOException {
- log.info("发送web信息 {}", message);
- Session session = null;
- if (SESSIONS.get(sessionId) != null) {
- session = SESSIONS.get(sessionId);
- }
- if (session != null) {
- sendMessage(session, message);
- } else {
- log.warn("没有找到你指定ID的会话:{}", sessionId);
- }
- }
-
- public void sendMessage(SendWebSocketDTO.SendMessage data, List ids) throws IOException {
- for (long id : ids) {
- if (SESSIONS.containsKey(String.valueOf(id))) {
- Session session = SESSIONS.get(String.valueOf(id));
- data.setCode(DefaultNumberConstants.TWO_HUNDRED);
- log.info(" 发送给 id:{} 的websocket 信息为:{}", id, data);
- session.getBasicRemote().sendText(JSONUtil.toJsonStr(data));
- } else {
- log.warn("没有找到你指定ID的会话:{}", id);
- }
- }
- }
-}
diff --git a/manage/ad-platform-task/src/main/java/com/baiye/socket/filter/WebsocketFilter.java b/manage/ad-platform-task/src/main/java/com/baiye/socket/filter/WebsocketFilter.java
new file mode 100644
index 00000000..7f6fda97
--- /dev/null
+++ b/manage/ad-platform-task/src/main/java/com/baiye/socket/filter/WebsocketFilter.java
@@ -0,0 +1,97 @@
+package com.baiye.socket.filter;
+
+import com.baiye.constant.SecurityConstants;
+import com.baiye.util.RedisUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @author Enzo
+ * @date : 2022/1/9
+ * 该过滤器暂不生效
+ */
+@Order(1)
+@Component
+@WebFilter(filterName = "WebsocketFilter", urlPatterns = "/task/prosperous")
+@RequiredArgsConstructor
+public class WebsocketFilter implements Filter {
+
+ private final RedisUtils redisUtils;
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ Filter.super.init(filterConfig);
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
+ HttpServletResponse response = (HttpServletResponse) servletResponse;
+ String token = ((HttpServletRequest) request).getHeader("Sec-WebSocket-Protocol");
+ response.setHeader("Sec-WebSocket-Protocol", token);
+ if (token != null) {
+ ModifyParametersWrapper mParametersWrapper = new ModifyParametersWrapper((HttpServletRequest) request);
+ mParametersWrapper.putHeader(SecurityConstants.AUTHORIZATION, token);
+ chain.doFilter(mParametersWrapper, response);
+ }
+ chain.doFilter(request, servletResponse);
+ }
+
+ @Override
+ public void destroy() {
+ // no need to do
+ }
+
+ /**
+ * 继承HttpServletRequestWrapper,创建装饰类,以达到修改HttpServletRequest参数的目的
+ */
+ private static class ModifyParametersWrapper extends HttpServletRequestWrapper {
+ private final Map customHeaders;
+
+ ModifyParametersWrapper(HttpServletRequest request) {
+ super(request);
+ this.customHeaders = new HashMap<>();
+ }
+
+ void putHeader(String name, String value) {
+ this.customHeaders.put(name, value);
+ }
+
+ @Override
+ public String getHeader(String name) {
+ // check the custom headers first
+ String headerValue = customHeaders.get(name);
+
+ if (headerValue != null) {
+ return headerValue;
+ }
+ // else return from into the original wrapped object
+ return ((HttpServletRequest) getRequest()).getHeader(name);
+ }
+
+ @Override
+ public Enumeration getHeaderNames() {
+ // create a set of the custom header names
+ Set set = new HashSet<>(customHeaders.keySet());
+
+ // now add the headers from the wrapped request object
+ Enumeration e = ((HttpServletRequest) getRequest()).getHeaderNames();
+ while (e.hasMoreElements()) {
+ // add the names of the request headers into the list
+ String n = e.nextElement();
+ set.add(n);
+ }
+
+ // create an enumeration from the set and return
+ return Collections.enumeration(set);
+ }
+ }
+}
diff --git a/manage/ad-platform-task/src/main/resources/application-dev.yml b/manage/ad-platform-task/src/main/resources/application-dev.yml
index 49b27f95..df8e9c92 100644
--- a/manage/ad-platform-task/src/main/resources/application-dev.yml
+++ b/manage/ad-platform-task/src/main/resources/application-dev.yml
@@ -86,23 +86,7 @@ login:
# 字体大小
font-size: 25
-#jwt
-jwt:
- header: Authorization
- # 令牌前缀
- token-start-with: Bearer
- # 必须使用最少88位的Base64对该令牌进行编码
- base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
- # 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
- token-validity-in-seconds: 14400000
- # 在线用户key
- online-key: online-token-
- # 验证码
- code-key: code-key-
- # token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
- detect: 1800000
- # 续期时间范围,默认1小时,单位毫秒
- renew: 3600000
+
#是否允许生成代码,生产环境设置为false
generator:
diff --git a/manage/ad-platform-task/src/main/resources/application.yml b/manage/ad-platform-task/src/main/resources/application.yml
index db686217..ce0443d0 100644
--- a/manage/ad-platform-task/src/main/resources/application.yml
+++ b/manage/ad-platform-task/src/main/resources/application.yml
@@ -21,4 +21,5 @@ rsa:
ribbon:
ReadTimeout: 3000
- ConnectTimeout: 3000
\ No newline at end of file
+ ConnectTimeout: 3000
+
diff --git a/pom.xml b/pom.xml
index 8fa49e1a..cbcfe4f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,10 +13,15 @@
services/ad-platform-callback
services/ad-platform-service
services/ad-platform-search
+
- ad-platform-common
+ ad-platform-common/ad-platform-common-core
+ ad-platform-common/ad-platform-common-auth
+
+
ad-platform-gateway
ad-platform-pojo
+
manage/ad-platform-management
manage/ad-platform-openapi
diff --git a/services/ad-platform-service/pom.xml b/services/ad-platform-service/pom.xml
index 6b4a18aa..1f9cbf03 100644
--- a/services/ad-platform-service/pom.xml
+++ b/services/ad-platform-service/pom.xml
@@ -21,7 +21,7 @@
com.baiye
- ad-platform-common
+ ad-platform-common-core
1.0-SNAPSHOT
diff --git a/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java b/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java
index 30629827..4f71db8f 100644
--- a/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java
+++ b/services/ad-platform-service/src/main/java/com/baiye/api/AssignDataController.java
@@ -1,12 +1,9 @@
package com.baiye.api;
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baiye.http.CommonResponse;
import com.baiye.model.dto.DistributeDTO;
import com.baiye.model.dto.DistributeResponseDTO;
-import com.baiye.model.enums.ResponseCode;
import com.baiye.service.AssignDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
diff --git a/services/ad-platform-source/pom.xml b/services/ad-platform-source/pom.xml
index f5d5b342..42b3eee5 100644
--- a/services/ad-platform-source/pom.xml
+++ b/services/ad-platform-source/pom.xml
@@ -21,7 +21,14 @@
com.baiye
- ad-platform-common
+ ad-platform-common-core
+ 1.0-SNAPSHOT
+
+
+
+
+ com.baiye
+ ad-platform-common-auth
1.0-SNAPSHOT