Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
93d4383d
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
93d4383d
编写于
9月 17, 2020
作者:
H
haoxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor:oauth2认证重构
上级
9278d176
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
8 deletion
+42
-8
youlai-auth/pom.xml
youlai-auth/pom.xml
+6
-0
youlai-auth/src/main/java/com/youlai/auth/config/AuthorizationServerConfig.java
...ava/com/youlai/auth/config/AuthorizationServerConfig.java
+18
-2
youlai-auth/src/main/java/com/youlai/auth/config/WebSecurityConfig.java
...c/main/java/com/youlai/auth/config/WebSecurityConfig.java
+3
-2
youlai-auth/src/main/java/com/youlai/auth/domain/User.java
youlai-auth/src/main/java/com/youlai/auth/domain/User.java
+5
-4
youlai-auth/src/main/java/com/youlai/auth/service/JdbcClientDetailsServiceImpl.java
...com/youlai/auth/service/JdbcClientDetailsServiceImpl.java
+10
-0
未找到文件。
youlai-auth/pom.xml
浏览文件 @
93d4383d
...
@@ -17,6 +17,12 @@
...
@@ -17,6 +17,12 @@
<dependencies>
<dependencies>
<dependency>
<groupId>
com.youlai
</groupId>
<artifactId>
youlai-common-db
</artifactId>
<version>
${youlai-common.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.youlai
</groupId>
<groupId>
com.youlai
</groupId>
<artifactId>
youlai-admin-api
</artifactId>
<artifactId>
youlai-admin-api
</artifactId>
...
...
youlai-auth/src/main/java/com/youlai/auth/config/AuthorizationServerConfig.java
浏览文件 @
93d4383d
package
com.youlai.auth.config
;
package
com.youlai.auth.config
;
import
com.youlai.auth.component.JwtTokenEnhancer
;
import
com.youlai.auth.component.JwtTokenEnhancer
;
import
com.youlai.auth.service.JdbcClientDetailsServiceImpl
;
import
com.youlai.common.core.constant.AuthConstants
;
import
com.youlai.common.core.constant.AuthConstants
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -15,6 +16,8 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.A
...
@@ -15,6 +16,8 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.A
import
org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer
;
import
org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer
;
import
org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer
;
import
org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer
;
import
org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer
;
import
org.springframework.security.oauth2.provider.ClientDetailsService
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.token.TokenEnhancer
;
import
org.springframework.security.oauth2.provider.token.TokenEnhancer
;
import
org.springframework.security.oauth2.provider.token.TokenEnhancerChain
;
import
org.springframework.security.oauth2.provider.token.TokenEnhancerChain
;
import
org.springframework.security.oauth2.provider.token.TokenStore
;
import
org.springframework.security.oauth2.provider.token.TokenStore
;
...
@@ -22,6 +25,8 @@ import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenCo
...
@@ -22,6 +25,8 @@ import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenCo
import
org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory
;
import
org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory
;
import
org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore
;
import
org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore
;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
java.security.KeyPair
;
import
java.security.KeyPair
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -42,6 +47,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -42,6 +47,10 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Autowired
@Autowired
private
RedisConnectionFactory
redisConnectionFactory
;
private
RedisConnectionFactory
redisConnectionFactory
;
@Autowired
private
DataSource
dataSource
;
/**
/**
* 配置客户端详情
* 配置客户端详情
*
*
...
@@ -51,15 +60,22 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -51,15 +60,22 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Override
@Override
@SneakyThrows
@SneakyThrows
public
void
configure
(
ClientDetailsServiceConfigurer
clients
)
throws
Exception
{
public
void
configure
(
ClientDetailsServiceConfigurer
clients
)
throws
Exception
{
clients
.
inMemory
()
/*
clients.inMemory()
.withClient("client")
.withClient("client")
.secret(passwordEncoder.encode("123456"))
.secret(passwordEncoder.encode("123456"))
.scopes("all")
.scopes("all")
.authorizedGrantTypes("password", "refresh_token")
.authorizedGrantTypes("password", "refresh_token")
.accessTokenValiditySeconds(3600)
.accessTokenValiditySeconds(3600)
.
refreshTokenValiditySeconds
(
86400
);
.refreshTokenValiditySeconds(86400);*/
JdbcClientDetailsServiceImpl
jdbcClientDetailsService
=
new
JdbcClientDetailsServiceImpl
(
dataSource
);
jdbcClientDetailsService
.
setFindClientDetailsSql
(
AuthConstants
.
CLIENT_DETAILS_FIND_SQL
);
jdbcClientDetailsService
.
setSelectClientDetailsSql
(
AuthConstants
.
CLIENT_DETAILS_SELECT_SQL
);
clients
.
withClientDetails
(
jdbcClientDetailsService
);
}
}
/**
/**
* 配置令牌端点的安全约束
* 配置令牌端点的安全约束
*
*
...
...
youlai-auth/src/main/java/com/youlai/auth/config/WebSecurityConfig.java
浏览文件 @
93d4383d
...
@@ -12,6 +12,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
...
@@ -12,6 +12,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.factory.PasswordEncoderFactories
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
@Configuration
@Configuration
...
@@ -31,8 +32,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -31,8 +32,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
}
}
@Bean
@Bean
public
PasswordEncoder
passwordEncoder
()
{
public
PasswordEncoder
passwordEncoder
()
{
return
new
BCrypt
PasswordEncoder
();
return
PasswordEncoderFactories
.
createDelegating
PasswordEncoder
();
}
}
@Bean
@Bean
...
...
youlai-auth/src/main/java/com/youlai/auth/domain/User.java
浏览文件 @
93d4383d
package
com.youlai.auth.domain
;
package
com.youlai.auth.domain
;
import
com.youlai.admin.api.dto.UserDTO
;
import
com.youlai.admin.api.dto.UserDTO
;
import
com.youlai.common.core.constant.AuthConstants
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
...
@@ -30,14 +31,14 @@ public class User implements UserDetails {
...
@@ -30,14 +31,14 @@ public class User implements UserDetails {
private
Collection
<
SimpleGrantedAuthority
>
authorities
;
private
Collection
<
SimpleGrantedAuthority
>
authorities
;
public
User
(
UserDTO
user
){
public
User
(
UserDTO
user
)
{
this
.
setId
(
user
.
getId
());
this
.
setId
(
user
.
getId
());
this
.
setUsername
(
user
.
getUsername
());
this
.
setUsername
(
user
.
getUsername
());
this
.
setPassword
(
user
.
getPassword
());
this
.
setPassword
(
AuthConstants
.
BCRYPT
+
user
.
getPassword
());
this
.
setEnabled
(
user
.
getStatus
().
equals
(
1
));
this
.
setEnabled
(
user
.
getStatus
().
equals
(
1
));
this
.
setClientId
(
user
.
getClientId
());
this
.
setClientId
(
user
.
getClientId
());
if
(
user
.
getRoles
()!=
null
)
{
if
(
user
.
getRoles
()
!=
null
)
{
authorities
=
new
ArrayList
<>();
authorities
=
new
ArrayList
<>();
user
.
getRoles
().
forEach
(
roleId
->
authorities
.
add
(
new
SimpleGrantedAuthority
(
String
.
valueOf
(
roleId
))));
user
.
getRoles
().
forEach
(
roleId
->
authorities
.
add
(
new
SimpleGrantedAuthority
(
String
.
valueOf
(
roleId
))));
}
}
...
...
youlai-auth/src/main/java/com/youlai/auth/service/JdbcClientDetailsServiceImpl.java
浏览文件 @
93d4383d
package
com.youlai.auth.service
;
package
com.youlai.auth.service
;
import
lombok.SneakyThrows
;
import
org.springframework.security.oauth2.provider.ClientDetails
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.stereotype.Service
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
public
class
JdbcClientDetailsServiceImpl
extends
JdbcClientDetailsService
{
public
class
JdbcClientDetailsServiceImpl
extends
JdbcClientDetailsService
{
public
JdbcClientDetailsServiceImpl
(
DataSource
dataSource
)
{
public
JdbcClientDetailsServiceImpl
(
DataSource
dataSource
)
{
super
(
dataSource
);
super
(
dataSource
);
}
}
@Override
@SneakyThrows
public
ClientDetails
loadClientByClientId
(
String
clientId
)
{
return
super
.
loadClientByClientId
(
clientId
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录