docs: Fix all docs from one <p> represents for a paragraph

This commit is contained in:
Zihlu Wang
2023-07-31 21:43:09 +08:00
parent 373fbf9083
commit 715ae6db3a
28 changed files with 627 additions and 133 deletions
@@ -15,11 +15,12 @@
* limitations under the License.
*/
package cn.org.codecrafters.simplejwt;
package cn.org.codecrafters.simplejwt.autoconfiguration;
import cn.org.codecrafters.devkit.guid.GuidCreator;
import cn.org.codecrafters.guid.GuidCreator;
import cn.org.codecrafters.simplejwt.TokenResolver;
import cn.org.codecrafters.simplejwt.authzero.AuthzeroTokenResolver;
import cn.org.codecrafters.simplejwt.properties.SimpleJwtProperties;
import cn.org.codecrafters.simplejwt.autoconfiguration.properties.SimpleJwtProperties;
import com.auth0.jwt.interfaces.DecodedJWT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,35 +34,91 @@ import org.springframework.context.annotation.Configuration;
import java.util.UUID;
/**
* SimpleJwtAutoConfiguration
* <p>
* SimpleJwtAutoConfiguration is responsible for automatically configuring the
* Simple JWT library when used in a Spring Boot application. It provides
* default settings and configurations to ensure that the library works
* smoothly without requiring manual configuration.
* </p>
*
* <p>
* This auto-configuration class sets up the necessary beans and components
* required for JWT generation and validation. It automatically creates and
* configures the {@link TokenResolver} bean based on the available options and
* properties.
* </p>
*
* <p>
* Developers using the Simple JWT library with Spring Boot do not need to
* explicitly configure the library, as the auto-configuration takes care of
* setting up the necessary components and configurations automatically.
* However, developers still have the flexibility to customize the behavior of
* the library by providing their own configurations and properties.
* </p>
*
* @author Zihlu Wang
* @version 1.0.0
* @since 1.0.0
*/
@Slf4j
@Configuration
@EnableConfigurationProperties(value = {SimpleJwtProperties.class})
public class SimpleJwtAutoConfiguration {
/**
* The GuidCreator instance to be used for generating JWT IDs (JTI).
*/
private GuidCreator<?> jtiCreator;
/**
* Sets the GuidCreator instance to be used for generating JWT IDs (JTI).
*
* @param jtiCreator the {@code GuidCreator} instance
*/
@Autowired
public void setJtiCreator(GuidCreator<?> jtiCreator) {
this.jtiCreator = jtiCreator;
}
/**
* The {@code SimpleJwtProperties} instance containing the configuration
* properties for Simple JWT.
*/
private final SimpleJwtProperties simpleJwtProperties;
/**
* Constructs a new {@code SimpleJwtAutoConfiguration} instance with the
* provided SimpleJwtProperties.
*
* @param simpleJwtProperties the SimpleJwtProperties instance
*/
@Autowired
public SimpleJwtAutoConfiguration(SimpleJwtProperties simpleJwtProperties) {
this.simpleJwtProperties = simpleJwtProperties;
}
/**
* Creates a new {@code GuidCreator} bean if no existing bean with the name
* "jtiCreator" is found. The created {@code GuidCreator} is used for
* generating JWT IDs (JTI).
*
* @return the GuidCreator instance
*/
@Bean
@ConditionalOnMissingBean(value = GuidCreator.class, name = "jtiCreator")
public GuidCreator<?> jtiCreator() {
return (GuidCreator<UUID>) UUID::randomUUID;
}
/**
* Creates a new {@link TokenResolver} bean using {@link
* AuthzeroTokenResolver} if no existing {@link TokenResolver} bean is
* found. The {@link AuthzeroTokenResolver} is configured with the
* provided {@link GuidCreator}, {@code algorithm}, {@code issuer}, and
* {@code secret} properties from {@link SimpleJwtProperties}.
*
* @return the {@link TokenResolver} instance
*/
@Bean
@ConditionalOnClass({DecodedJWT.class, AuthzeroTokenResolver.class})
@ConditionalOnMissingBean({TokenResolver.class})
@@ -0,0 +1,38 @@
/*
* 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.
*/
/**
* <p>
* The classes in this package are responsible for automatically configuring
* the Simple JWT library when it is used in a Spring Boot application. They
* provide default settings and configurations to ensure that the library works
* smoothly and seamlessly without requiring developers to manually configure
* it.
* </p>
*
* <p>
* Developers using the Simple JWT library with Spring Boot do not need to
* explicitly configure the library, as the auto-configuration classes take
* care of setting up the necessary components and configurations
* automatically. However, developers still have the flexibility to customize
* the behavior of the library by providing their own configurations and
* properties.
* </p>
*
* @since 1.0.0
*/
package cn.org.codecrafters.simplejwt.autoconfiguration;
@@ -0,0 +1,96 @@
/*
* 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.autoconfiguration.properties;
import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* <p>
* {@code SimpleJwtProperties} is a configuration properties class used to
* store the properties related to Simple JWT library configuration. These
* properties can be configured in the application's properties file (e.g.,
* application.properties) with the prefix "code-crafters.simple-jwt".
* </p>
*
* <p>
* SimpleJwtProperties provides configuration options for the JWT algorithm,
* issuer, and secret. The properties are used by the {@link
* cn.org.codecrafters.simplejwt.autoconfiguration.SimpleJwtAutoConfiguration}
* class to set up the necessary configurations for JWT generation and
* validation.
* </p>
*
* <p>
* Developers can customize the JWT algorithm, issuer, and secret by setting
* the corresponding properties in the application's properties file. The
* SimpleJwtAutoConfiguration class reads these properties and uses them to
* create the TokenResolver bean with the desired configuration.
* </p>
*
* @since 1.0.0
*/
@Data
@ConfigurationProperties(prefix = "code-crafters.simple-jwt")
public class SimpleJwtProperties {
/**
* The algorithm used for JWT generation and validation.
*/
private TokenAlgorithm algorithm;
/**
* The issuer value to be included in the generated JWT.
*/
private String issuer;
/**
* The secret key used for JWT generation and validation.
*/
private String secret;
/**
* Returns the JWT algorithm configured in the properties.
*
* @return the JWT algorithm
*/
public final TokenAlgorithm algorithm() {
return algorithm;
}
/**
* Returns the issuer value configured in the properties.
*
* @return the issuer value
*/
public final String issuer() {
return issuer;
}
/**
* Returns the secret key configured in the properties.
*
* @return the secret key
*/
public final String secret() {
return secret;
}
}
@@ -0,0 +1,39 @@
/*
* 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.
*/
/**
* <p>
* The "cn.org.codecrafters.simplejwt.autoconfiguration.properties" package
* contains configuration properties classes used for Simple JWT library
* auto-configuration. These classes define the properties that can be
* configured in the application's properties file (e.g.,
* application.properties) to customize the behavior and settings of the Simple
* JWT library.
* </p>
*
* <p>
* Developers can customize the JWT algorithm, issuer, and secret by setting
* the corresponding properties in the application's properties file with the
* prefix "code-crafters.simple-jwt". The SimpleJwtAutoConfiguration class
* reads these properties and uses them to create the {@link
* cn.org.codecrafters.simplejwt.TokenResolver} bean with the desired
* configuration.
* </p>
*
* @since 1.0.0
*/
package cn.org.codecrafters.simplejwt.autoconfiguration.properties;
@@ -1,53 +0,0 @@
/*
* 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;
}
}