基于Spring Boot2 + Spring Security OAuth2 实现单点登陆(二)

放几个阿里云的优惠链接 代金券 / 高性能服务器2折起 / 高性能服务器5折

关于单点登陆的基本实现:点这里

实现一个基于jdbc的OAuth2认证

本文主要介绍使用jdbc存储token的例子。代码基于上一篇文章做一些修改实现。
源码地址


修改项目依赖
project("sso-auth-server") {
    dependencies {
        compile 'org.springframework.boot:spring-boot-starter-web'
        compile 'org.springframework.boot:spring-boot-starter-security'
        compile 'org.springframework.boot:spring-boot-starter-jdbc' // 新添加
        compile 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.0.RELEASE'
        runtime 'mysql:mysql-connector-java' // 新添加
    }
}

创建OAuth2数据存储相关表

Spring官方给出了基于HSQL建表sql。本文数据库使用mysql,对它做了一些修改。看这里

  • 配置数据库链接
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/oauth2test
  • 创建数据库表
    这里直接使用程序调用sql脚本实现。
public class AuthenticationApplication {
   
    private static final Logger log = LoggerFactory.getLogger(AuthenticationApplication.class);

    public static void main(String[] args) 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值