Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
b4d8fa93
microservices-platform
项目概览
zhangjian1949
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b4d8fa93
编写于
2月 23, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加sso单点登录demo
上级
eca52068
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
194 addition
and
0 deletion
+194
-0
zlt-demo/pom.xml
zlt-demo/pom.xml
+2
-0
zlt-demo/sso-demo/README.md
zlt-demo/sso-demo/README.md
+21
-0
zlt-demo/sso-demo/pom.xml
zlt-demo/sso-demo/pom.xml
+50
-0
zlt-demo/sso-demo/src/main/java/com/sso/demo/SSOApplication.java
...o/sso-demo/src/main/java/com/sso/demo/SSOApplication.java
+18
-0
zlt-demo/sso-demo/src/main/java/com/sso/demo/config/SecurityConfig.java
...emo/src/main/java/com/sso/demo/config/SecurityConfig.java
+34
-0
zlt-demo/sso-demo/src/main/java/com/sso/demo/controller/HomeController.java
...src/main/java/com/sso/demo/controller/HomeController.java
+29
-0
zlt-demo/sso-demo/src/main/resources/bootstrap.yml
zlt-demo/sso-demo/src/main/resources/bootstrap.yml
+22
-0
zlt-demo/sso-demo/src/main/resources/templates/index.html
zlt-demo/sso-demo/src/main/resources/templates/index.html
+18
-0
zlt-demo/sso-demo/单点登录架构图.jpg
zlt-demo/sso-demo/单点登录架构图.jpg
+0
-0
未找到文件。
zlt-demo/pom.xml
浏览文件 @
b4d8fa93
...
@@ -18,5 +18,7 @@
...
@@ -18,5 +18,7 @@
<module>
rocketmq-demo
</module>
<module>
rocketmq-demo
</module>
<!-- seata分布式事务demo -->
<!-- seata分布式事务demo -->
<module>
seata-demo
</module>
<module>
seata-demo
</module>
<!-- 单点登录demo -->
<module>
sso-demo
</module>
</modules>
</modules>
</project>
</project>
\ No newline at end of file
zlt-demo/sso-demo/README.md
0 → 100644
浏览文件 @
b4d8fa93
## **详细的原理和注意事项请查看**
[
单点登录详解
](
https://www.kancloud.cn/zlt2000/microservices-platform/1515193
)
## 启动以下服务
1.
zlt-uaa:统一认证中心
2.
user-center:用户服务
3.
sc-gateway:api网关
4.
back-web:webApp应用前端页面
5.
sso-demo:单点登录demo(zlt应用)
## 测试步骤
1.
登录webApp应用:
通过地址 http://127.0.0.1:8066 先登录webApp应用
2.
访问zlt应用(单点成功):
在浏览器打开一个新的页签(共享session),通过地址 http://127.0.0.1:8080 访问zlt应用,单点登录成功显示当前登录用户名、权限、应用id信息
\ No newline at end of file
zlt-demo/sso-demo/pom.xml
0 → 100644
浏览文件 @
b4d8fa93
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-demo
</artifactId>
<version>
3.2.0
</version>
</parent>
<artifactId>
sso-demo
</artifactId>
<description>
单点登录demo
</description>
<dependencies>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-common-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-oauth2
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-extension
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
zlt-demo/sso-demo/src/main/java/com/sso/demo/SSOApplication.java
0 → 100644
浏览文件 @
b4d8fa93
package
com.sso.demo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @author zlt
* @date 2020/2/22
* <p>
* Blog: https://blog.csdn.net/zlt2000
* Github: https://github.com/zlt2000
*/
@SpringBootApplication
public
class
SSOApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SSOApplication
.
class
,
args
);
}
}
zlt-demo/sso-demo/src/main/java/com/sso/demo/config/SecurityConfig.java
0 → 100644
浏览文件 @
b4d8fa93
package
com.sso.demo.config
;
import
cn.hutool.core.util.StrUtil
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
/**
* security配置
*
* @author zlt
* @date 2020/2/22
* <p>
* Blog: https://blog.csdn.net/zlt2000
* Github: https://github.com/zlt2000
*/
@EnableOAuth2Sso
@Configuration
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Value
(
"${security.oauth2.sso.login-path:}"
)
private
String
loginPath
;
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
authorizeRequests
().
anyRequest
().
authenticated
()
.
and
()
.
csrf
().
disable
();
if
(
StrUtil
.
isNotEmpty
(
loginPath
))
{
http
.
formLogin
().
loginProcessingUrl
(
loginPath
);
}
}
}
\ No newline at end of file
zlt-demo/sso-demo/src/main/java/com/sso/demo/controller/HomeController.java
0 → 100644
浏览文件 @
b4d8fa93
package
com.sso.demo.controller
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.web.bind.annotation.GetMapping
;
/**
* @author zlt
* @date 2020/2/22
* <p>
* Blog: https://blog.csdn.net/zlt2000
* Github: https://github.com/zlt2000
*/
@Controller
public
class
HomeController
{
@GetMapping
(
"/"
)
public
String
home
(
ModelMap
modelMap
,
Authentication
authentication
)
{
OAuth2Authentication
oauth2Authentication
=
(
OAuth2Authentication
)
authentication
;
modelMap
.
put
(
"username"
,
oauth2Authentication
.
getName
());
modelMap
.
put
(
"authorities"
,
oauth2Authentication
.
getAuthorities
());
modelMap
.
put
(
"clientId"
,
oauth2Authentication
.
getOAuth2Request
().
getClientId
());
OAuth2AuthenticationDetails
details
=
(
OAuth2AuthenticationDetails
)
oauth2Authentication
.
getDetails
();
modelMap
.
put
(
"token"
,
details
.
getTokenValue
());
return
"index"
;
}
}
zlt-demo/sso-demo/src/main/resources/bootstrap.yml
0 → 100644
浏览文件 @
b4d8fa93
server
:
port
:
8080
spring
:
application
:
name
:
sso-demo
zlt
:
api-uaa
:
url
:
http://127.0.0.1:9900/api-uaa/oauth
security
:
oauth2
:
sso
:
login-path
:
/singleLogin
client
:
client-id
:
zlt
client-secret
:
zlt
access-token-uri
:
${zlt.api-uaa.url}/token
user-authorization-uri
:
${zlt.api-uaa.url}/authorize
resource
:
token-info-uri
:
${zlt.api-uaa.url}/check_token
zlt-demo/sso-demo/src/main/resources/templates/index.html
0 → 100644
浏览文件 @
b4d8fa93
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
content=
"text/html;charset=UTF-8"
>
<title>
SSO单点登录demo
</title>
</head>
<body>
<div>
登录者:
<span
th:text=
"${username}"
></span>
<br/>
权限:
<span
th:text=
"${authorities}"
></span>
<br/>
应用id:
<span
th:text=
"${clientId}"
></span>
<br/>
token:
<span
th:text=
"${token}"
></span>
</div>
</body>
</html>
zlt-demo/sso-demo/单点登录架构图.jpg
0 → 100644
浏览文件 @
b4d8fa93
73.3 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录