SpringBoot+SpringSecurityOAuth2.0 实现SSO单点登录(一)--客户端

SSO Client

准备:

使用maven构建项目,导入1.5.4SpringBootjar

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.4.RELEASE</version>

<relativePath/>

</parent>

导入所必须的springboot集成securityjarspring-boot-starter-security以及它的依赖包spring-security-jwt

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-security</artifactId>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-jwt</artifactId>

 

基于OAuth认证,导入

<groupId>org.springframework.security.oauth</groupId>

<artifactId>spring-security-oauth2</artifactId>

由于是web项目继续导入spring-boot-starter-web

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

页面显示模版使用springBoot官方推荐的thymeleaf 导入spring-boot-starter-thymeleaf

 

配置:

配置springBoot启动yml文件,设置SSO认证必要参数

#配置服务地址 及登出地址

myOAthConfig: 

  hostUrl: http://localhost:5678

  logoutUrl: ${myOAthConfig.hostUrl}/logout

 

security:

  oauth2:

    sso:

      login-path: /login

    client:

      client-id: acme

      client-secret: acmesecret

      access-token-uri: ${myOAthConfig.hostUrl}/oauth/token

      user-authorization-uri: ${myOAthConfig.hostUrl}/oauth/authorize

      client-authentication-scheme: form

    resource:

      jwt:

        key-uri: ${myOAthConfig.hostUrl}/oauth/token_key

添加本地安全策略:

新建SecurityConfiguration继承WebSecurityConfigurerAdapter添加@Configuration上下文配置spring容器  @EnableOAuth2Sso开启OAuth认证SSO

重写configure(HttpSecurity http)方法,配置该客户端访问安全策略

 

 

 

首先开启SSO服务器,再开启Client 否则会报错

 

  • 16
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值