实现一个最基本的OAuth3认证
项目使用3个独立的工程分别实现认证服务、资源服务器和单点登陆服务器
源码地址
添加项目依赖
allprojects {
apply plugin: 'idea'
apply plugin: 'java'
}
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
maven { url 'http://maven.aliyun.com/mvn/repository/' }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
maven { url 'http://maven.aliyun.com/mvn/repository/' }
mavenCentral()
}
}
project("sso-auth-server") {
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.0.RELEASE'
}
}
project("sso-auth-client") {
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.0.RELEASE'
}
}
project("sso-auth-resource") {
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.0.RELEASE'
}
}
认证服务器配置
- 使用EnableAuthorizationServer注解开启认证服务
@SpringBootApplication
@EnableAuthorizationServer
public class AuthenticationApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(AuthenticationApplication.class)
.run(args);
}
}
- 使用EnableWebSecurity注解开启权限验证,并做相关配置
@EnableWebSecurity
public class
版权声明:本文为qq_19671173原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。