- * 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.xncoding.jwt.common.util;
-
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-
-public class DateUtil {
- private final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
-
- private final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
-
- private final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
-
- private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
- private final static SimpleDateFormat sdfmsTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- private final static SimpleDateFormat allTime = new SimpleDateFormat("yyyyMMddHHmmss");
-
- private final static SimpleDateFormat sdfDay_ = new SimpleDateFormat("yyyy/MM/dd");
-
-
- /**
- * 获取YYYY格式
- *
- * @return
- */
- public static String getYear() {
- return sdfYear.format(new Date());
- }
-
- /**
- * 获取YYYY格式
- *
- * @return
- */
- public static String getYear(Date date) {
- return sdfYear.format(date);
- }
-
- /**
- * 获取YYYY-MM-DD格式
- *
- * @return
- */
- public static String getDay() {
- return sdfDay.format(new Date());
- }
-
- /**
- * 获取YYYY-MM-DD格式
- *
- * @return
- */
- public static String getDay(Date date) {
- return sdfDay.format(date);
- }
-
- /**
- * 获取YYYYMMDD格式
- *
- * @return
- */
- public static String getDays() {
- return sdfDays.format(new Date());
- }
-
- /**
- * 获取YYYYMMDD格式
- *
- * @return
- */
- public static String getDays(Date date) {
- return sdfDays.format(date);
- }
-
- /**
- * 获取YYYY/MM/DD格式
- *
- * @return
- */
- public static String getDays_(Date date) {
- return sdfDay_.format(date);
- }
-
- /**
- * 获取YYYY-MM-DD HH:mm:ss格式
- *
- * @return
- */
- public static String getTime() {
- return sdfTime.format(new Date());
- }
-
- /**
- * 获取YYYY-MM-DD HH:mm:ss.SSS格式
- *
- * @return
- */
- public static String getMsTime() {
- return sdfmsTime.format(new Date());
- }
-
- /**
- * 获取YYYYMMDDHHmmss格式
- *
- * @return
- */
- public static String getAllTime() {
- return allTime.format(new Date());
- }
-
- /**
- * 获取YYYY-MM-DD HH:mm:ss格式
- *
- * @return
- */
- public static String getTime(Date date) {
- return sdfTime.format(date);
- }
-
- /**
- * @param s
- * @param e
- * @return boolean
- * @throws
- * @Title: compareDate
- * @Description:(日期比较,如果s>=e 返回true 否则返回false)
- * @author luguosui
- */
- public static boolean compareDate(String s, String e) {
- if (parseDate(s) == null || parseDate(e) == null) {
- return false;
- }
- return parseDate(s).getTime() >= parseDate(e).getTime();
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static Date parseDate(String date) {
- try {
- return sdfDay.parse(date);
- } catch (ParseException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static Date parseTime(String date) {
- try {
- return sdfTime.parse(date);
- } catch (ParseException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static Date parse(String date, String pattern) {
- DateFormat fmt = new SimpleDateFormat(pattern);
- try {
- return fmt.parse(date);
- } catch (ParseException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static String format(Date date, String pattern) {
- DateFormat fmt = new SimpleDateFormat(pattern);
- return fmt.format(date);
- }
-
- /**
- * 把日期转换为Timestamp
- *
- * @param date
- * @return
- */
- public static Timestamp format(Date date) {
- return new Timestamp(date.getTime());
- }
-
- /**
- * 校验日期是否合法
- *
- * @return
- */
- public static boolean isValidDate(String s) {
- try {
- sdfTime.parse(s);
- return true;
- } catch (Exception e) {
- // 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
- return false;
- }
- }
-
- /**
- * 校验日期是否合法
- *
- * @return
- */
- public static boolean isValidDate(String s, String pattern) {
- DateFormat fmt = new SimpleDateFormat(pattern);
- try {
- fmt.parse(s);
- return true;
- } catch (Exception e) {
- // 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
- return false;
- }
- }
-
- /**
- * 获取指定日期偏移指定时间后的时间
- *
- * @param date 基准日期
- * @param calendarField 偏移的粒度大小(小时、天、月等)使用Calendar中的常数
- * @param offsite 偏移量,正数为向后偏移,负数为向前偏移
- * @return 偏移后的日期
- */
- public static Date offsiteDate(Date date, int calendarField, int offsite) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(date);
- cal.add(calendarField, offsite);
- return cal.getTime();
- }
-
- /**
- * 返回日期零时
- *
- * @param date 目标日期
- * @return 目标日期零时
- */
- public static Date getDateStartTime(Date date) {
- String str = format(date, "yyyyMMdd") + "000000";
- try {
- return allTime.parse(str);
- } catch (ParseException e) {
- return null;
- }
- }
-
-
- /**
- * 返回日期最后时间End
- *
- * @param date 目标日期
- * @return 目标日日期最后时间
- */
- public static Date getDateEndTime(Date date) {
- String str = format(date, "yyyyMMdd") + "235959";
- try {
- return allTime.parse(str);
- } catch (ParseException e) {
- return null;
- }
- }
-
-}
diff --git a/app-manage-api/src/main/java/com/xncoding/jwt/common/util/JWTUtil.java b/app-manage-api/src/main/java/com/xncoding/jwt/common/util/JWTUtil.java
deleted file mode 100644
index d2a5ac5..0000000
--- a/app-manage-api/src/main/java/com/xncoding/jwt/common/util/JWTUtil.java
+++ /dev/null
@@ -1,173 +0,0 @@
-package com.xncoding.jwt.common.util;
-
-import com.auth0.jwt.JWT;
-import com.auth0.jwt.JWTVerifier;
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTDecodeException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Date;
-
-public class JWTUtil {
-
- private static final Logger log = LoggerFactory.getLogger(JWTUtil.class);
-
- // 过期时间5分钟
- private static final long EXPIRE_TIME = 5 * 60 * 1000;
-
- /**
- * 校验token是否正确
- *
- * @param token 密钥
- * @param secret 用户的密码
- * @return 是否正确
- */
- public static boolean verify(String token, String username, String secret) {
- try {
- Algorithm algorithm = Algorithm.HMAC256(secret);
- JWTVerifier verifier = JWT.require(algorithm)
- .withClaim("username", username)
- .build();
- DecodedJWT jwt = verifier.verify(token);
- return true;
- } catch (Exception exception) {
- log.error("校验token失败", exception);
- return false;
- }
- }
-
- /**
- * 获得token中的信息无需secret解密也能获得
- *
- * @return token中包含的用户名
- */
- public static String getUsername(String token) {
- try {
- DecodedJWT jwt = JWT.decode(token);
- return jwt.getClaim("username").asString();
- } catch (JWTDecodeException e) {
- return null;
- }
- }
-
- /**
- * 生成签名,5min后过期
- *
- * @param username 用户名
- * @param secret 用户的密码
- * @return 加密的token
- */
- public static String sign(String username, String secret) {
- try {
- Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
- Algorithm algorithm = Algorithm.HMAC256(secret);
- // 附带username信息
- return JWT.create()
- .withClaim("username", username)
- .withExpiresAt(date)
- .sign(algorithm);
- } catch (UnsupportedEncodingException e) {
- return null;
- }
- }
-
- /*----------------------------以下是socket校验--------------------------*/
- /**
- * 生成Socket Token签名, 5min后过期
- *
- * @param username 用户名
- * @param secret 用户的密码
- * @param appid applicationId
- * @param imei IMEI码
- * @return 加密的token
- */
- public static String signSocket(String username, String secret, String appid, String imei) {
- try {
- Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
- Algorithm algorithm = Algorithm.HMAC256(secret);
- // 附带username信息
- return JWT.create()
- .withClaim("username", username)
- .withClaim("appid", appid)
- .withClaim("imei", imei)
- .withExpiresAt(date)
- .sign(algorithm);
- } catch (UnsupportedEncodingException e) {
- return null;
- }
- }
-
- /**
- * 校验token是否正确
- *
- * @param token 密钥
- * @param secret 用户的密码
- * @return 是否正确
- */
- public static boolean verifySocket(String token, String secret) {
- try {
- DecodedJWT jwt1 = JWT.decode(token);
- String username = jwt1.getClaim("username").asString();
- String appid = jwt1.getClaim("appid").asString();
- String imei = jwt1.getClaim("imei").asString();
-
- Algorithm algorithm = Algorithm.HMAC256(secret);
- JWTVerifier verifier = JWT.require(algorithm)
- .withClaim("username", username)
- .withClaim("appid", appid)
- .withClaim("imei", imei)
- .build();
- DecodedJWT jwt = verifier.verify(token);
- return true;
- } catch (Exception exception) {
- log.error("校验token失败", exception);
- return false;
- }
- }
-
- /**
- * 获得token中的信息无需secret解密也能获得
- *
- * @return token中包含的用户名
- */
- public static String getSocketUsername(String token) {
- try {
- DecodedJWT jwt1 = JWT.decode(token);
- return jwt1.getClaim("username").asString();
- } catch (JWTDecodeException e) {
- return null;
- }
- }
-
- /**
- * 获得token中的信息无需secret解密也能获得
- *
- * @return token中包含的Appid
- */
- public static String getSocketAppid(String token) {
- try {
- DecodedJWT jwt1 = JWT.decode(token);
- return jwt1.getClaim("appid").asString();
- } catch (JWTDecodeException e) {
- return null;
- }
- }
-
- /**
- * 获得token中的信息无需secret解密也能获得
- *
- * @return token中包含的IMEI码
- */
- public static String getSocketImei(String token) {
- try {
- DecodedJWT jwt1 = JWT.decode(token);
- return jwt1.getClaim("imei").asString();
- } catch (JWTDecodeException e) {
- return null;
- }
- }
-
-}
diff --git a/app-manage-api/src/main/java/com/xncoding/jwt/common/util/JsonConverter.java b/app-manage-api/src/main/java/com/xncoding/jwt/common/util/JsonConverter.java
deleted file mode 100644
index c0fc254..0000000
--- a/app-manage-api/src/main/java/com/xncoding/jwt/common/util/JsonConverter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.xncoding.jwt.common.util;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-
-/**
- * 对象和Json转换器
- *
- * @author XiongNeng
- * @version 1.0
- * @since 2018/1/18
- */
-public class JsonConverter {
- public static JSONObject objectToJSONObject(Object object) {
- try {
- String jsonString = new ObjectMapper().writeValueAsString(object);
- return new JSONObject(jsonString);
- } catch (JSONException | JsonProcessingException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public static JSONArray objectToJSONArray(Object object) {
- try {
- String jsonString = new ObjectMapper().writeValueAsString(object);
- return new JSONArray(jsonString);
- } catch (JSONException | JsonProcessingException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- public static 数据库数据源配置 说明:这个类中包含了许多默认配置,若这些配置符合您的情况,您可以不用管,若不符合,建议不要修改本类,建议直接在"application.yml"中配置即可
- * 权限信息.(授权):
- * 1、如果用户正常退出,缓存自动清空;
- * 2、如果用户非正常退出,缓存自动清空;
- * 3、如果我们修改了用户的权限,而用户不退出系统,修改的权限无法立即生效。
- * (需要手动编程进行实现;放在service进行调用)
- * 在权限修改后调用realm中的方法,realm已经由spring管理,所以从spring中获取realm实例,调用clearCached方法;
- * :Authorization 是授权访问控制,用于对用户进行的操作授权,证明该用户是否允许进行当前操作,如访问某个链接,某个资源文件等。
- *
- * @param principals
- * @return
- */
- @Override
- protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
- /*
- * 当没有使用缓存的时候,不断刷新页面的话,这个代码会不断执行,
- * 当其实没有必要每次都重新设置权限信息,所以我们需要放到缓存中进行管理;
- * 当放到缓存中时,这样的话,doGetAuthorizationInfo就只会执行一次了,
- * 缓存过期之后会再次执行。
- */
- _logger.info("权限配置-->MyShiroRealm.doGetAuthorizationInfo()");
- String username = JWTUtil.getUsername(principals.toString());
-
- // 下面的可以使用缓存提升速度
- ManagerInfo managerInfo = managerInfoService.findByUsername(username);
-
- SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
-
- //设置相应角色的权限信息
- for (SysRole role : managerInfo.getRoles()) {
- //设置角色
- authorizationInfo.addRole(role.getRole());
- for (Permission p : role.getPermissions()) {
- //设置权限
- authorizationInfo.addStringPermission(p.getPermission());
- }
- }
- return authorizationInfo;
- }
-
-}
diff --git a/app-manage-api/src/main/java/com/xncoding/jwt/shiro/ShiroKit.java b/app-manage-api/src/main/java/com/xncoding/jwt/shiro/ShiroKit.java
deleted file mode 100644
index 9a77dc1..0000000
--- a/app-manage-api/src/main/java/com/xncoding/jwt/shiro/ShiroKit.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/**
- * Copyright (c) 2015-2017, Chill Zhuang 庄骞 (smallchill@163.com).
- *
- * 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.xncoding.jwt.shiro;
-
-import com.xncoding.jwt.dao.entity.ManagerInfo;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.crypto.SecureRandomNumberGenerator;
-import org.apache.shiro.crypto.hash.SimpleHash;
-import org.apache.shiro.session.Session;
-import org.apache.shiro.subject.Subject;
-
-/**
- * shiro工具类
- *
- * @author dafei, Chill Zhuang
- */
-public class ShiroKit {
-
- private static final String NAMES_DELIMETER = ",";
-
- /**
- * 散列算法
- */
- public final static String HASH_ALGORITHM_NAME = "MD5";
-
- /**
- * 循环次数
- */
- public final static int HASH_ITERATIONS = 2;
-
- /**
- * shiro密码加密工具类
- *
- * @param credentials 密码
- * @param saltSource 密码盐
- * @return
- */
- public static String md5(String credentials, String saltSource) {
- return new SimpleHash(HASH_ALGORITHM_NAME, credentials, saltSource, HASH_ITERATIONS).toHex();
- }
-
- /**
- * 获取随机盐值
- *
- * @param length 字节长度,一个字节2位16进制数表示
- * @return
- */
- public static String getRandomSalt(int length) {
- return new SecureRandomNumberGenerator().nextBytes(length).toHex();
- }
-
- /**
- * 获取当前 Subject
- *
- * @return Subject
- */
- public static Subject getSubject() {
- return SecurityUtils.getSubject();
- }
-
-
- /**
- * 验证当前用户是否属于该角色?,使用时与lacksRole 搭配使用
- *
- * @param roleName 角色名
- * @return 属于该角色:true,否则false
- */
- public static boolean hasRole(String roleName) {
- return getSubject() != null && roleName != null
- && roleName.length() > 0 && getSubject().hasRole(roleName);
- }
-
- /**
- * 与hasRole标签逻辑相反,当用户不属于该角色时验证通过。
- *
- * @param roleName 角色名
- * @return 不属于该角色:true,否则false
- */
- public static boolean lacksRole(String roleName) {
- return !hasRole(roleName);
- }
-
- /**
- * 验证当前用户是否属于以下任意一个角色。
- *
- * @param roleNames 角色列表
- * @return 属于:true,否则false
- */
- public static boolean hasAnyRoles(String roleNames) {
- boolean hasAnyRole = false;
- Subject subject = getSubject();
- if (subject != null && roleNames != null && roleNames.length() > 0) {
- for (String role : roleNames.split(NAMES_DELIMETER)) {
- if (subject.hasRole(role.trim())) {
- hasAnyRole = true;
- break;
- }
- }
- }
- return hasAnyRole;
- }
-
- /**
- * 验证当前用户是否拥有指定权限,使用时与lacksPermission 搭配使用
- *
- * @param permission 权限名
- * @return 拥有权限:true,否则false
- */
- public static boolean hasPermission(String permission) {
- return getSubject() != null && permission != null
- && permission.length() > 0
- && getSubject().isPermitted(permission);
- }
-
- /**
- * 与hasPermission标签逻辑相反,当前用户没有制定权限时,验证通过。
- *
- * @param permission 权限名
- * @return 拥有权限:true,否则false
- */
- public static boolean lacksPermission(String permission) {
- return !hasPermission(permission);
- }
-
- /**
- * 已认证通过的用户,不包含已记住的用户,这是与user标签的区别所在。与notAuthenticated搭配使用
- *
- * @return 通过身份验证:true,否则false
- */
- public static boolean isAuthenticated() {
- return getSubject() != null && getSubject().isAuthenticated();
- }
-
- /**
- * 未认证通过用户,与authenticated标签相对应。与guest标签的区别是,该标签包含已记住用户。。
- *
- * @return 没有通过身份验证:true,否则false
- */
- public static boolean notAuthenticated() {
- return !isAuthenticated();
- }
-
- /**
- * 认证通过或已记住的用户。与guset搭配使用。
- *
- * @return 用户:true,否则 false
- */
- public static boolean isUser() {
- return getSubject() != null && getSubject().getPrincipal() != null;
- }
-
- /**
- * 验证当前用户是否为“访客”,即未认证(包含未记住)的用户。用user搭配使用
- *
- * @return 访客:true,否则false
- */
- public static boolean isGuest() {
- return !isUser();
- }
-
- /**
- * 输出当前用户信息,通常为登录帐号信息。
- *
- * @return 当前用户信息
- */
- public static String principal() {
- if (getSubject() != null) {
- Object principal = getSubject().getPrincipal();
- return principal.toString();
- }
- return "";
- }
-
-}
diff --git a/app-manage-api/src/main/resources/application.yml b/app-manage-api/src/main/resources/application.yml
deleted file mode 100644
index d7eb05c..0000000
--- a/app-manage-api/src/main/resources/application.yml
+++ /dev/null
@@ -1,97 +0,0 @@
-##########################################################
-################## 所有profile共有的配置 #################
-##########################################################
-
-################### 自定义项目配置 ###################
-xncoding:
- socket-port: 9096 #socket端口
- ping-interval: 60000 #Ping消息间隔(毫秒)
- ping-timeout: 180000 #Ping消息超时时间(毫秒)
-
-################### 项目启动端口 ###################
-server.port: 9095
-
-################### spring配置 ###################
-spring:
- profiles:
- active: dev
- http:
- multipart:
- max-request-size: 100MB #最大请求大小
- max-file-size: 100MB #最大文件大小
-
-################### mybatis-plus配置 ###################
-mybatis-plus:
- mapper-locations: classpath*:com/xncoding/jwt/dao/repository/mapping/*.xml
- typeAliasesPackage: >
- com.xncoding.jwt.api.model,
- com.xncoding.jwt.dao.entity,
- com.xncoding.jwt.common.dao.entity
- global-config:
- id-type: 0 # 0:数据库ID自增 1:用户输入id 2:全局唯一id(IdWorker) 3:全局唯一ID(uuid)
- db-column-underline: false
- refresh-mapper: true
- configuration:
- map-underscore-to-camel-case: true
- cache-enabled: true #配置的缓存的全局开关
- lazyLoadingEnabled: true #延时加载的开关
- multipleResultSetsEnabled: true #开启的话,延时加载一个属性时会加载该对象全部属性,否则按需加载属性
-
-################### spring security配置 ###################
-security:
- ignored: /static/**
-
-logging:
- level:
- org.springframework.web.servlet: ERROR
-
----
-
-#####################################################################
-######################## 开发环境profile ##########################
-#####################################################################
-spring:
- profiles: dev
- datasource:
- url: jdbc:mysql://127.0.0.1:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
- username: root
- password: 123456
- thymeleaf:
- cache: false
-
-################### 自定义项目配置 ###################
-xncoding:
- apk-url-prefix: http://xncoding.net/files/ #APK文件访问URL前缀
-
-logging:
- level:
- ROOT: INFO
- com:
- xncoding: DEBUG
- file: E:/logs/app-manage-api.log
-
----
-
-#####################################################################
-######################## 测试环境profile ##########################
-#####################################################################
-
-spring:
- profiles: test
- datasource:
- url: jdbc:mysql://127.0.0.1:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
- username: root
- password: 123456
- thymeleaf:
- cache: false
-
-################### 自定义项目配置 ###################
-xncoding:
- apk-url-prefix: https://show.xncoding.net/files/ #APK文件访问URL前缀
-
-logging:
- level:
- ROOT: INFO
- com:
- xncoding: DEBUG
- file: /var/logs/app-manage-api.log
diff --git a/app-manage-api/src/main/resources/ehcache.xml b/app-manage-api/src/main/resources/ehcache.xml
deleted file mode 100644
index b580e22..0000000
--- a/app-manage-api/src/main/resources/ehcache.xml
+++ /dev/null
@@ -1,66 +0,0 @@
-
->(){});
- return new ObjectMapper().readValue(jsonObject.toString(), clazz);
- } catch (IOException e) {
- return null;
- }
- }
-}
diff --git a/app-manage-api/src/main/java/com/xncoding/jwt/config/MybatisPlusConfig.java b/app-manage-api/src/main/java/com/xncoding/jwt/config/MybatisPlusConfig.java
deleted file mode 100644
index 1c427c1..0000000
--- a/app-manage-api/src/main/java/com/xncoding/jwt/config/MybatisPlusConfig.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.xncoding.jwt.config;
-
-import com.alibaba.druid.pool.DruidDataSource;
-import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
-import com.xncoding.jwt.config.properties.DruidProperties;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
-
-import javax.annotation.Resource;
-
-/**
- * MybatisPlus配置
- *
- * @author xiongneng
- * @since 2017/5/20 21:58
- */
-@Configuration
-@EnableTransactionManagement(order = 2)
-@MapperScan(basePackages = {
- "com.xncoding.jwt.common.dao.repository",
- "com.xncoding.jwt.dao.repository"})
-public class MybatisPlusConfig {
-
- @Resource
- private DruidProperties druidProperties;
-
- /**
- * 单数据源连接池配置
- */
- @Bean
- public DruidDataSource singleDatasource() {
- DruidDataSource dataSource = new DruidDataSource();
- druidProperties.config(dataSource);
- return dataSource;
- }
-
- /**
- * mybatis-plus分页插件
- */
- @Bean
- public PaginationInterceptor paginationInterceptor() {
- return new PaginationInterceptor();
- }
-}
diff --git a/app-manage-api/src/main/java/com/xncoding/jwt/config/NettySocketConfig.java b/app-manage-api/src/main/java/com/xncoding/jwt/config/NettySocketConfig.java
deleted file mode 100644
index 3733c6f..0000000
--- a/app-manage-api/src/main/java/com/xncoding/jwt/config/NettySocketConfig.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.xncoding.jwt.config;
-
-import com.corundumstudio.socketio.AuthorizationListener;
-import com.corundumstudio.socketio.HandshakeData;
-import com.corundumstudio.socketio.SocketIOServer;
-import com.corundumstudio.socketio.annotation.SpringAnnotationScanner;
-import com.xncoding.jwt.common.util.JWTUtil;
-import com.xncoding.jwt.config.properties.MyProperties;
-import com.xncoding.jwt.dao.entity.ManagerInfo;
-import com.xncoding.jwt.service.ApiService;
-import com.xncoding.jwt.service.ManagerInfoService;
-import com.xncoding.jwt.shiro.ShiroKit;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import javax.annotation.Resource;
-
-/**
- * NettySocketConfig
- *
- * @author XiongNeng
- * @version 1.0
- * @since 2018/1/19
- */
-@Configuration
-public class NettySocketConfig {
-
- @Resource
- private MyProperties myProperties;
-
- @Resource
- private ApiService apiService;
-
- @Resource
- private ManagerInfoService managerInfoService;
-
- private static final Logger logger = LoggerFactory.getLogger(NettySocketConfig.class);
-
- @Bean
- public SocketIOServer socketIOServer() {
- /*
- * 创建Socket,并设置监听端口
- */
- com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration();
- // 设置主机名,默认是0.0.0.0
- // config.setHostname("localhost");
- // 设置监听端口
- config.setPort(myProperties.getSocketPort());
- // 协议升级超时时间(毫秒),默认10000。HTTP握手升级为ws协议超时时间
- config.setUpgradeTimeout(10000);
- // Ping消息间隔(毫秒),默认25000。客户端向服务器发送一条心跳消息间隔
- config.setPingInterval(myProperties.getPingInterval());
- // Ping消息超时时间(毫秒),默认60000,这个时间间隔内没有接收到心跳消息就会发送超时事件
- config.setPingTimeout(myProperties.getPingTimeout());
- // 握手协议参数使用JWT的Token认证方案
- config.setAuthorizationListener(data -> {
- // 可以使用如下代码获取用户密码信息
- String token = data.getSingleUrlParam("token");
- String username = JWTUtil.getSocketUsername(token);
- ManagerInfo managerInfo = managerInfoService.findByUsername(username);
- return JWTUtil.verifySocket(token, managerInfo.getPassword());
- });
- return new SocketIOServer(config);
- }
-
- @Bean
- public SpringAnnotationScanner springAnnotationScanner(SocketIOServer socketServer) {
- return new SpringAnnotationScanner(socketServer);
- }
-}
diff --git a/app-manage-api/src/main/java/com/xncoding/jwt/config/ShiroConfig.java b/app-manage-api/src/main/java/com/xncoding/jwt/config/ShiroConfig.java
deleted file mode 100644
index 19e7130..0000000
--- a/app-manage-api/src/main/java/com/xncoding/jwt/config/ShiroConfig.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package com.xncoding.jwt.config;
-
-import com.xncoding.jwt.shiro.JWTFilter;
-import com.xncoding.jwt.shiro.MyShiroRealm;
-import org.apache.shiro.cache.ehcache.EhCacheManager;
-import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
-import org.apache.shiro.mgt.DefaultSubjectDAO;
-import org.apache.shiro.mgt.SecurityManager;
-import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
-import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
-import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
-
-import javax.servlet.Filter;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Description : Apache Shiro 核心通过 Filter 来实现,就好像SpringMvc 通过DispachServlet 来主控制一样。
- * 既然是使用 Filter 一般也就能猜到,是通过URL规则来进行过滤和权限校验,所以我们需要定义一系列关于URL的规则和访问权限。
- */
-
-@Configuration
-@Order(1)
-public class ShiroConfig {
- /**
- * ShiroFilterFactoryBean 处理拦截资源文件问题。
- * 注意:单独一个ShiroFilterFactoryBean配置是或报错的,以为在
- * 初始化ShiroFilterFactoryBean的时候需要注入:SecurityManager Filter Chain定义说明
- * 1、一个URL可以配置多个Filter,使用逗号分隔
- * 2、当设置多个过滤器时,全部验证通过,才视为通过
- * 3、部分过滤器可指定参数,如perms,roles
- */
- @Bean
- public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
-
- ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
- // 必须设置 SecurityManager
- shiroFilterFactoryBean.setSecurityManager(securityManager);
- //验证码过滤器
- Map