watchdog-spring-boot-starter

Watchdog is an OAuth 2 provider for SpringBoot

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

org.yuequan
ArtifactId

ArtifactId

watchdog-spring-boot-starter
Last Version

Last Version

0.8.3.BETA
Release Date

Release Date

Type

Type

jar
Description

Description

watchdog-spring-boot-starter
Watchdog is an OAuth 2 provider for SpringBoot
Project URL

Project URL

https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/watchdog-spring-boot-starter
Project Organization

Project Organization

Pivotal Software, Inc.
Source Code Management

Source Code Management

https://github.com/yuequan1997/watchdog-spring-boot-starter

Download watchdog-spring-boot-starter

How to add to project

<!-- https://jarcasting.com/artifacts/org.yuequan/watchdog-spring-boot-starter/ -->
<dependency>
    <groupId>org.yuequan</groupId>
    <artifactId>watchdog-spring-boot-starter</artifactId>
    <version>0.8.3.BETA</version>
</dependency>
// https://jarcasting.com/artifacts/org.yuequan/watchdog-spring-boot-starter/
implementation 'org.yuequan:watchdog-spring-boot-starter:0.8.3.BETA'
// https://jarcasting.com/artifacts/org.yuequan/watchdog-spring-boot-starter/
implementation ("org.yuequan:watchdog-spring-boot-starter:0.8.3.BETA")
'org.yuequan:watchdog-spring-boot-starter:jar:0.8.3.BETA'
<dependency org="org.yuequan" name="watchdog-spring-boot-starter" rev="0.8.3.BETA">
  <artifact name="watchdog-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.yuequan', module='watchdog-spring-boot-starter', version='0.8.3.BETA')
)
libraryDependencies += "org.yuequan" % "watchdog-spring-boot-starter" % "0.8.3.BETA"
[org.yuequan/watchdog-spring-boot-starter "0.8.3.BETA"]

Dependencies

compile (8)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter jar 2.1.0.RELEASE
org.springframework.boot : spring-boot-starter-security jar 2.1.0.RELEASE
org.springframework.security.oauth : spring-security-oauth2 jar 2.3.4.RELEASE
org.springframework : spring-jdbc Optional jar
com.fasterxml.jackson.core : jackson-annotations Optional jar 2.9.7
com.fasterxml.jackson.core : jackson-databind Optional jar 2.9.7
com.sun.xml.bind : jaxb-impl jar 2.2.11
com.sun.xml.bind : jaxb-core jar 2.2.11

test (4)

Group / Artifact Type Version
org.springframework.security : spring-security-test jar
org.springframework.boot : spring-boot-starter-test jar 2.1.0.RELEASE
com.h2database : h2 jar 1.4.197
javax.servlet : javax.servlet-api jar 4.0.1

Project Modules

There are no modules declared in this project.

logowatchdog-spring-boot-starter

Watchdog is an OAuth 2 provider for SpringBoot

starter基于spring-boot-starter-securityspring-security-oauth2上做的改进封装,能够快速的搭建出一个可管理的OAuth 2 provider

not recommended

在没有它之前你可能需要这样的硬编码或者使用RedisJDBC等之类的来做这件事情难以管理,扩展也不便太麻烦使用起来不优雅。

如何使用

工程下也有示例项目在smaple文件夹中

注意哟,Watchdog是从SpringBoot 2.1.0.RELEASE 上开发的,建议使用新的版本,使用低的版本可能会带来配置上的不一致而产生问题哦

执行项目根路径下面的schema.sql文件,创建所需的表,同时也欢迎大家来补充和扩展其它类型的数据库

pom.xml文件中引入依赖(由于刚推送到Maven Central有的仓库还没有同步可能还需要几个小时)

<dependency>
    <groupId>org.yuequan</groupId>
    <artifactId>watchdog-spring-boot-starter</artifactId>
    <version>0.8.2.BETA</version>
</dependency>

然后再启动类上配置@EnableWatchdog注解

@SpringBootApplication
@EnableWatchDog
public class WatchdogSampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(WatchdogSampleApplication.class, args);
    }
}

配置好的你的PasswordEncoderauthenticationManager,类似于以下:

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser(User.withUsername("user_1").password(passwordEncoder.encode("123456")).authorities("USER"));
    }

    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }
}

启动你的项目,输入网址http://localhost:8080/watchdog.html

index

show

可以点击授权重定向地址跳转到客户端认证授权,也可以复制client_idclient_secret进行token认证,例如http://localhost:8080/oauth/token?username=yourUser&password=yourPassword&grant_type=password&scope=DEFAULT&client_id=CLIENT_ID&client_secret=CLIENT_PASSWORD

update

create

delete

WatchdogUrlRegistryProvider

HttpSecurity进行扩展是最常见不过的事情了,所以Watchdog提供了一种很优雅的方式去扩展,如下:

@Component
public class AuthorizationProvider implements WatchdogUrlRegistryProvider {

    @Override
    public boolean configure(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config.............
        return true;
    }
}

Versions

Version
0.8.3.BETA
0.8.2.BETA
0.8.1.BETA
0.8.0.BETA
0.7.0.BETA
0.6.0.BETA