diff --git a/simple-jwt-spring-boot-starter/pom.xml b/simple-jwt-spring-boot-starter/pom.xml new file mode 100644 index 0000000..a4f73a8 --- /dev/null +++ b/simple-jwt-spring-boot-starter/pom.xml @@ -0,0 +1,71 @@ + + + + + 4.0.0 + + cn.org.codecrafters + jdevkit + 1.0.0 + + + simple-jwt-spring-boot-starter + + + 17 + 17 + UTF-8 + + + + + cn.org.codecrafters + simple-jwt-facade + + + + cn.org.codecrafters + simple-jwt-authzero + provided + + + + org.springframework.boot + spring-boot-autoconfigure + + + + org.springframework.boot + spring-boot-starter-logging + + + + org.springframework.boot + spring-boot-configuration-processor + + + + org.springframework.boot + spring-boot-starter-test + test + + + + \ No newline at end of file diff --git a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/SimpleJwtAutoConfiguration.java b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/SimpleJwtAutoConfiguration.java new file mode 100644 index 0000000..88a0d23 --- /dev/null +++ b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/SimpleJwtAutoConfiguration.java @@ -0,0 +1,76 @@ +/* + * 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 cn.org.codecrafters.devkit.guid.GuidCreator; +import cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver; +import cn.org.codecrafters.simplejwt.properties.SimpleJwtProperties; +import com.auth0.jwt.interfaces.DecodedJWT; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.UUID; + +/** + * SimpleJwtAutoConfiguration + * + * @author Zihlu Wang + */ +@Slf4j +@Configuration +@EnableConfigurationProperties(value = {SimpleJwtProperties.class}) +public class SimpleJwtAutoConfiguration { + + private GuidCreator jtiCreator; + + @Autowired + public void setJtiCreator(GuidCreator jtiCreator) { + this.jtiCreator = jtiCreator; + } + + private final SimpleJwtProperties simpleJwtProperties; + + @Autowired + public SimpleJwtAutoConfiguration(SimpleJwtProperties simpleJwtProperties) { + this.simpleJwtProperties = simpleJwtProperties; + } + + @Bean + @ConditionalOnMissingBean(value = GuidCreator.class, name = "jtiCreator") + public GuidCreator jtiCreator() { + return (GuidCreator) UUID::randomUUID; + } + + @Bean + @ConditionalOnClass({DecodedJWT.class, AuthzeroTokenResolver.class}) + @ConditionalOnMissingBean({TokenResolver.class}) + @ConditionalOnBean(value = {GuidCreator.class}, name = "jtiCreator") + public TokenResolver tokenResolver() { + return new AuthzeroTokenResolver(this.jtiCreator, + simpleJwtProperties.algorithm(), + simpleJwtProperties.issuer(), + simpleJwtProperties.secret()); + } + +} diff --git a/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/properties/SimpleJwtProperties.java b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/properties/SimpleJwtProperties.java new file mode 100644 index 0000000..34d7d66 --- /dev/null +++ b/simple-jwt-spring-boot-starter/src/main/java/cn/org/codecrafters/simplejwt/properties/SimpleJwtProperties.java @@ -0,0 +1,53 @@ +/* + * 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.properties; + +import cn.org.codecrafters.devkit.guid.GuidCreator; +import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm; +import lombok.Data; +import lombok.Getter; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * SimpleJwtProperties + * + * @author Zihlu Wang + */ +@Data +@ConfigurationProperties(prefix = "code-crafters.simple-jwt") +public class SimpleJwtProperties { + + private TokenAlgorithm algorithm; + + private String issuer; + + private String secret; + + public final TokenAlgorithm algorithm() { + return algorithm; + } + + public final String issuer() { + return issuer; + } + + public final String secret() { + return secret; + } + +} diff --git a/simple-jwt-spring-boot-starter/src/main/resources/META-INF/springvorbote-webdev-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/simple-jwt-spring-boot-starter/src/main/resources/META-INF/springvorbote-webdev-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..7a213b1 --- /dev/null +++ b/simple-jwt-spring-boot-starter/src/main/resources/META-INF/springvorbote-webdev-spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +cn.org.codecrafters.simplejwt.SimpleJwtAutoConfiguration \ No newline at end of file diff --git a/simple-jwt-spring-boot-starter/src/main/resources/logback.xml b/simple-jwt-spring-boot-starter/src/main/resources/logback.xml new file mode 100644 index 0000000..af1c7a3 --- /dev/null +++ b/simple-jwt-spring-boot-starter/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 diff --git a/sms-sender-facade/pom.xml b/sms-sender-facade/pom.xml new file mode 100644 index 0000000..0707250 --- /dev/null +++ b/sms-sender-facade/pom.xml @@ -0,0 +1,44 @@ + + + + + 4.0.0 + + cn.org.codecrafters + jdevkit + 1.0.0 + + + sms-sender-facade + + + 17 + 17 + UTF-8 + + + + + cn.org.codecrafters + devkit-core + + + + \ No newline at end of file