Skip to content

Commit 216bf79

Browse files
refactor : v4.0.0 (knife -> easyplus)
1 parent 0f6d844 commit 216bf79

File tree

209 files changed

+3999
-4090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+3999
-4090
lines changed

README.md

+38-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Spring Security Oauth2 JPA Implementation
1+
# Spring Oauth2 EasyPlus
22

3-
> App-Token based OAuth2 implementation built to grow with Spring Boot and JPA
3+
> App-Token based easy OAuth2 implementation built to grow with Spring Boot
44
55
## Table of Contents
66

@@ -22,9 +22,9 @@
2222
## Quick Start
2323
```xml
2424
<dependency>
25-
<groupId>io.github.patternknife.securityhelper.oauth2.api</groupId>
26-
<artifactId>spring-security-oauth2-password-jpa-implementation</artifactId>
27-
<version>3.5.0</version>
25+
<groupId>io.github.patternhelloworld.securityhelper.oauth2.api</groupId>
26+
<artifactId>spring-oauth2-easyplus</artifactId>
27+
<version>4.0.0</version>
2828
</dependency>
2929
```
3030

@@ -36,6 +36,7 @@
3636
* Client : DOC, Integration tester
3737
* Immediate Permission (Authority) Check: Not limited to verifying the token itself, but also ensuring real-time validation of any updates to permissions in the database.
3838
* Token Introspector: Enable the ``/oauth2/introspect`` endpoint to allow multiple resource servers to verify the token's validity and permissions with the authorization server.
39+
* Hybrid Token Verification Methods: Support for multiple verification approaches, including API calls to the authorization server, direct database validation, and local JWT decoding.
3940
* Set up the same access & refresh token APIs on both ``/oauth2/token`` and on our controller layer such as ``/api/v1/traditional-oauth/token``, both of which function same and have `the same request & response payloads for success and errors`. (However, ``/oauth2/token`` is the standard that "spring-authorization-server" provides.)
4041
* As you are aware, the API ``/oauth2/token`` is what "spring-authorization-server" provides.
4142
* ``/api/v1/traditional-oauth/token`` is what this library implemented directly.
@@ -72,7 +73,7 @@
7273
| different for the same user | Access-Token is NOT shared |
7374

7475
* Set this in your ``application.properties``.
75-
* App-Token Behavior Based on `io.github.patternknife.securityhelper.oauth2.no-app-token-same-access-token`
76+
* App-Token Behavior Based on `io.github.patternhelloworld.securityhelper.oauth2.no-app-token-same-access-token`
7677

7778
| `no-app-token-same-access-token` Value | App-Token Status | Access Token Sharing Behavior |
7879
|------------------------------------------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
@@ -127,8 +128,8 @@ mvnw clean install # Integration tests are done here, which creates docs by Spri
127128

