Commit 8d81165a authored by fangxinjiang's avatar fangxinjiang

init

parent 0b25a0d3
......@@ -3,6 +3,8 @@ package com.yifu.cloud.plus.v1.yifu.auth.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.List;
......@@ -14,11 +16,12 @@ import java.util.List;
*/
@Data
@RefreshScope
@ConfigurationProperties("gateway")
@Configuration
//@ConfigurationProperties("gateway")
public class GatewayConfigProperties {
/**
* 网关解密登录前端密码 秘钥 {@link com.yifu.cloud.plus.v1.yifu.auth.filter.PasswordDecoderFilter}
* 解密登录前端密码 秘钥 {@link com.yifu.cloud.plus.v1.yifu.auth.filter.PasswordDecoderFilter}
*/
private String encodeKey;
......
......@@ -4,14 +4,19 @@ import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import com.yifu.cloud.plus.v1.yifu.auth.config.GatewayConfigProperties;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Component;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
......@@ -24,13 +29,15 @@ import javax.servlet.http.HttpServletResponse;
* @description
*/
@Log4j2
@EnableConfigurationProperties(GatewayConfigProperties.class)
@Data
@RequiredArgsConstructor
public class PasswordDecoderFilter extends UsernamePasswordAuthenticationFilter {
private static final String KEY_ALGORITHM = "AES";
private GatewayConfigProperties gatewayConfig;
/**
* 解密登录前端密码 秘钥
*/
private String encodeKey = "thanks,pig4cloud";
private boolean postOnly = true;
......@@ -57,8 +64,8 @@ public class PasswordDecoderFilter extends UsernamePasswordAuthenticationFilter
private String decryptAES(String password) {
// 构建前端对应解密AES 因子
AES aes = new AES(Mode.CFB, Padding.NoPadding,
new SecretKeySpec(gatewayConfig.getEncodeKey().getBytes(), KEY_ALGORITHM),
new IvParameterSpec(gatewayConfig.getEncodeKey().getBytes()));
new SecretKeySpec(encodeKey.getBytes(), KEY_ALGORITHM),
new IvParameterSpec(encodeKey.getBytes()));
// 解密
return aes.decryptStr(password);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment