-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from wwan13/feature/jwt
scan payload
- Loading branch information
Showing
27 changed files
with
254 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.13' | ||
id 'io.spring.dependency-management' version '1.1.4' | ||
id 'java' | ||
id 'org.springframework.boot' version '2.7.13' | ||
id 'io.spring.dependency-management' version '1.1.4' | ||
} | ||
|
||
group = 'io.wwan13' | ||
version = '0.0.1' | ||
|
||
java { | ||
sourceCompatibility = '17' | ||
sourceCompatibility = '17' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
// spring | ||
implementation 'org.springframework.boot:spring-boot-starter' | ||
// spring | ||
implementation 'org.springframework.boot:spring-boot-starter' | ||
|
||
// web | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
// web | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
// jwt | ||
implementation 'io.jsonwebtoken:jjwt-api:0.11.5' | ||
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' | ||
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' | ||
// jwt | ||
implementation 'io.jsonwebtoken:jjwt-api:0.11.5' | ||
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' | ||
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' | ||
|
||
// password encoder | ||
implementation 'org.springframework.security:spring-security-crypto:6.1.0' | ||
// password encoder | ||
implementation 'org.springframework.security:spring-security-crypto:6.1.0' | ||
|
||
// test | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
// reflections api | ||
implementation 'org.reflections:reflections:0.9.10' | ||
|
||
// test | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/io/wwan13/wintersecurity/jwt/payload/annotation/Payload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.wwan13.wintersecurity.jwt.payload.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Payload { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/io/wwan13/wintersecurity/jwt/payload/support/ReflectionPayloadScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.wwan13.wintersecurity.jwt.payload.support; | ||
|
||
import io.wwan13.wintersecurity.jwt.PayloadScanner; | ||
import io.wwan13.wintersecurity.jwt.payload.DefaultPayload; | ||
import io.wwan13.wintersecurity.jwt.payload.annotation.Payload; | ||
import org.reflections.Reflections; | ||
import org.reflections.scanners.SubTypesScanner; | ||
import org.reflections.scanners.TypeAnnotationsScanner; | ||
|
||
import java.util.Set; | ||
|
||
public class ReflectionPayloadScanner implements PayloadScanner { | ||
|
||
private static final String DEFAULT_SCAN_BASE_PACKAGE = ""; | ||
|
||
@Override | ||
public Class<?> scan() { | ||
Reflections reflections = new Reflections( | ||
DEFAULT_SCAN_BASE_PACKAGE, | ||
new TypeAnnotationsScanner(), | ||
new SubTypesScanner() | ||
); | ||
|
||
Set<Class<?>> payloads = reflections.getTypesAnnotatedWith(Payload.class); | ||
validateMoreThanTwo(payloads); | ||
|
||
return payloads.stream() | ||
.findFirst() | ||
.orElse(DefaultPayload.class); | ||
} | ||
|
||
public void validateMoreThanTwo(Set<Class<?>> payloads) { | ||
if (payloads.size() > 1) { | ||
throw new IllegalStateException("Must be only one payload."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.