新增APP过滤器,加密工具
This commit is contained in:
parent
66f896bc04
commit
b5dada173a
@ -1,5 +1,6 @@
|
||||
package com.cm.common.base;
|
||||
|
||||
import com.cm.common.utils.HashMapUtil;
|
||||
import com.cm.common.utils.RequestUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -53,16 +54,7 @@ public abstract class AbstractController {
|
||||
* @return
|
||||
*/
|
||||
protected Map<String, Object> requestParams(HttpServletRequest request) {
|
||||
Enumeration<String> requestNames = request.getParameterNames();
|
||||
Map<String, Object> params = getParams();
|
||||
while (requestNames.hasMoreElements()) {
|
||||
String name = requestNames.nextElement();
|
||||
String value = request.getParameter(name);
|
||||
if (value.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
params.put(name, value);
|
||||
}
|
||||
Map<String, Object> params = HashMapUtil.requestParamsToMap(request);
|
||||
params.put("requestUri", request.getRequestURI());
|
||||
params.put("requestHost", request.getRemoteHost());
|
||||
params.put("requestPort", request.getLocalPort());
|
||||
|
@ -63,7 +63,7 @@ public abstract class AbstractService {
|
||||
* @param subCount
|
||||
*/
|
||||
protected void setZTreeInfo(ZTreeDTO zTreeDTO, Integer subCount) {
|
||||
zTreeDTO.setUrl("javascript:;");
|
||||
zTreeDTO.setUrl("javascript:void(0);");
|
||||
if (null != subCount && 0 < subCount) {
|
||||
zTreeDTO.setIsParent(true);
|
||||
} else {
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.cm.common.config;
|
||||
|
||||
import com.cm.common.filter.AppFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: FilterConfig
|
||||
* @Description: 过滤器控制
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019-08-01 14:08
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Configuration
|
||||
public class FilterConfig {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean appFilterRegister() {
|
||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
||||
filterRegistrationBean.setFilter(new AppFilter());
|
||||
filterRegistrationBean.addUrlPatterns("/app/*");
|
||||
filterRegistrationBean.setName("appFilter");
|
||||
filterRegistrationBean.setOrder(1);
|
||||
return filterRegistrationBean;
|
||||
}
|
||||
|
||||
}
|
@ -8,45 +8,61 @@ package com.cm.common.constants;
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public interface ISystemConstant {
|
||||
|
||||
/**
|
||||
* 系统接口标签前缀
|
||||
*/
|
||||
String API_TAGS_SYSTEM_PREFIX = "系统接口-";
|
||||
|
||||
/**
|
||||
* 资源接口标签前缀
|
||||
*/
|
||||
String API_TAGS_RESOURCE_PREFIX = "资源接口-";
|
||||
|
||||
/**
|
||||
* APP接口前缀
|
||||
*/
|
||||
String API_TAGS_APP_PREFIX = "APP接口-";
|
||||
/**
|
||||
* api前缀
|
||||
*/
|
||||
String API_PREFIX = "/api";
|
||||
|
||||
/**
|
||||
* 路由前缀
|
||||
*/
|
||||
String ROUTE_PREFIX = "/route";
|
||||
|
||||
/**
|
||||
* 资源前缀
|
||||
*/
|
||||
String RESOURCE_PREFIX = "/resource";
|
||||
|
||||
/**
|
||||
* APP前缀
|
||||
*/
|
||||
String APP_PREFIX = "/app";
|
||||
/**
|
||||
* true
|
||||
*/
|
||||
String IS_TRUE = "true";
|
||||
|
||||
/**
|
||||
* false
|
||||
*/
|
||||
String IS_FALSE = "false";
|
||||
|
||||
/**
|
||||
* UTF-8编码
|
||||
*/
|
||||
String CHARSET_UTF8 = "UTF-8";
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
String TOKEN = "token";
|
||||
/**
|
||||
* app的token加密秘钥
|
||||
*/
|
||||
String APP_TOKEN_AES_KEY = "CMXX_TOKEN_INFOS";
|
||||
/**
|
||||
* app的token标识
|
||||
*/
|
||||
String APP_TOKEN_SIGN = "tokenSign";
|
||||
/**
|
||||
* app的token标识前缀
|
||||
*/
|
||||
String APP_TOKEN_VERIFY = "CM_Token_";
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,19 @@ package com.cm.common.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class AesUtil {
|
||||
|
||||
private static final String IV_STRING = "16-Bytes--String";
|
||||
|
||||
/**
|
||||
* AES加密
|
||||
*
|
||||
@ -68,4 +74,44 @@ public class AesUtil {
|
||||
// 8.解密
|
||||
return new String(cipher.doFinal(contentByte), "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用aes加密,兼容IOS
|
||||
*
|
||||
* @param key
|
||||
* @param content
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String aesCommonEncoder(String key, String content) throws Exception {
|
||||
byte[] byteContent = content.getBytes("UTF-8");
|
||||
byte[] enCodeFormat = key.getBytes();
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
|
||||
byte[] initParam = IV_STRING.getBytes();
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(initParam);
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
|
||||
byte[] encryptedBytes = cipher.doFinal(byteContent);
|
||||
return new String(Base64.encodeBase64(encryptedBytes), "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* aes通用解密,兼容IOS
|
||||
*
|
||||
* @param key
|
||||
* @param content
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String aesCommonDecoder(String key, String content) throws Exception {
|
||||
byte[] encryptedBytes = Base64.decodeBase64(content);
|
||||
byte[] enCodeFormat = key.getBytes();
|
||||
SecretKeySpec secretKey = new SecretKeySpec(enCodeFormat, "AES");
|
||||
byte[] initParam = IV_STRING.getBytes();
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(initParam);
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
|
||||
byte[] result = cipher.doFinal(encryptedBytes);
|
||||
return new String(result, "UTF-8");
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.cm.common.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@ -16,6 +18,26 @@ import java.util.Map.Entry;
|
||||
*/
|
||||
public class HashMapUtil {
|
||||
|
||||
/**
|
||||
* 请求参数转Map
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> requestParamsToMap(HttpServletRequest request) {
|
||||
Enumeration<String> requestNames = request.getParameterNames();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
while (requestNames.hasMoreElements()) {
|
||||
String name = requestNames.nextElement();
|
||||
String value = request.getParameter(name);
|
||||
if (value.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
params.put(name, value);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 类转Map
|
||||
*
|
||||
|
8
pom.xml
8
pom.xml
@ -40,11 +40,12 @@
|
||||
<common-fileupload.version>1.3.1</common-fileupload.version>
|
||||
<common-codec.version>1.12</common-codec.version>
|
||||
<common-compress>1.18</common-compress>
|
||||
<common-beanutils.version>1.9.3</common-beanutils.version>
|
||||
<saaj.version>1.3.18</saaj.version>
|
||||
<shiro.version>1.4.0</shiro.version>
|
||||
<poi.version>3.17</poi.version>
|
||||
<validation.version>2.0.1.Final</validation.version>
|
||||
<hibernate-validation.version>6.0.8.Final</hibernate-validation.version>
|
||||
<hibernate-validation.version>6.0.17.Final</hibernate-validation.version>
|
||||
<dom4j.version>1.6.1</dom4j.version>
|
||||
<quartz.version>2.3.0</quartz.version>
|
||||
<ehcache.version>2.10.4</ehcache.version>
|
||||
@ -276,6 +277,11 @@
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>${common-compress}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>${common-beanutils.version}</version>
|
||||
</dependency>
|
||||
<!-- Apache commons end -->
|
||||
<!-- POI start -->
|
||||
<dependency>
|
||||
|
Loading…
Reference in New Issue
Block a user