mirror of https://gitee.com/maxjhandsome/pig
🔖 发布一个版本。v1.1.5 支持前端传输加密。(pig/pig-config/pig-ui 都需更新)
This commit is contained in:
parent
df084ef811
commit
35ae1c2bbf
|
@ -60,7 +60,6 @@ public class AccessFilter extends ZuulFilter {
|
||||||
RequestContext requestContext = RequestContext.getCurrentContext();
|
RequestContext requestContext = RequestContext.getCurrentContext();
|
||||||
requestContext.addZuulRequestHeader(SecurityConstants.USER_HEADER, authentication.getName());
|
requestContext.addZuulRequestHeader(SecurityConstants.USER_HEADER, authentication.getName());
|
||||||
requestContext.addZuulRequestHeader(SecurityConstants.ROLE_HEADER, CollectionUtil.join(authentication.getAuthorities(),","));
|
requestContext.addZuulRequestHeader(SecurityConstants.ROLE_HEADER, CollectionUtil.join(authentication.getAuthorities(),","));
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
* Author: lengleng (wangiegie@gmail.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.pig.gateway.component.filter;
|
||||||
|
|
||||||
|
import com.github.pig.common.constant.SecurityConstants;
|
||||||
|
import com.netflix.zuul.ZuulFilter;
|
||||||
|
import com.netflix.zuul.context.RequestContext;
|
||||||
|
import com.xiaoleilu.hutool.codec.Base64;
|
||||||
|
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||||
|
import com.xiaoleilu.hutool.util.CharsetUtil;
|
||||||
|
import com.xiaoleilu.hutool.util.StrUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lengleng
|
||||||
|
* 前端密码处理器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RefreshScope
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty(value = "security.encode.key")
|
||||||
|
public class DecodePasswordFilter extends ZuulFilter {
|
||||||
|
private static final String PASSWORD = "password";
|
||||||
|
private static final String KEY_ALGORITHM = "AES";
|
||||||
|
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/CBC/NOPadding";
|
||||||
|
@Value("${security.encode.key}")
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String filterType() {
|
||||||
|
return FilterConstants.PRE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int filterOrder() {
|
||||||
|
return FilterConstants.SEND_ERROR_FILTER_ORDER + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldFilter() {
|
||||||
|
HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
|
||||||
|
|
||||||
|
if (!StrUtil.containsAnyIgnoreCase(request.getRequestURI(),
|
||||||
|
SecurityConstants.OAUTH_TOKEN_URL, SecurityConstants.MOBILE_TOKEN_URL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object run() {
|
||||||
|
RequestContext ctx = RequestContext.getCurrentContext();
|
||||||
|
Map<String, List<String>> params = ctx.getRequestQueryParams();
|
||||||
|
if (params == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> passList = params.get("password");
|
||||||
|
if (CollUtil.isEmpty(passList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String password = passList.get(0);
|
||||||
|
if (StrUtil.isNotBlank(password)) {
|
||||||
|
try {
|
||||||
|
password = decryptAES(password, key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("密码解密失败:{}", password);
|
||||||
|
}
|
||||||
|
params.put(PASSWORD, CollUtil.newArrayList(password.trim()));
|
||||||
|
}
|
||||||
|
ctx.setRequestQueryParams(params);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static String decryptAES(String data, String pass) throws Exception {
|
||||||
|
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
|
||||||
|
SecretKeySpec keyspec = new SecretKeySpec(pass.getBytes(), KEY_ALGORITHM);
|
||||||
|
IvParameterSpec ivspec = new IvParameterSpec(pass.getBytes());
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
|
||||||
|
byte[] result = cipher.doFinal(Base64.decode(data.getBytes(CharsetUtil.UTF_8)));
|
||||||
|
return new String(result, CharsetUtil.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
|
@ -130,17 +130,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||||
return getDeptTree(this.selectList(sysDeptEntityWrapper), 0);
|
return getDeptTree(this.selectList(sysDeptEntityWrapper), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询部门列表
|
|
||||||
*
|
|
||||||
* @param sysDeptEntityWrapper sysDeptEntityWrapper
|
|
||||||
* @return 部门列表
|
|
||||||
*/
|
|
||||||
private List<SysDept> selectDeptDtoList(EntityWrapper<SysDept> sysDeptEntityWrapper) {
|
|
||||||
return sysDeptMapper.selectDeptDtoList(sysDeptEntityWrapper.getEntity().getDelFlag());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建部门树
|
* 构建部门树
|
||||||
*
|
*
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -37,7 +37,7 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<pig.version>1.1.4</pig.version>
|
<pig.version>1.1.5</pig.version>
|
||||||
<spring-boot.version>1.5.12.RELEASE</spring-boot.version>
|
<spring-boot.version>1.5.12.RELEASE</spring-boot.version>
|
||||||
<spring-cloud.version>Edgware.SR3</spring-cloud.version>
|
<spring-cloud.version>Edgware.SR3</spring-cloud.version>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue