Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
31e773c3
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,发现更多精彩内容 >>
提交
31e773c3
编写于
3月 10, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化sso-demo增加登出功能
上级
c62acfa5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
8 deletion
+54
-8
zlt-demo/sso-demo/src/main/java/com/sso/demo/config/SecurityConfig.java
...emo/src/main/java/com/sso/demo/config/SecurityConfig.java
+9
-1
zlt-demo/sso-demo/src/main/java/com/sso/demo/config/SsoLogoutSuccessHandler.java
...ain/java/com/sso/demo/config/SsoLogoutSuccessHandler.java
+39
-0
zlt-demo/sso-demo/src/main/resources/bootstrap.yml
zlt-demo/sso-demo/src/main/resources/bootstrap.yml
+1
-0
zlt-demo/sso-demo/src/main/resources/templates/index.html
zlt-demo/sso-demo/src/main/resources/templates/index.html
+5
-7
未找到文件。
zlt-demo/sso-demo/src/main/java/com/sso/demo/config/SecurityConfig.java
浏览文件 @
31e773c3
...
@@ -6,6 +6,9 @@ import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth
...
@@ -6,6 +6,9 @@ import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.web.authentication.logout.LogoutSuccessHandler
;
import
javax.annotation.Resource
;
/**
/**
* security配置
* security配置
...
@@ -22,11 +25,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -22,11 +25,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value
(
"${security.oauth2.sso.login-path:}"
)
@Value
(
"${security.oauth2.sso.login-path:}"
)
private
String
loginPath
;
private
String
loginPath
;
@Resource
private
LogoutSuccessHandler
ssoLogoutSuccessHandler
;
@Override
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
authorizeRequests
().
anyRequest
().
authenticated
()
http
.
authorizeRequests
().
anyRequest
().
authenticated
()
.
and
()
.
and
()
.
csrf
().
disable
();
.
csrf
().
disable
()
.
logout
()
.
logoutSuccessHandler
(
ssoLogoutSuccessHandler
);
if
(
StrUtil
.
isNotEmpty
(
loginPath
))
{
if
(
StrUtil
.
isNotEmpty
(
loginPath
))
{
http
.
formLogin
().
loginProcessingUrl
(
loginPath
);
http
.
formLogin
().
loginProcessingUrl
(
loginPath
);
}
}
...
...
zlt-demo/sso-demo/src/main/java/com/sso/demo/config/SsoLogoutSuccessHandler.java
0 → 100644
浏览文件 @
31e773c3
package
com.sso.demo.config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails
;
import
org.springframework.security.web.DefaultRedirectStrategy
;
import
org.springframework.security.web.RedirectStrategy
;
import
org.springframework.security.web.authentication.logout.LogoutSuccessHandler
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* 登出成功处理类
*
* @author zlt
* @date 2020/3/10
* <p>
* Blog: https://blog.csdn.net/zlt2000
* Github: https://github.com/zlt2000
*/
@Component
public
class
SsoLogoutSuccessHandler
implements
LogoutSuccessHandler
{
@Value
(
"${zlt.logout-uri:''}"
)
private
String
logoutUri
;
private
RedirectStrategy
redirectStrategy
=
new
DefaultRedirectStrategy
();
@Override
public
void
onLogoutSuccess
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Authentication
authentication
)
throws
IOException
{
OAuth2Authentication
oauth2Authentication
=
(
OAuth2Authentication
)
authentication
;
OAuth2AuthenticationDetails
details
=
(
OAuth2AuthenticationDetails
)
oauth2Authentication
.
getDetails
();
String
accessToken
=
details
.
getTokenValue
();
redirectStrategy
.
sendRedirect
(
request
,
response
,
logoutUri
+
accessToken
);
}
}
zlt-demo/sso-demo/src/main/resources/bootstrap.yml
浏览文件 @
31e773c3
...
@@ -8,6 +8,7 @@ spring:
...
@@ -8,6 +8,7 @@ spring:
zlt
:
zlt
:
api-uaa
:
api-uaa
:
url
:
http://127.0.0.1:9900/api-uaa/oauth
url
:
http://127.0.0.1:9900/api-uaa/oauth
logout-uri
:
${zlt.api-uaa.url}/remove/token?redirectUri=http://127.0.0.1:8080&access_token=
security
:
security
:
oauth2
:
oauth2
:
...
...
zlt-demo/sso-demo/src/main/resources/templates/index.html
浏览文件 @
31e773c3
...
@@ -6,13 +6,11 @@
...
@@ -6,13 +6,11 @@
</head>
</head>
<body>
<body>
<div>
<div>
登录者:
<span
th:text=
"${username}"
></span>
<p>
登录者:
<span
th:text=
"${username}"
></span></p>
<br/>
<p>
权限:
<span
th:text=
"${authorities}"
></span></p>
权限:
<span
th:text=
"${authorities}"
></span>
<p>
应用id:
<span
th:text=
"${clientId}"
></span></p>
<br/>
<p>
token:
<span
th:text=
"${token}"
></span></p>
应用id:
<span
th:text=
"${clientId}"
></span>
<p><input
type=
"button"
value=
"登出"
onclick=
"location='/logout'"
/></p>
<br/>
token:
<span
th:text=
"${token}"
></span>
</div>
</div>
</body>
</body>
</html>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录