From a2f23131426f71ac0f1759f329f12e232887f098 Mon Sep 17 00:00:00 2001 From: Zihlu Wang Date: Sat, 29 Jul 2023 23:57:54 +0800 Subject: [PATCH] feat(simple-jwt-facade): finished the design of simple-jwt-facade --- pom.xml | 1 + simple-jwt-facade/pom.xml | 37 +++++++++++++ .../codecrafters/simplejwt/ResolvedToken.java | 35 ++++++++++++ .../codecrafters/simplejwt/TokenPayload.java | 27 +++++++++ .../codecrafters/simplejwt/TokenResolver.java | 55 +++++++++++++++++++ .../src/main/resources/logback.xml | 38 +++++++++++++ 6 files changed, 193 insertions(+) create mode 100644 simple-jwt-facade/pom.xml create mode 100644 simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java create mode 100644 simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java create mode 100644 simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java create mode 100644 simple-jwt-facade/src/main/resources/logback.xml diff --git a/pom.xml b/pom.xml index 73ae3e6..c68428c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ guid dev-utils devkit-core + simple-jwt-facade diff --git a/simple-jwt-facade/pom.xml b/simple-jwt-facade/pom.xml new file mode 100644 index 0000000..ea5ce9a --- /dev/null +++ b/simple-jwt-facade/pom.xml @@ -0,0 +1,37 @@ + + + + + 4.0.0 + + cn.org.codecrafters + jdevkit + 1.0.0 + + + simple-jwt-facade + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java new file mode 100644 index 0000000..8918a6e --- /dev/null +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/ResolvedToken.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2023 CodeCraftersCN. + * + * 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 cn.org.codecrafters.simplejwt; + +/** + * ResolvedToken + * + * @author Zihlu Wang + * @since 29 Jul 2023 + */ +public record ResolvedToken(T resolvedToken) { + + public ResolvedToken { + } + + public static ResolvedToken init(T resolvedToken) { + return new ResolvedToken<>(resolvedToken); + } + +} diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java new file mode 100644 index 0000000..73a36eb --- /dev/null +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenPayload.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2023 CodeCraftersCN. + * + * 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 cn.org.codecrafters.simplejwt; + +/** + * PayloadObject + * + * @author Zihlu Wang + * @since 29 Jul 2023 + */ +public interface TokenPayload { +} diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java new file mode 100644 index 0000000..e1fce6a --- /dev/null +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2023 CodeCraftersCN. + * + * 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 cn.org.codecrafters.simplejwt; + +import java.time.Duration; +import java.util.Map; + +/** + * TokenResolver + * + * @author Zihlu Wang + * @since 29 Jul 2023 + */ +public interface TokenResolver { + + String createToken(Duration expireAfter, String audience); + + String createToken(Duration expireAfter, String audience, Map payloads); + + String createToken(Duration expireAfter, String audience, T payloads); + + String createToken(Duration expireAfter, String subject, String audience); + + String createToken(Duration expireAfter, String subject, String audience, Map payloads); + + String createToken(Duration expireAfter, String subject, String audience, T payloads); + + Map extract(String token); + + T extract(String token, Class targetType); + + String renew(String oldToken); + + String renew(String oldToken, Map payloads); + + String renew(String oldToken, T payloads); + + ResolvedToken resolve(String token); + +} diff --git a/simple-jwt-facade/src/main/resources/logback.xml b/simple-jwt-facade/src/main/resources/logback.xml new file mode 100644 index 0000000..af1c7a3 --- /dev/null +++ b/simple-jwt-facade/src/main/resources/logback.xml @@ -0,0 +1,38 @@ + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} : %msg%n + + + + + + %date{yyyy-MM-dd HH:mm:ss} [%thread] %highlight(%-5level) %cyan(%logger{50}) : %msg%n + + + + + + + \ No newline at end of file