128129
```java
129130

130-
// ADD 'io.github.patternknife.securityhelper.oauth2.api'
131-
@SpringBootApplication(scanBasePackages = {"com.patternknife.securityhelper.oauth2.client", "io.github.patternknife.securityhelper.oauth2.api"})
131+
// ADD 'io.github.patternhelloworld.securityhelper.oauth2.api'
132+
@SpringBootApplication(scanBasePackages = {"com.patternhelloworld.securityhelper.oauth2.client", "io.github.patternhelloworld.securityhelper.oauth2.api"})
132133
public class SpringSecurityOauth2PasswordJpaImplApplication {
133134

134135
public static void main(String[] args) {
@@ -140,25 +141,25 @@ public class SpringSecurityOauth2PasswordJpaImplApplication {
140141

141142
```java
142143
@Configuration
143-
// ADD 'io.github.patternknife.securityhelper.oauth2.api.config.security'
144+
// ADD 'io.github.patternhelloworld.securityhelper.oauth2.api.config.security'
144145
@EnableJpaRepositories(
145-
basePackages = {"com.patternknife.securityhelper.oauth2.client.domain",
146-
"com.patternknife.securityhelper.oauth2.client.config.securityimpl",
147-
"io.github.patternknife.securityhelper.oauth2.api.config.security"},
146+
basePackages = {"com.patternhelloworld.securityhelper.oauth2.client.domain",
147+
"com.patternhelloworld.securityhelper.oauth2.client.config.securityimpl",
148+
"io.github.patternhelloworld.securityhelper.oauth2.api.config.security"},
148149
entityManagerFactoryRef = "commonEntityManagerFactory",
149150
transactionManagerRef= "commonTransactionManager"
150151
)
151152
public class CommonDataSourceConfiguration {
152153

153154

154-
// ADD 'io.github.patternknife.securityhelper.oauth2.api.config.security'
155+
// ADD 'io.github.patternhelloworld.securityhelper.oauth2.api.config.security'
155156
@Primary
156157
@Bean(name = "commonEntityManagerFactory")
157158
public LocalContainerEntityManagerFactoryBean commonEntityManagerFactory(EntityManagerFactoryBuilder builder) {
158159
return builder
159160
.dataSource(commonDataSource())
160-
.packages("com.patternknife.securityhelper.oauth2.client.domain",
161-
"io.github.patternknife.securityhelper.oauth2.api.config.security")
161+
.packages("com.patternhelloworld.securityhelper.oauth2.client.domain",
162+
"io.github.patternhelloworld.securityhelper.oauth2.api.config.security")
162163
.persistenceUnit("commonEntityManager")
163164
.build();
164165
}
@@ -187,13 +188,12 @@ public class CommonDataSourceConfiguration {
187188

188189
- **Customize the whole error payload as desired for all cases**
189190
- What is "all cases"?
190-
- Authorization Server ("/oauth2/token", "/api/v1/traditional-oauth/token") and Resource Server (Bearer token inspection : 401, Permission : 403)
191+
- Authorization Server ("/oauth2/token", "/api/v1/traditional-oauth/token") and Resource Server (Bearer token authentication : 401, authorization (permission) : 403)
191192
- Customize errors of the following cases
192193
- Login (/oauth2/token) : ``client.config.securityimpl.response.CustomAuthenticationFailureHandlerImpl``
193194
- Login (/api/v1/traditional-oauth/token) : ``client.config.response.error.GlobalExceptionHandler.authenticationException`` ("/api/v1/traditional-oauth/token", Resource Server (Bearer token inspection))
194195
- Resource Server (Bearer token expired or with a wrong value, 401) :``client.config.securityimpl.response.CustomAuthenticationEntryPointImpl``
195196
- Resource Server (Permission, 403, @PreAuthorized on your APIs) ``client.config.response.error.GlobalExceptionHandler.authorizationException``
196-
197197

198198
- **Customize the whole success payload as desired for the only "/oauth2/token"**
199199
- ``client.config.securityimpl.response.CustomAuthenticationSuccessHandlerImpl``
@@ -202,9 +202,28 @@ public class CommonDataSourceConfiguration {
202202
- **Customize the verification logic for UsernamePassword and Client as desired**
203203
- ``IOauth2AuthenticationHashCheckService``
204204

205-
- **Customize OpaqueTokenIntrospector as desired (!Set this to your Resource Servers)**
205+
- **Customize OpaqueTokenIntrospector as desired (!This is for Resource Servers)**
206206
- ``client.config.securityimpl.introspector.CustomResourceServerTokenIntrospector``
207-
- ![img3.png](reference/docs/img3.png)
207+
- ```properties
208+
# Introspection type configuration:
209+
# - api: The Resource Server sends introspection requests to the Authorization Server.
210+
# Benefits: High scalability and real-time authorization checks.
211+
# Drawbacks: Increased traffic due to frequent API calls.
212+
#
213+
# - database: The Resource Server and Authorization Server share the same database.
214+
# Benefits: Minimal traffic and real-time authorization checks.
215+
# Drawbacks: Limited scalability due to direct database dependency.
216+
#
217+
# - decode: The Resource Server decodes the Access Token locally using the JWT algorithm.
218+
# Benefits: No traffic and high scalability.
219+
# Drawbacks: Lacks real-time authorization updates.
220+
#
221+
# [WARNING] api: Certain test cases are currently failing due to issues with the specified introspection URI calls.
222+
patternhelloworld.securityhelper.oauth2.introspection.type=database
223+
patternhelloworld.securityhelper.oauth2.introspection.uri=http://localhost:8370/oauth2/introspect
224+
patternhelloworld.securityhelper.oauth2.introspection.client-id=client_customer
225+
patternhelloworld.securityhelper.oauth2.introspection.client-secret=12345
226+
```
208227
## OAuth2 - ROPC
209228
* Refer to ``client/src/docs/asciidoc/api-app.adoc``
210229

client/deploy.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@echo off
2-
set local_maven_repo="C:\Users\Andrew Kang\.m2\repository\com\patternknife\securityhelper\oauth2\spring-security-oauth2-password-jpa-implementation"
2+
set local_maven_repo="C:\Users\Andrew Kang\.m2\repository\com\patternhelloworld\securityhelper\oauth2\spring-oauth2-easyplus"
33
mvnw.cmd -DaltDeploymentRepository=snapshot-repo::default::file://%local_maven_repo%/snapshots clean deploy

client/deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
local_maven_repo='/mnt/c/Users/Andrew\sKang/.m2/repository/com/patternknife/securityhelper/oauth2/spring-security-oauth2-password-jpa-implementation'
2+
local_maven_repo='/mnt/c/Users/Andrew\sKang/.m2/repository/com/patternhelloworld/securityhelper/oauth2/spring-oauth2-easyplus'
33
mvn -DaltDeploymentRepository=snapshot-repo::default::file://${local_maven_repo}/snapshots clean deploy
44

client/pom.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
http://maven.apache.org/xsd/maven-4.0.0.xsd">
66

77
<modelVersion>4.0.0</modelVersion>
8-
<groupId>com.patternknife.securityhelper.oauth2.client</groupId>
9-
<artifactId>spring-security-oauth2-password-jpa-implementation-client</artifactId>
10-
<version>3.5.0</version>
8+
<groupId>com.patternhelloworld.securityhelper.oauth2.client</groupId>
9+
<artifactId>spring-oauth2-easyplus-client</artifactId>
10+
<version>4.0.0</version>
1111
<packaging>jar</packaging>
1212

1313
<properties>
@@ -46,9 +46,9 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
4646
<dependencies>
4747

4848
<dependency>
49-
<groupId>io.github.patternknife.securityhelper.oauth2.api</groupId>
50-
<artifactId>spring-security-oauth2-password-jpa-implementation</artifactId>
51-
<version>3.5.0</version>
49+
<groupId>io.github.patternhelloworld.securityhelper.oauth2.api</groupId>
50+
<artifactId>spring-oauth2-easyplus</artifactId>
51+
<version>4.0.0</version>
5252
</dependency>
5353

5454
<!-- DB -->
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
package com.patternknife.securityhelper.oauth2.client;
2-
3-
import org.springframework.boot.SpringApplication;
4-
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
6-
import javax.annotation.PostConstruct;
7-
import java.util.TimeZone;
8-
9-
10-
@SpringBootApplication(scanBasePackages = {"com.patternknife.securityhelper.oauth2.client", "io.github.patternknife.securityhelper.oauth2.api"})
11-
public class SpringSecurityOauth2PasswordJpaImplApplication {
12-
13-
@PostConstruct
14-
void init() {
15-
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
16-
}
17-
18-
public static void main(String[] args) {
19-
SpringApplication.run(SpringSecurityOauth2PasswordJpaImplApplication.class, args);
20-
}
21-
22-
}
1+
package com.patternhelloworld.securityhelper.oauth2.client;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
import javax.annotation.PostConstruct;
7+
import java.util.TimeZone;
8+
9+
10+
@SpringBootApplication(scanBasePackages = {"com.patternhelloworld.securityhelper.oauth2.client", "io.github.patternhelloworld.securityhelper.oauth2.api"})
11+
public class SpringSecurityOauth2PasswordJpaImplApplication {
12+
13+
@PostConstruct
14+
void init() {
15+
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
16+
}
17+
18+
public static void main(String[] args) {
19+
SpringApplication.run(SpringSecurityOauth2PasswordJpaImplApplication.class, args);
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.database;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.database;
22

33
import com.zaxxer.hikari.HikariDataSource;
44
import jakarta.persistence.EntityManagerFactory;
@@ -20,24 +20,24 @@
2020

2121
@Configuration
2222
@EnableJpaRepositories(
23-
basePackages = {"com.patternknife.securityhelper.oauth2.client.domain",
24-
"com.patternknife.securityhelper.oauth2.client.config.securityimpl",
25-
"io.github.patternknife.securityhelper.oauth2.api.config.security"},
23+
basePackages = {"com.patternhelloworld.securityhelper.oauth2.client.domain",
24+
"com.patternhelloworld.securityhelper.oauth2.client.config.securityimpl",
25+
"io.github.patternhelloworld.securityhelper.oauth2.api.config.security"},
2626
entityManagerFactoryRef = "commonEntityManagerFactory",
2727
transactionManagerRef= "commonTransactionManager"
2828
)
2929
public class CommonDataSourceConfiguration {
3030

3131
@Bean
3232
@Primary
33-
@ConfigurationProperties("spring.datasource.hikari.patternknife")
33+
@ConfigurationProperties("spring.datasource.hikari.patternhelloworld")
3434
public DataSourceProperties commonDataSourceProperties() {
3535
return new DataSourceProperties();
3636
}
3737

3838
@Bean(name="commonDataSource")
3939
@Primary
40-
@ConfigurationProperties("spring.datasource.hikari.patternknife.configuration")
40+
@ConfigurationProperties("spring.datasource.hikari.patternhelloworld.configuration")
4141
public DataSource commonDataSource() {
4242
return new LazyConnectionDataSourceProxy(commonDataSourceProperties().initializeDataSourceBuilder()
4343
.type(HikariDataSource.class).build());
@@ -48,8 +48,8 @@ public DataSource commonDataSource() {
4848
public LocalContainerEntityManagerFactoryBean commonEntityManagerFactory(EntityManagerFactoryBuilder builder) {
4949
return builder
5050
.dataSource(commonDataSource())
51-
.packages("com.patternknife.securityhelper.oauth2.client.domain",
52-
"io.github.patternknife.securityhelper.oauth2.api.config.security")
51+
.packages("com.patternhelloworld.securityhelper.oauth2.client.domain",
52+
"io.github.patternhelloworld.securityhelper.oauth2.api.config.security")
5353
.persistenceUnit("commonEntityManager")
5454
.build();
5555
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.database;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.database;
22

33
import jakarta.persistence.EntityManager;
44
import jakarta.persistence.PersistenceContext;

client/src/main/java/com/patternknife/securityhelper/oauth2/client/config/database/QueryDslConfig.java renamed to client/src/main/java/com/patternhelloworld/securityhelper/oauth2/client/config/database/QueryDslConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.database;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.database;
22

33

44
import com.querydsl.jpa.impl.JPAQueryFactory;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.database;
2+
3+
public enum SelectablePersistenceConst {
4+
5+
MYSQL_8("dialect.database.config.com.patternhelloworld.securityhelper.oauth2.client.CustomMySQL8Dialect"),
6+
MSSQL("dialect.database.config.com.patternhelloworld.securityhelper.oauth2.client.CustomSQLServerDialect");
7+
8+
private final String value;
9+
10+
SelectablePersistenceConst(String value) {
11+
this.value = value;
12+
}
13+
14+
public String getValue() {
15+
return value;
16+
}
17+
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.database.dialect;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.database.dialect;
22

33

44
import org.hibernate.boot.model.FunctionContributions;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.database.dialect;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.database.dialect;
22

33

44
import org.hibernate.boot.model.FunctionContributions;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.logger.common;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.logger.common;
22

33
import jakarta.servlet.http.HttpServletRequest;
44
import org.springframework.security.core.Authentication;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.logger.module;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.logger.module;
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.slf4j.Logger;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.logger.module;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.logger.module;
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.slf4j.Logger;
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.logger.module;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.logger.module;
22

3-
import com.patternknife.securityhelper.oauth2.client.config.response.error.GlobalExceptionHandler;
4-
import com.patternknife.securityhelper.oauth2.client.config.logger.common.CommonLoggingRequest;
3+
import com.patternhelloworld.securityhelper.oauth2.client.config.response.error.GlobalExceptionHandler;
4+
import com.patternhelloworld.securityhelper.oauth2.client.config.logger.common.CommonLoggingRequest;
55

66

7-
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.dto.SecurityKnifeErrorResponsePayload;
7+
import io.github.patternhelloworld.securityhelper.oauth2.api.config.security.response.error.dto.SecurityEasyPlusErrorResponsePayload;
88
import org.aspectj.lang.JoinPoint;
99
import org.aspectj.lang.annotation.AfterReturning;
1010
import org.aspectj.lang.annotation.Aspect;
@@ -21,7 +21,7 @@ public class ResponseErrorLogConfig {
2121
private static final Logger logger = LoggerFactory.getLogger(ResponseErrorLogConfig.class);
2222

2323

24-
@AfterReturning(pointcut = ("within(com.patternknife.securityhelper.oauth2.client.config.response.error..*) || within(io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.handler..*)"),
24+
@AfterReturning(pointcut = ("within(com.patternhelloworld.securityhelper.oauth2.client.config.response.error..*) || within(io.github.patternhelloworld.securityhelper.oauth2.api.config.security.response.error.handler..*)"),
2525
returning = "returnValue")
2626
public void endpointAfterExceptionReturning(JoinPoint p, Object returnValue) {
2727

@@ -31,7 +31,7 @@ public void endpointAfterExceptionReturning(JoinPoint p, Object returnValue) {
3131
try {
3232
if (p.getTarget().getClass().equals(GlobalExceptionHandler.class)) {
3333

34-
SecurityKnifeErrorResponsePayload errorResponsePayload = (SecurityKnifeErrorResponsePayload) ((ResponseEntity) returnValue).getBody();
34+
SecurityEasyPlusErrorResponsePayload errorResponsePayload = (SecurityEasyPlusErrorResponsePayload) ((ResponseEntity) returnValue).getBody();
3535
loggedText += String.format("[After - Error Response]\n message : %s || \n userMessage : %s || \n cause : %s || \n stackTrace : %s",
3636
errorResponsePayload != null ? errorResponsePayload.getMessage() : "No error message",
3737
errorResponsePayload != null ? errorResponsePayload.getUserMessage() : "No error userMessage",
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.patternknife.securityhelper.oauth2.client.config.logger.module;
1+
package com.patternhelloworld.securityhelper.oauth2.client.config.logger.module;
22

3-
import com.patternknife.securityhelper.oauth2.client.config.logger.common.CommonLoggingRequest;
3+
import com.patternhelloworld.securityhelper.oauth2.client.config.logger.common.CommonLoggingRequest;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
66
import org.aspectj.lang.JoinPoint;
@@ -20,7 +20,7 @@ public class ResponseSuccessLogConfig {
2020
private static final Logger logger = LoggerFactory.getLogger(ResponseSuccessLogConfig.class);
2121

2222

23-
@AfterReturning(pointcut = ("within(com.patternknife.securityhelper.oauth2.client.domain..api..*)"),
23+
@AfterReturning(pointcut = ("within(com.patternhelloworld.securityhelper.oauth2.client.domain..api..*)"),
2424
returning = "returnValue")
2525
public void endpointAfterReturning(JoinPoint p, Object returnValue) {
2626

0 commit comments

Comments
 (0)