修改路径

This commit is contained in:
朱毅骏 2022-08-24 13:59:57 +08:00
parent ae73499e6c
commit 6c8bfc651b
29 changed files with 217 additions and 52 deletions

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<version>2.6.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cn.zyjblogs</groupId>
@ -18,6 +18,7 @@
<module>zyjblogs-rbac</module>
<module>zyjblogs-gateway</module>
<module>zyjblogs-common-spring-boot-starter</module>
<module>zyjblogs-web-spring-boot-starter</module>
</modules>
<properties>

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.constant;
package cn.zyjblogs.starter.common.entity.constant;
public class CommonConstant {
public static final Integer IS_DELETED = 1;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.constant;
package cn.zyjblogs.starter.common.entity.constant;
public class HttpHeaderConstant {
public static final String AUTHORIZATION = "Authorization";

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.constant;
package cn.zyjblogs.starter.common.entity.constant;
public class LengthConstant {
public static final int ID_SIZE = 32;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.constant;
package cn.zyjblogs.starter.common.entity.constant;
public class RegexConstant {
public static final String MOBILE_PHONE_PATTERN = "[\\s]?|^1[3456789]\\d{9}$";

View File

@ -1,7 +1,7 @@
package cn.zyjblogs.common.entity.context;
package cn.zyjblogs.starter.common.entity.context;
import cn.zyjblogs.common.entity.dto.ContextDto;
import cn.zyjblogs.common.utils.bean.BeanUtils;
import cn.zyjblogs.starter.common.entity.dto.ContextDto;
import cn.zyjblogs.starter.common.utils.bean.BeanUtils;
import com.alibaba.ttl.TransmittableThreadLocal;
import java.util.Locale;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.dto;
package cn.zyjblogs.starter.common.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.jwt;
package cn.zyjblogs.starter.common.entity.jwt;
import io.jsonwebtoken.impl.DefaultClaims;

View File

@ -3,7 +3,7 @@
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.common.entity.response;
package cn.zyjblogs.starter.common.entity.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -3,7 +3,7 @@
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.common.entity.response;
package cn.zyjblogs.starter.common.entity.response;
public class ResponseResult {
private static final int ZERO_DATA_TOTAL = 0;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.entity.response;
package cn.zyjblogs.starter.common.entity.response;
public enum ResponseStatus {
CONTINUE(100, "Continue"),

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.exception;
package cn.zyjblogs.starter.common.exception;
public abstract class AbstractFrameworkException extends RuntimeException {
public AbstractFrameworkException(String message) {

View File

@ -1,13 +1,12 @@
package cn.zyjblogs.common.utils.bean;
package cn.zyjblogs.starter.common.utils.bean;
import cn.zyjblogs.common.utils.jackson.JacksonHolder;
import cn.zyjblogs.common.utils.jackson.exception.JsonConvertException;
import cn.zyjblogs.starter.common.utils.jackson.JacksonHolder;
import cn.zyjblogs.starter.common.utils.jackson.exception.JsonConvertException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;

View File

@ -3,7 +3,7 @@
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.common.utils.crypto;
package cn.zyjblogs.starter.common.utils.crypto;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

View File

@ -3,7 +3,7 @@
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.common.utils.crypto;
package cn.zyjblogs.starter.common.utils.crypto;
import java.nio.charset.StandardCharsets;
import java.security.Security;

View File

@ -3,7 +3,7 @@
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.common.utils.crypto;
package cn.zyjblogs.starter.common.utils.crypto;
import java.nio.charset.StandardCharsets;
import java.security.AlgorithmParameters;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.utils.jackson;
package cn.zyjblogs.starter.common.utils.jackson;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;

View File

@ -1,7 +1,7 @@
package cn.zyjblogs.common.utils.jackson;
package cn.zyjblogs.starter.common.utils.jackson;
import cn.zyjblogs.common.utils.jackson.exception.JsonConvertException;
import cn.zyjblogs.starter.common.utils.jackson.exception.JsonConvertException;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;

View File

@ -1,6 +1,6 @@
package cn.zyjblogs.common.utils.jackson.exception;
package cn.zyjblogs.starter.common.utils.jackson.exception;
import cn.zyjblogs.common.exception.AbstractFrameworkException;
import cn.zyjblogs.starter.common.exception.AbstractFrameworkException;
public class JsonConvertException extends AbstractFrameworkException {
public JsonConvertException(String msg) {

View File

@ -3,7 +3,7 @@
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.common.utils.jwt;
package cn.zyjblogs.starter.common.utils.jwt;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Clock;

View File

@ -1,4 +1,4 @@
package cn.zyjblogs.common.utils.rsa;
package cn.zyjblogs.starter.common.utils.rsa;
import java.io.File;
import java.io.IOException;

View File

@ -16,11 +16,6 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!-- Spring 集成 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
@ -74,8 +69,11 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -1,17 +1,11 @@
package cn.zyjblogs.gateway.filter;
import cn.zyjblogs.common.entity.constant.HttpHeaderConstant;
import cn.zyjblogs.common.entity.context.BaseContextHandler;
import cn.zyjblogs.common.entity.dto.ContextDto;
import cn.zyjblogs.common.entity.jwt.OauthClaims;
import cn.zyjblogs.common.entity.response.ResponseObject;
import cn.zyjblogs.common.entity.response.ResponseResult;
import cn.zyjblogs.common.entity.response.ResponseStatus;
import cn.zyjblogs.starter.common.entity.constant.HttpHeaderConstant;
import cn.zyjblogs.starter.common.entity.response.ResponseObject;
import cn.zyjblogs.starter.common.entity.response.ResponseResult;
import cn.zyjblogs.starter.common.entity.response.ResponseStatus;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.Jwts;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

View File

@ -1,6 +1,6 @@
package cn.zyjblogs.oauth.config.security;
import cn.zyjblogs.common.entity.constant.ContextKeyConstant;
import cn.zyjblogs.starter.common.entity.constant.ContextKeyConstant;
import cn.zyjblogs.oauth.server.user.po.OauthUserDetails;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;

View File

@ -3,6 +3,7 @@ package cn.zyjblogs.oauth.config.security;
import cn.zyjblogs.oauth.server.user.po.OauthUserDetails;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
@ -12,6 +13,7 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
@ -39,16 +41,22 @@ public class OauthAuthenticationProvider extends DaoAuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
if (authentication.getCredentials() == null){
this.logger.debug("密码为空");
throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
}
String password = (String) authentication.getCredentials();
//获取用户信息
UserDetails user = userDetailsService.loadUserByUsername(username);
if (user == null){
return null;
this.logger.debug("用户不存在");
throw new UsernameNotFoundException("用户不存在");
}
OauthUserDetails userDetails = (OauthUserDetails) user;
//比较前端传入的密码明文和数据库中加密的密码是否相等
if (!passwordEncoder.matches(password, userDetails.getPassword())) {
throw new DisabledException("用户密码不正确");
this.logger.debug("密码不正确");
throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
}
//获取用户权限信息
Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities();

View File

@ -1,13 +1,11 @@
package cn.zyjblogs.oauth.config.security;
import cn.zyjblogs.common.entity.constant.ContextKeyConstant;
import cn.zyjblogs.common.utils.bean.BeanUtils;
import cn.zyjblogs.starter.common.entity.constant.ContextKeyConstant;
import cn.zyjblogs.oauth.server.user.po.OauthUserDetails;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter;
import org.springframework.stereotype.Component;

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>zyjblogs-parent</artifactId>
<groupId>cn.zyjblogs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>zyjblogs-web-spring-boot-starter</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!-- Spring 集成 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,110 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package cn.zyjblogs.starter.web.config;
import com.google.common.collect.Lists;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
import java.lang.reflect.Field;
import java.util.List;
import java.util.stream.Collectors;
@EnableOpenApi
@Configuration
@Import({BeanValidatorPluginsConfiguration.class})
public class Knife4jAutoConfigurationConfig {
@Value("${spring.application.name}")
private String applicationName;
public Knife4jAutoConfigurationConfig() {
}
@Bean
public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
return new BeanPostProcessor() {
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
this.customizeSpringfoxHandlerMappings(this.getHandlerMappings(bean));
}
return bean;
}
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
List<T> copy = (List)mappings.stream().filter((mapping) -> mapping.getPatternParser() == null).collect(Collectors.toList());
mappings.clear();
mappings.addAll(copy);
}
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
try {
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
field.setAccessible(true);
return (List)field.get(bean);
} catch (IllegalAccessException | IllegalArgumentException var3) {
throw new IllegalStateException(var3);
}
}
};
}
@Bean({"defaultApi"})
public Docket defaultApi() {
return (new Docket(DocumentationType.SWAGGER_2)).directModelSubstitute(LocalDateTime.class, Date.class).directModelSubstitute(LocalDate.class, String.class).directModelSubstitute(LocalTime.class, String.class).directModelSubstitute(ZonedDateTime.class, String.class).apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.basePackage("cn.zyjblogs")).paths(PathSelectors.any()).build().securityContexts(Lists.newArrayList(new SecurityContext[]{this.securityContext(), this.securityContext()})).securitySchemes(Lists.newArrayList(new SecurityScheme[]{this.apiKey()}));
}
private ApiInfo apiInfo() {
return (new ApiInfoBuilder()).title(this.applicationName.toUpperCase() + " RESTFUL APIS").contact(new Contact("zyjblogs", "", "")).version("1.0.0").build();
}
private ApiKey apiKey() {
return new ApiKey("BearerToken", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(this.defaultAuth()).forPaths(PathSelectors.regex("/.*")).build();
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[]{authorizationScope};
return Lists.newArrayList(new SecurityReference[]{new SecurityReference("BearerToken", authorizationScopes)});
}
}