Skip to content

Commit

Permalink
add moudle authorization server.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Mar 6, 2024
1 parent 1f5a1d5 commit d325c6a
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 19 deletions.
36 changes: 36 additions & 0 deletions boot/authorization/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
83 changes: 83 additions & 0 deletions boot/authorization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Getting Started

### Reference Documentation

For further reference, please consider the following sections:

* [Official Gradle documentation](https://docs.gradle.org)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.2.3/gradle-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.2.3/gradle-plugin/reference/html/#build-image)
* [GraalVM Native Image Support](https://docs.spring.io/spring-boot/docs/3.2.3/reference/html/native-image.html#native-image)
* [Spring Configuration Processor](https://docs.spring.io/spring-boot/docs/3.2.3/reference/htmlsingle/index.html#appendix.configuration-metadata.annotation-processor)
* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.2.3/reference/htmlsingle/index.html#data.sql.jpa-and-spring-data)
* [Spring Data Redis (Access+Driver)](https://docs.spring.io/spring-boot/docs/3.2.3/reference/htmlsingle/index.html#data.nosql.redis)
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.2.3/reference/htmlsingle/index.html#using.devtools)
* [OAuth2 Authorization Server](https://docs.spring.io/spring-boot/docs/3.2.3/reference/htmlsingle/index.html#web.security.oauth2.authorization-server)
* [Spring Web](https://docs.spring.io/spring-boot/docs/3.2.3/reference/htmlsingle/index.html#web)

### Guides

The following guides illustrate how to use some features concretely:

* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)
* [Messaging with Redis](https://spring.io/guides/gs/messaging-redis/)
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)

### Additional Links

These additional references should also help you:

* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)
* [Configure AOT settings in Build Plugin](https://docs.spring.io/spring-boot/docs/3.2.3/gradle-plugin/reference/htmlsingle/#aot)

## GraalVM Native Support

This project has been configured to let you generate either a lightweight container or a native executable.
It is also possible to run your tests in a native image.

### Lightweight Container with Cloud Native Buildpacks

If you're already familiar with Spring Boot container images support, this is the easiest way to get started.
Docker should be installed and configured on your machine prior to creating the image.

To create the image, run the following goal:

```
$ ./gradlew bootBuildImage
```

Then, you can run the app like any other container:

```
$ docker run --rm -p 8080:8080 authorization:0.0.1-SNAPSHOT
```

### Executable with Native Build Tools

Use this option if you want to explore more options such as running your tests in a native image.
The GraalVM `native-image` compiler should be installed and configured on your machine.

NOTE: GraalVM 22.3+ is required.

To create the executable, run the following goal:

```
$ ./gradlew nativeCompile
```

Then, you can run the app as follows:

```
$ build/native/nativeCompile/authorization
```

You can also run your existing tests suite in a native image.
This is an efficient way to validate the compatibility of your application.

To run your existing tests in a native image, run the following goal:

```
$ ./gradlew nativeTest
```
73 changes: 73 additions & 0 deletions boot/authorization/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
plugins {
id 'java'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
id 'org.graalvm.buildtools.native'
id 'org.hibernate.orm' version '6.4.4.Final'
}

java {
sourceCompatibility = '21'
targetCompatibility = '21'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

tasks.named("bootBuildImage") {
tags = ["${dockerPrefix}/${rootProject.name}-${project.name}:latest"]
imageName = ("${dockerPrefix}/${rootProject.name}-${project.name}:${project.version}")
environment = [
"BPE_DELIM_JAVA_TOOL_OPTIONS" : " ",
"BPE_APPEND_JAVA_TOOL_OPTIONS": "-Dfile.encoding=UTF-8"
]
buildWorkspace {
bind {
source = "cache.${rootProject.name}-${project.name}.work"
}
}
buildCache {
bind {
source = "cache.${rootProject.name}-${project.name}.build"
}
}
launchCache {
bind {
source = "cache.${rootProject.name}-${project.name}.launch"
}
}
publish = true
docker {
publishRegistry {
username = "${dockerUsername}"
password = "${dockerPassword}"
email = "${dockerEmail}"
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-authorization-server'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.postgresql:postgresql'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}

hibernate {
enhancement {
enableAssociationManagement = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.plate.authorization;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author Alex bob(<a href="https://github.com/vnobo">Alex Bob</a>)
*/
@SpringBootApplication
public class AuthorizationApplication {

public static void main(String[] args) {
SpringApplication.run(AuthorizationApplication.class, args);
}

}
26 changes: 26 additions & 0 deletions boot/authorization/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server:
shutdown: graceful
http2.enabled: true
compression.enabled: true

spring:
threads.virtual.enabled: true
#main.keep-alive: true
application.name: authorization
mvc.format:
time: "HH:mm:ss"
date-time: "yyyy-MM-dd HH:mm:ss"
date: "yyyy-MM-dd"
jackson:
date-format: "yyyy-MM-dd HH:mm:ss"
time-zone: "GMT+8"
locale: "zh_CN"
codec:
max-in-memory-size: 10MB
log-request-details: false
cache:
type: redis
redis:
key-prefix: "authorization:caches:"
time-to-live: 300s
enable-statistics: true
40 changes: 40 additions & 0 deletions boot/authorization/src/main/resources/data-postgres.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
insert into se_users(code, username, password, name, creator, updater)
values ('U1000', 'admin',
'{pbkdf2}7d8a68bc5d507bd19bc153ff10bcdef66f5a5f3d0c1ab2438630e50b5c65894bccc2c7e4404c5afa',
'系统超级管理员', 'U1000', 'U1000');

insert into se_authorities(code, user_code, authority, creator, updater)
values ('UA1000', 'U1000', 'ROLE_SYSTEM_ADMINISTRATORS', 'U1000', 'U1000'),
('UA1001', 'U1000', 'users:read', 'U1000', 'U1000'),
('UA1002', 'U1000', 'users:write', 'U1000', 'U1000'),
('UA1003', 'U1000', 'users:delete', 'U1000', 'U1000');

insert into se_groups(code, name, creator, updater)
values ('G1000', '系统管理员', 'U1000', 'U1000');

insert into se_group_members(code, group_code, user_code, creator, updater)
values ('GM1000', 'G1000', 'U1000', 'U1000', 'U1000');

insert into se_group_authorities(code, group_code, authority, creator, updater)
values ('GA1000', 'G1000', 'ROLE_ADMINISTRATORS', 'U1000', 'U1000'),
('GA1001', 'U1000', 'users:read', 'U1000', 'U1000'),
('GA1002', 'U1000', 'users:write', 'U1000', 'U1000');


/********Init menus****************/
insert into se_menus(code, type, authority, name, path, creator, updater, extend)
values ('M1000', 'FOLDER', 'ROLE_FOLDER_SYSTEM', '系统管理', '', 'U1000', 'U1000', '{
"icons": "settings"
}');
insert into se_menus(code, pcode, type, authority, name, path, creator, updater, extend)
values ('M1001', 'M1000', 'MENU', 'ROLE_MENU_SYSTEM_USERS', '用户管理', '/system/users', 'U1000', 'U1000', '{
"icons": "lock"
}');
insert into se_menus(code, pcode, type, authority, name, path, creator, updater, extend)
values ('M1002', 'M1000', 'MENU', 'ROLE_MENU_SYSTEM_GROUPS', '角色管理', '/system/groups', 'U1000', 'U1000', '{
"icons": "users"
}');
insert into se_menus(code, pcode, type, authority, name, path, creator, updater, extend)
values ('M1003', 'M1000', 'MENU', 'ROLE_MENU_SYSTEM_MENUS', '菜单管理', '/system/menus', 'U1000', 'U1000', '{
"icons": "menu-2"
}');
Loading

0 comments on commit d325c6a

Please sign in to comment.