完善依赖,调整APP依赖
This commit is contained in:
parent
c191deb51e
commit
9d3143b261
@ -12,11 +12,6 @@
|
||||
<artifactId>basic-app</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-exception</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-interface</artifactId>
|
||||
|
@ -1,11 +1,11 @@
|
||||
package ink.wgink.app;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.app.entity.AppToken;
|
||||
import ink.wgink.app.entity.AppTokenUser;
|
||||
import ink.wgink.app.enums.AppTokenTypeEnum;
|
||||
import ink.wgink.pojo.app.AppToken;
|
||||
import ink.wgink.pojo.app.AppTokenUser;
|
||||
import ink.wgink.exceptions.TokenException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.interfaces.manager.IAppManager;
|
||||
import ink.wgink.util.AesUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -29,7 +29,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @Date: 2019-08-02 11:08
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class AppTokenManager {
|
||||
public class AppTokenManager implements IAppManager {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppTokenManager.class);
|
||||
private static AppTokenManager appTokenManager = AppTokenManagerBuilder.appTokenManager;
|
||||
private static final Map<String, AppToken> tokens = new ConcurrentHashMap();
|
||||
@ -47,6 +48,7 @@ public class AppTokenManager {
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AppToken getToken(String token) {
|
||||
AppToken appToken = tokens.get(token);
|
||||
if (appToken != null) {
|
||||
@ -62,7 +64,7 @@ public class AppTokenManager {
|
||||
* @param appTokenTypeEnum
|
||||
* @param appTokenUser
|
||||
*/
|
||||
public synchronized void addToken(String token, AppTokenTypeEnum appTokenTypeEnum, AppTokenUser appTokenUser) {
|
||||
public synchronized void addToken(String token, AppToken.AppTokenTypeEnum appTokenTypeEnum, AppTokenUser appTokenUser) {
|
||||
AppToken appToken = new AppToken();
|
||||
appToken.setToken(token);
|
||||
appToken.setAppTokenTypeEnum(appTokenTypeEnum);
|
||||
@ -78,6 +80,7 @@ public class AppTokenManager {
|
||||
tokens.put(token, appToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppTokenUser parseToAppTokenUser(String token) throws TokenException {
|
||||
String userInfo = null;
|
||||
try {
|
||||
@ -119,6 +122,7 @@ public class AppTokenManager {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AppTokenUser> listCurrentUsers() {
|
||||
List<AppTokenUser> users = new ArrayList<>();
|
||||
for (Map.Entry<String, AppToken> kvs : tokens.entrySet()) {
|
||||
|
@ -1,27 +0,0 @@
|
||||
package ink.wgink.app.enums;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: AppTokenTypeEnum
|
||||
* @Description: appToken类别
|
||||
* @Author: WangGeng
|
||||
* @Date: 2020/3/8 10:09 上午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public enum AppTokenTypeEnum {
|
||||
|
||||
WECHAT("wechat"),
|
||||
WECHAT_MINI_APP("wxminiapp"),
|
||||
APP("app");
|
||||
private String type;
|
||||
|
||||
AppTokenTypeEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type == null ? "" : type.trim();
|
||||
}
|
||||
}
|
155
basic-app/src/main/java/ink/wgink/app/filter/AppTokenFilter.java
Normal file
155
basic-app/src/main/java/ink/wgink/app/filter/AppTokenFilter.java
Normal file
@ -0,0 +1,155 @@
|
||||
package ink.wgink.app.filter;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import ink.wgink.app.AppTokenManager;
|
||||
import ink.wgink.exceptions.TokenException;
|
||||
import ink.wgink.pojo.app.AppToken;
|
||||
import ink.wgink.pojo.app.AppTokenUser;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: AppTokenFilter
|
||||
* @Description: App过滤器
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/1 4:43 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class AppTokenFilter extends GenericFilterBean implements InitializingBean {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AppTokenFilter.class);
|
||||
private AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
/**
|
||||
* APP登录(用户名密码)
|
||||
*/
|
||||
private static final String URL_LOGIN_DEFAULT = "/**/app/sign/login";
|
||||
/**
|
||||
* APP登录(手机验证码)
|
||||
*/
|
||||
private static final String URL_LOGIN_PHONE = "/**/app/sign/loginphone";
|
||||
/**
|
||||
* APP注册
|
||||
*/
|
||||
private static final String URL_REGISTER = "/**/app/register/saveregisteruser";
|
||||
/**
|
||||
* APP注册简单
|
||||
*/
|
||||
private static final String URL_REGISTER_SIMPLE = "/**/app/register/saveregisterusersimple";
|
||||
/**
|
||||
* APP忘记密码
|
||||
*/
|
||||
private static final String URL_FORGET_PASSWORD = "/**/app/user/forgetpassword";
|
||||
/**
|
||||
* 下载头像
|
||||
*/
|
||||
private static final String URL_DOWNLOAD_AVATAR = "/**/app/user/downloadavatar/**";
|
||||
/**
|
||||
* APP下载
|
||||
*/
|
||||
private static final String URL_DOWNLOAD_APP = "/**/app/appversion/downloadapp/**";
|
||||
/**
|
||||
* APP版本号
|
||||
*/
|
||||
private static final String URL_APP_VERSION_NUM = "/**/app/appversion/getappversionnumber/**";
|
||||
/**
|
||||
* APP放行
|
||||
*/
|
||||
private static final String URL_RELEASE_APP = "/**/app/**/**release/**";
|
||||
/**
|
||||
* APP路由放行
|
||||
*/
|
||||
private static final String URL_RELEASE_APP_ROUTE = "/**/approute/**/**release/**";
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
String requestUri = request.getRequestURI();
|
||||
// 非app 放行
|
||||
boolean appMatcher = antPathMatcher.match("/**/app*/**", requestUri);
|
||||
if (!appMatcher) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
boolean matcher = antPathMatcher.match(URL_LOGIN_DEFAULT, requestUri)
|
||||
|| antPathMatcher.match(URL_LOGIN_PHONE, requestUri)
|
||||
|| antPathMatcher.match(URL_REGISTER, requestUri)
|
||||
|| antPathMatcher.match(URL_REGISTER_SIMPLE, requestUri)
|
||||
|| antPathMatcher.match(URL_FORGET_PASSWORD, requestUri)
|
||||
|| antPathMatcher.match(URL_DOWNLOAD_AVATAR, requestUri)
|
||||
|| antPathMatcher.match(URL_DOWNLOAD_APP, requestUri)
|
||||
|| antPathMatcher.match(URL_APP_VERSION_NUM, requestUri)
|
||||
|| antPathMatcher.match(URL_RELEASE_APP, requestUri)
|
||||
|| antPathMatcher.match(URL_RELEASE_APP_ROUTE, requestUri);
|
||||
if (matcher) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
String token = request.getHeader("token");
|
||||
if (StringUtils.isBlank(token)) {
|
||||
errorResponse(response, "token不能为空");
|
||||
return;
|
||||
}
|
||||
LOG.debug("校验token");
|
||||
try {
|
||||
checkToken(token);
|
||||
} catch (TokenException e) {
|
||||
errorResponse(response, e.getMessage());
|
||||
return;
|
||||
}
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验token
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
* @throws TokenException
|
||||
*/
|
||||
private void checkToken(String token) throws TokenException {
|
||||
AppTokenManager appTokenManager = AppTokenManager.getInstance();
|
||||
LOG.debug("检查token是否存在");
|
||||
AppToken appToken = appTokenManager.getToken(token);
|
||||
if (appToken != null) {
|
||||
return;
|
||||
}
|
||||
LOG.debug("解析token是否合法");
|
||||
AppTokenUser appTokenUser = appTokenManager.parseToAppTokenUser(token);
|
||||
appTokenManager.addToken(token, AppToken.AppTokenTypeEnum.APP, appTokenUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误返回
|
||||
*
|
||||
* @param response
|
||||
* @param errorInfo
|
||||
* @throws IOException
|
||||
*/
|
||||
private void errorResponse(HttpServletResponse response, String errorInfo) throws IOException {
|
||||
response.setStatus(HttpStatus.BAD_REQUEST.value());
|
||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
ErrorResult result = new ErrorResult(ErrorResult.ErrorResultCodeEnum.PARAMS_ERROR.getValue(), errorInfo);
|
||||
response.getWriter().write(JSON.toJSONString(result));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package ink.wgink.exceptions;
|
||||
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: AppTokenException
|
||||
* @Description: AppToken异常
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/1 5:43 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class AppTokenException extends SystemException {
|
||||
|
||||
public AppTokenException() {
|
||||
}
|
||||
|
||||
public AppTokenException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AppTokenException(String message, boolean withMsg) {
|
||||
super(message, withMsg);
|
||||
}
|
||||
|
||||
public AppTokenException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public AppTokenException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -12,6 +12,11 @@
|
||||
<artifactId>basic-interface</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-exception</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-pojo</artifactId>
|
||||
|
@ -0,0 +1,44 @@
|
||||
package ink.wgink.interfaces.manager;
|
||||
|
||||
import ink.wgink.exceptions.TokenException;
|
||||
import ink.wgink.pojo.app.AppToken;
|
||||
import ink.wgink.pojo.app.AppTokenUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: IAppManager
|
||||
* @Description: app管理
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/1 4:33 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IAppManager {
|
||||
|
||||
/**
|
||||
* 获取AppToken对象
|
||||
*
|
||||
* @param token token 字符串
|
||||
* @return
|
||||
*/
|
||||
AppToken getToken(String token);
|
||||
|
||||
/**
|
||||
* 解析 token 串为 AppTokenUser 对象
|
||||
*
|
||||
* @param token token 字符串
|
||||
* @return
|
||||
* @throws TokenException
|
||||
*/
|
||||
AppTokenUser parseToAppTokenUser(String token) throws TokenException;
|
||||
|
||||
/**
|
||||
* 当前用户列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<AppTokenUser> listCurrentUsers();
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
package ink.wgink.app.entity;
|
||||
|
||||
|
||||
import ink.wgink.app.enums.AppTokenTypeEnum;
|
||||
package ink.wgink.pojo.app;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
@ -77,4 +74,20 @@ public class AppToken {
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public enum AppTokenTypeEnum {
|
||||
|
||||
WECHAT("wechat"),
|
||||
WECHAT_MINI_APP("wxminiapp"),
|
||||
APP("app");
|
||||
private String type;
|
||||
|
||||
AppTokenTypeEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type == null ? "" : type.trim();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package ink.wgink.app.entity;
|
||||
package ink.wgink.pojo.app;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ink.wgink.app.entity;
|
||||
package ink.wgink.pojo.app;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
@ -11,6 +11,7 @@ package ink.wgink.app.entity;
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class AppTokenUserDepartment {
|
||||
|
||||
private String departmentId;
|
||||
private String departmentName;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ink.wgink.app.entity;
|
||||
package ink.wgink.pojo.app;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
@ -1,4 +1,4 @@
|
||||
package ink.wgink.app.entity;
|
||||
package ink.wgink.pojo.app;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
@ -1,4 +1,4 @@
|
||||
package ink.wgink.app.entity;
|
||||
package ink.wgink.pojo.app;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
@ -59,4 +59,40 @@ public class ErrorResult implements Serializable {
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public enum ErrorResultCodeEnum {
|
||||
|
||||
/**
|
||||
* 错误类型
|
||||
*/
|
||||
SYSTEM_ERROR(40001),
|
||||
ENCODE_ERROR(40002),
|
||||
DECODE_ERROR(40003),
|
||||
APP_DEPENDENCY_ERROR(40004),
|
||||
TEXT_ILLEGAL(40101),
|
||||
PARAMS_ERROR(40102),
|
||||
QUERY_ERROR(40101),
|
||||
SAVE_ERROR(40102),
|
||||
UPDATE_ERROR(40103),
|
||||
REMOVE_ERROR(40104),
|
||||
FILE_ERROR(40401),
|
||||
TEST_ERROR(40201),
|
||||
LOGIN_OUT(40301),
|
||||
TOKEN_ERROR(40302),
|
||||
USERNAME_PASSWORD_ERROR(40303),
|
||||
USER_EXIST(40304),
|
||||
PERMISSION_ERROR(40401),
|
||||
DEVICE_ERROR(40501),
|
||||
DEVICE_VERSION_ERROR(40502);
|
||||
|
||||
private int value;
|
||||
|
||||
ErrorResultCodeEnum(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,6 @@
|
||||
<artifactId>basic-util</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-pojo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring start -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@ -134,6 +128,13 @@
|
||||
</dependency>
|
||||
<!-- slf4j end -->
|
||||
|
||||
<!-- wgink start -->
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-pojo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- wgink end -->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,7 +1,6 @@
|
||||
package ink.wgink.common.advice;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import ink.wgink.common.enums.ErrorResultCodeEnum;
|
||||
import ink.wgink.exceptions.*;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
@ -9,8 +8,6 @@ import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.util.AesUtil;
|
||||
import ink.wgink.util.ReflectUtil;
|
||||
import ink.wgink.util.map.HashMapUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -24,14 +21,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.SQLSyntaxErrorException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
@ -59,23 +49,25 @@ public class ResponseAdvice {
|
||||
} else {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
ErrorResult result = new ErrorResult(ErrorResultCodeEnum.SYSTEM_ERROR.getValue(), "系统错误");
|
||||
ErrorResult result = new ErrorResult(ErrorResult.ErrorResultCodeEnum.SYSTEM_ERROR.getValue(), "系统错误");
|
||||
if (e instanceof SaveException) {
|
||||
result.setCode(ErrorResultCodeEnum.SAVE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.SAVE_ERROR.getValue());
|
||||
} else if (e instanceof RemoveException) {
|
||||
result.setCode(ErrorResultCodeEnum.REMOVE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.REMOVE_ERROR.getValue());
|
||||
} else if (e instanceof UpdateException) {
|
||||
result.setCode(ErrorResultCodeEnum.UPDATE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.UPDATE_ERROR.getValue());
|
||||
} else if (e instanceof SearchException) {
|
||||
result.setCode(ErrorResultCodeEnum.QUERY_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.QUERY_ERROR.getValue());
|
||||
} else if (e instanceof ParamsException) {
|
||||
result.setCode(ErrorResultCodeEnum.PARAMS_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.PARAMS_ERROR.getValue());
|
||||
} else if (e instanceof FileException) {
|
||||
result.setCode(ErrorResultCodeEnum.FILE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.FILE_ERROR.getValue());
|
||||
} else if (e instanceof AppTokenException) {
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.APP_DEPENDENCY_ERROR.getValue());
|
||||
} else if (e instanceof AppDeviceException) {
|
||||
result.setCode(ErrorResultCodeEnum.DEVICE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.DEVICE_ERROR.getValue());
|
||||
} else if (e instanceof AppVersionException) {
|
||||
result.setCode(ErrorResultCodeEnum.DEVICE_VERSION_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.DEVICE_VERSION_ERROR.getValue());
|
||||
} else if (e instanceof AccessTokenException) {
|
||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||
}
|
||||
@ -83,16 +75,16 @@ public class ResponseAdvice {
|
||||
if (e instanceof SystemException) {
|
||||
result.setMsg(e.getMessage());
|
||||
} else if (e instanceof UnsupportedEncodingException) {
|
||||
result.setCode(ErrorResultCodeEnum.ENCODE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.ENCODE_ERROR.getValue());
|
||||
result.setMsg(e.getMessage());
|
||||
} else if (e instanceof AesUtil.AesEncodeException) {
|
||||
result.setCode(ErrorResultCodeEnum.ENCODE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.ENCODE_ERROR.getValue());
|
||||
result.setMsg(e.getMessage());
|
||||
} else if (e instanceof AesUtil.AesDecodeException) {
|
||||
result.setCode(ErrorResultCodeEnum.DECODE_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.DECODE_ERROR.getValue());
|
||||
result.setMsg(e.getMessage());
|
||||
} else if (e instanceof ReflectUtil.ReflectException) {
|
||||
result.setCode(ErrorResultCodeEnum.SYSTEM_ERROR.getValue());
|
||||
result.setCode(ErrorResult.ErrorResultCodeEnum.SYSTEM_ERROR.getValue());
|
||||
} else {
|
||||
StringBuilder errorMessageSB = new StringBuilder();
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
|
@ -4,10 +4,14 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.common.component.SecurityComponent;
|
||||
import ink.wgink.common.enums.RoleDataRightEnum;
|
||||
import ink.wgink.exceptions.AccessTokenException;
|
||||
import ink.wgink.exceptions.AppTokenException;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.exceptions.TokenException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.pojo.app.AppTokenUser;
|
||||
import ink.wgink.pojo.bos.UserInfoBO;
|
||||
import ink.wgink.pojo.dtos.ZTreeDTO;
|
||||
import ink.wgink.util.ReflectUtil;
|
||||
import ink.wgink.util.date.DateUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -41,13 +45,22 @@ public class DefaultBaseService {
|
||||
*/
|
||||
protected void setSaveInfo(Map<String, Object> params) {
|
||||
UserInfoBO userInfoBO = securityComponent.getCurrentUser();
|
||||
if (userInfoBO != null) {
|
||||
setSave(userInfoBO.getUserId(), params);
|
||||
} else {
|
||||
setSave("1", params);
|
||||
setSave(userInfoBO.getUserId(), params);
|
||||
}
|
||||
|
||||
protected AppTokenUser getAppTokenUser(String token) {
|
||||
try {
|
||||
return securityComponent.getAppTokenUser(token);
|
||||
} catch (ReflectUtil.ReflectException e) {
|
||||
throw new AppTokenException("未引入APP的依赖");
|
||||
}
|
||||
}
|
||||
|
||||
protected void setAppSaveInfo(Map<String, Object> params, String token) {
|
||||
AppTokenUser appTokenUser = getAppTokenUser(token);
|
||||
setSave(appTokenUser.getId(), params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置新增基础信息
|
||||
*
|
||||
|
@ -1,11 +1,17 @@
|
||||
package ink.wgink.common.component;
|
||||
|
||||
import ink.wgink.interfaces.manager.IAppManager;
|
||||
import ink.wgink.pojo.app.AppToken;
|
||||
import ink.wgink.pojo.app.AppTokenUser;
|
||||
import ink.wgink.pojo.bos.*;
|
||||
import ink.wgink.pojo.dtos.CurrentUserIdInfoDTO;
|
||||
import ink.wgink.pojo.pos.DepartmentPO;
|
||||
import ink.wgink.pojo.pos.GroupPO;
|
||||
import ink.wgink.pojo.pos.PositionPO;
|
||||
import ink.wgink.pojo.pos.RolePO;
|
||||
import ink.wgink.util.ReflectUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@ -25,6 +31,8 @@ import java.util.List;
|
||||
@Component
|
||||
public class SecurityComponent {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SecurityComponent.class);
|
||||
|
||||
/**
|
||||
* 获取当前用户
|
||||
*
|
||||
@ -54,12 +62,6 @@ public class SecurityComponent {
|
||||
if (user instanceof UserInfoBO) {
|
||||
userInfoBO = (UserInfoBO) user;
|
||||
}
|
||||
if (userInfoBO == null) {
|
||||
userInfoBO = new UserInfoBO();
|
||||
userInfoBO.setUserId("1");
|
||||
userInfoBO.setUserName("admin");
|
||||
userInfoBO.setUserUsername("admin");
|
||||
}
|
||||
return userInfoBO;
|
||||
}
|
||||
|
||||
@ -158,4 +160,41 @@ public class SecurityComponent {
|
||||
return currentUserIdInfoDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* AppManager
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IAppManager getAppManager() throws ReflectUtil.ReflectException {
|
||||
return ReflectUtil.getSingleInstance("ink.wgink.app.AppTokenManager", IAppManager.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* AppToken 对象
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public AppToken getAppToken(String token) throws ReflectUtil.ReflectException {
|
||||
IAppManager appManager = getAppManager();
|
||||
if (appManager == null) {
|
||||
return null;
|
||||
}
|
||||
return appManager.getToken(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* token 对应的 app 用户
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public AppTokenUser getAppTokenUser(String token) throws ReflectUtil.ReflectException {
|
||||
AppToken appToken = getAppToken(token);
|
||||
if (appToken == null) {
|
||||
return null;
|
||||
}
|
||||
return appToken.getAppTokenUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
package ink.wgink.common.enums;
|
||||
|
||||
/**
|
||||
* @ClassName: ErrorResultCodeEnum
|
||||
* @Description: 错误代码
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/2 3:51 PM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public enum ErrorResultCodeEnum {
|
||||
|
||||
/**
|
||||
* 错误类型
|
||||
*/
|
||||
SYSTEM_ERROR(40001),
|
||||
ENCODE_ERROR(40002),
|
||||
DECODE_ERROR(40003),
|
||||
TEXT_ILLEGAL(40101),
|
||||
PARAMS_ERROR(40102),
|
||||
QUERY_ERROR(40101),
|
||||
SAVE_ERROR(40102),
|
||||
UPDATE_ERROR(40103),
|
||||
REMOVE_ERROR(40104),
|
||||
FILE_ERROR(40401),
|
||||
TEST_ERROR(40201),
|
||||
LOGIN_OUT(40301),
|
||||
TOKEN_ERROR(40302),
|
||||
USERNAME_PASSWORD_ERROR(40303),
|
||||
USER_EXIST(40304),
|
||||
PERMISSION_ERROR(40401),
|
||||
DEVICE_ERROR(40501),
|
||||
DEVICE_VERSION_ERROR(40502);
|
||||
|
||||
private int value;
|
||||
|
||||
ErrorResultCodeEnum(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package ink.wgink.common.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.common.enums.ErrorResultCodeEnum;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -28,7 +27,7 @@ public class AccessDenyHandler implements AccessDeniedHandler {
|
||||
if (contentType != null && contentType.contains(MediaType.APPLICATION_JSON_VALUE)) {
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
response.getWriter().write(JSONObject.toJSONString(new ErrorResult(ErrorResultCodeEnum.PERMISSION_ERROR.getValue(), "权限不足")));
|
||||
response.getWriter().write(JSONObject.toJSONString(new ErrorResult(ErrorResult.ErrorResultCodeEnum.PERMISSION_ERROR.getValue(), "权限不足")));
|
||||
} else {
|
||||
response.setContentType(MediaType.TEXT_HTML_VALUE);
|
||||
request.getRequestDispatcher("/error/403.html").forward(request, response);
|
||||
|
@ -13,11 +13,6 @@
|
||||
<description>文件模块</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>basic-app</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ink.wgink</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
|
@ -4,9 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import ink.wgink.app.AppTokenManager;
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.common.enums.ErrorResultCodeEnum;
|
||||
import ink.wgink.exceptions.FileException;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.SaveException;
|
||||
@ -20,6 +18,7 @@ import ink.wgink.module.file.pojo.dtos.FileInfoDTO;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.pojo.ListPage;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import ink.wgink.pojo.result.SuccessResultList;
|
||||
import ink.wgink.util.ResourceUtil;
|
||||
@ -312,7 +311,7 @@ public class FileServiceImpl extends DefaultBaseService implements IFileService
|
||||
if (StringUtils.isBlank(token)) {
|
||||
setSaveInfo(params);
|
||||
} else {
|
||||
setSaveInfoByUserId(params, AppTokenManager.getInstance().getToken(token).getAppTokenUser().getId());
|
||||
setAppSaveInfo(params, token);
|
||||
}
|
||||
fileDao.save(params);
|
||||
}
|
||||
@ -442,7 +441,7 @@ public class FileServiceImpl extends DefaultBaseService implements IFileService
|
||||
result.put("data", fileArray);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
result.put("errno", ErrorResultCodeEnum.FILE_ERROR.getValue());
|
||||
result.put("errno", ErrorResult.ErrorResultCodeEnum.FILE_ERROR.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user