diff --git a/readme.md b/readme.md
index c5d2ed701cd530dd1049888df9a57a35d14d4cee..0b5bfa5e6de10b2fd1fac01c60f946516d1d1df1 100644
--- a/readme.md
+++ b/readme.md
@@ -4,7 +4,7 @@ It's a demo project for spring-auth-server.
This project consist of following three sub-projects.
-## spring-auth-server-demo
+## auth-server-demo
Auth. server, including identity management.
@@ -39,8 +39,19 @@ Dependencies:
- SQL Server 2019;
- Spring Auth Server;
+## idp-server-demo
-## spring-resource-server-demo
+Identity server demo.
+
+Dependencies:
+- Java 17;
+- Spring Boot 3.0;
+ - Spring Boot JPA;
+ - Spring Boot Web;
+- SQL Server 2019;
+- Spring Auth Server;
+
+## resource-server-demo
Resource server.
@@ -57,6 +68,7 @@ Dependencies:
- SQL Server 2019;
- Resource Server;
+
## angular-client-demo
An angular client which consume that resources.
diff --git a/resource-server-demo/pom.xml b/resource-server-demo/pom.xml
index 0292efa8d258b5ed9a0b95a8e0680f1e5658d10c..8a8f353a5fdef2f50cb1727731fbb583b1731f81 100644
--- a/resource-server-demo/pom.xml
+++ b/resource-server-demo/pom.xml
@@ -35,10 +35,16 @@
- org.postgresql
- postgresql
+ com.microsoft.sqlserver
+ mssql-jdbc
+ 11.2.1.jre17
runtime
+
+ com.h2database
+ h2
+ test
+
org.springframework.security
spring-security-test
diff --git a/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/config/ResourceServerConfig.java b/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/config/ResourceServerConfig.java
index c481ffec3688e71e75fe8570c62301cfc5e49021..868b66851788c7901b9204cce05c1e5d8ae0a82d 100644
--- a/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/config/ResourceServerConfig.java
+++ b/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/config/ResourceServerConfig.java
@@ -1,19 +1,24 @@
package com.poc.alvachien.resourceserverdemo.config;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@EnableWebSecurity
+@Configuration(proxyBeanMethods = false)
public class ResourceServerConfig {
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
- .authorizeRequests()
- .requestMatchers("/api/protected/**").authenticated()
- .requestMatchers("/").permitAll();
+ .securityMatcher("/api/protected/**")
+ .authorizeHttpRequests()
+ .requestMatchers("/api/protected/**").hasAuthority("SCOPE_message.read")
+ .and()
+ .oauth2ResourceServer()
+ .jwt();
return http.build();
}
}
diff --git a/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/ProtectedController.java b/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/ProtectedController.java
index fda0d5ab8eead6425523cd98038f2a267425290f..77cfacd8e9d5a1f2779784e3de6770ee83bb272e 100644
--- a/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/ProtectedController.java
+++ b/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/ProtectedController.java
@@ -3,7 +3,6 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.RequestParam;
@RestController
diff --git a/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/NonProtectedController.java b/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/PublicController.java
similarity index 64%
rename from resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/NonProtectedController.java
rename to resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/PublicController.java
index 4be64bec0630f2dd7063810fe9642c3f80c13ef1..22518a6647ba0a7d9068515ffda8d88e532d0cd8 100644
--- a/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/NonProtectedController.java
+++ b/resource-server-demo/src/main/java/com/poc/alvachien/resourceserverdemo/controller/PublicController.java
@@ -3,14 +3,12 @@ package com.poc.alvachien.resourceserverdemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.RequestParam;
-
@RestController
-@RequestMapping("/api/NonProtected")
-public class NonProtectedController {
+@RequestMapping("/api/Public")
+public class PublicController {
@GetMapping("/sayhi")
public String sayhi() {
- return "Say hi from Non-Protected";
+ return "Say hi from Public";
}
}
diff --git a/resource-server-demo/src/main/resources/application.properties b/resource-server-demo/src/main/resources/application.properties
deleted file mode 100644
index e876b698a99ebf012df64612c674246f184e0dee..0000000000000000000000000000000000000000
--- a/resource-server-demo/src/main/resources/application.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-server.port:9500
-
-spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:9600
-
-spring.jpa.hibernate.ddl-auto=update
-spring.datasource.url=jdbc:sqlserver://localhost;encrypt=true;database=authresource;integratedSecurity=true;trustServerCertificate=true
-#spring.datasource.username=springuser
-#spring.datasource.password=ThePassword
-spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
-spring.jpa.show-sql: true
diff --git a/resource-server-demo/src/main/resources/application.yml b/resource-server-demo/src/main/resources/application.yml
new file mode 100644
index 0000000000000000000000000000000000000000..715e00ffa6c0afbd652865d63663e28c4fc54b3f
--- /dev/null
+++ b/resource-server-demo/src/main/resources/application.yml
@@ -0,0 +1,16 @@
+server:
+ port: 8090
+
+logging:
+ level:
+ root: INFO
+ org.springframework.web: INFO
+ org.springframework.security: INFO
+ org.springframework.security.oauth2: INFO
+
+spring:
+ security:
+ oauth2:
+ resourceserver:
+ jwt:
+ issuer-uri: http://localhost:9000
\ No newline at end of file