Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
8d81165a
Commit
8d81165a
authored
May 30, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
0b25a0d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
GatewayConfigProperties.java
...oud.plus.v1/yifu/auth/config/GatewayConfigProperties.java
+5
-2
PasswordDecoderFilter.java
...cloud/plus/v1/yifu/auth/filter/PasswordDecoderFilter.java
+12
-5
No files found.
yifu-auth/src/main/java/com/yifu.cloud.plus.v1/yifu/auth/config/GatewayConfigProperties.java
View file @
8d81165a
...
...
@@ -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
;
...
...
yifu-auth/src/main/java/com/yifu/cloud/plus/v1/yifu/auth/filter/PasswordDecoderFilter.java
View file @
8d81165a
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment