Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
smileNicky
jeeplatform
提交
f927e9fa
J
jeeplatform
项目概览
smileNicky
/
jeeplatform
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
5
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jeeplatform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
5
Issue
5
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f927e9fa
编写于
5月 11, 2020
作者:
马
马增群
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OAuth2.0信息数据库存储实现
上级
8b94fbd0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
50 addition
and
4 deletion
+50
-4
code/jeeplatform-cms/src/main/java/org/muses/jeeplatform/cms/util/EnvironmentUtils.java
...java/org/muses/jeeplatform/cms/util/EnvironmentUtils.java
+5
-0
code/jeeplatform-cms/src/main/resources/application.properties
...jeeplatform-cms/src/main/resources/application.properties
+1
-1
code/jeeplatform-sso-oauth2/pom.xml
code/jeeplatform-sso-oauth2/pom.xml
+11
-0
code/jeeplatform-sso-oauth2/src/main/java/org/muses/jeeplatform/oauth/configuration/OAuthConfiguration.java
...s/jeeplatform/oauth/configuration/OAuthConfiguration.java
+12
-2
code/jeeplatform-sso-oauth2/src/main/resources/application.yml
...jeeplatform-sso-oauth2/src/main/resources/application.yml
+5
-0
code/jeeplatform-sso-oauth2/src/test/java/org/muses/jeeplatform/oauth/JeeplatformSsoOauth2ApplicationTests.java
...eplatform/oauth/JeeplatformSsoOauth2ApplicationTests.java
+16
-1
未找到文件。
code/jeeplatform-cms/src/main/java/org/muses/jeeplatform/cms/util/EnvironmentUtils.java
浏览文件 @
f927e9fa
...
...
@@ -4,6 +4,11 @@ import org.springframework.context.EnvironmentAware;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Component
;
/**
* copy
* @ https://github.com/chengjiansheng/cjs-oauth2-sso-demo/blob/master/oauth2-sso-client-member/src/main/java/com/cjs/example/util/EnvironmentUtils.java
* @Date 2020/05/11 11:47
*/
@Component
public
class
EnvironmentUtils
implements
EnvironmentAware
{
...
...
code/jeeplatform-cms/src/main/resources/application.properties
浏览文件 @
f927e9fa
...
...
@@ -5,7 +5,7 @@ security.oauth2.client.user-authorization-uri=http://localhost:8888/oauth/author
security.oauth2.client.access-token-uri
=
http://localhost:8888/oauth/token
security.oauth2.resource.user-info-uri
=
http://localhost:8888/user
security.oauth2.client.use-current-uri
=
false
#
security.oauth2.client.pre-established-redirect-uri=http://localhost:8084/cms/login
security.oauth2.client.pre-established-redirect-uri
=
http://localhost:8084/cms/login
security.oauth2.resource.token-info-uri
=
http://localhost:8888/oauth/check_token
security.oauth2.authorization.check-token-access
=
http://localhost:8888/oauth/check_token
...
...
code/jeeplatform-sso-oauth2/pom.xml
浏览文件 @
f927e9fa
...
...
@@ -93,6 +93,17 @@
<version>
3.1.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.27
</version>
<scope>
runtime
</scope>
</dependency>
</dependencies>
<dependencyManagement>
...
...
code/jeeplatform-sso-oauth2/src/main/java/org/muses/jeeplatform/oauth/configuration/OAuthConfiguration.java
浏览文件 @
f927e9fa
package
org.muses.jeeplatform.oauth.configuration
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.authentication.AuthenticationManager
;
...
...
@@ -13,13 +14,16 @@ 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.configurers.AuthorizationServerEndpointsConfigurer
;
import
org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer
;
import
org.springframework.security.oauth2.provider.ClientDetailsService
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.TokenStore
;
import
org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore
;
import
org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter
;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -46,6 +50,10 @@ public class OAuthConfiguration extends AuthorizationServerConfigurerAdapter {
@Resource
(
name
=
"userService"
)
private
UserDetailsService
userDetailsService
;
@Autowired
@Qualifier
(
"dataSource"
)
private
DataSource
dataSource
;
private
static
final
String
CLIENT_ID
=
"cms"
;
private
static
final
String
SECRET_CHAR_SEQUENCE
=
"{noop}secret"
;
private
static
final
String
SCOPE_READ
=
"read"
;
...
...
@@ -68,7 +76,7 @@ public class OAuthConfiguration extends AuthorizationServerConfigurerAdapter {
@Override
public
void
configure
(
ClientDetailsServiceConfigurer
clients
)
throws
Exception
{
clients
/*
clients
// 使用内存存储
.inMemory()
//标记客户端id
...
...
@@ -85,7 +93,8 @@ public class OAuthConfiguration extends AuthorizationServerConfigurerAdapter {
//刷新token 时间 秒
.refreshTokenValiditySeconds(FREFRESH_TOKEN_VALIDITY_SECONDS)
//允许授权类型
.
authorizedGrantTypes
(
GRANT_TYPE_PASSWORD
,
AUTHORIZATION_CODE
,
REFRESH_TOKEN
,
IMPLICIT
);
.authorizedGrantTypes(GRANT_TYPE_PASSWORD , AUTHORIZATION_CODE , REFRESH_TOKEN , IMPLICIT);*/
clients
.
jdbc
(
dataSource
);
}
@Override
...
...
@@ -165,6 +174,7 @@ public class OAuthConfiguration extends AuthorizationServerConfigurerAdapter {
}
@Bean
public
BCryptPasswordEncoder
bCryptPasswordEncoder
()
{
return
new
BCryptPasswordEncoder
();
...
...
code/jeeplatform-sso-oauth2/src/main/resources/application.yml
浏览文件 @
f927e9fa
...
...
@@ -2,6 +2,11 @@ server:
port
:
8888
spring
:
datasource
:
url
:
jdbc:mysql://192.168.0.152:33306/jeeplatform?autoReconnect=true&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
username
:
root
password
:
minstone
driver-class-name
:
com.mysql.jdbc.Driver
#添加Thymeleaf配置,除了cache在项目没上线前建议关了,其它配置都可以不用配的,本博客只是列举一下有这些配置
thymeleaf
:
# cache默认开启的,这里可以关了,项目上线之前,项目上线后可以开启
...
...
code/jeeplatform-sso-oauth2/src/test/java/org/muses/jeeplatform/oauth/JeeplatformSsoOauth2ApplicationTests.java
浏览文件 @
f927e9fa
package
org.muses.jeeplatform.oauth
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
javax.sql.DataSource
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
@SpringBootTest
class
JeeplatformSsoOauth2ApplicationTests
{
@Autowired
DataSource
dataSource
;
void
contextLoads
()
{
@Test
public
void
contextLoads
()
throws
SQLException
{
System
.
out
.
println
(
dataSource
.
getClass
());
Connection
connection
=
dataSource
.
getConnection
();
System
.
out
.
println
(
connection
);
connection
.
close
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录