فهرست منبع

2021/6/10 16:23 删除测试文件

yinhao 4 سال پیش
والد
کامیت
f688df5d0a
64فایلهای تغییر یافته به همراه0 افزوده شده و 2379 حذف شده
  1. 0 15
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/Oauth2AuthApplication.java
  2. 0 124
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/api/CommonResult.java
  3. 0 11
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/api/IErrorCode.java
  4. 0 28
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/api/ResultCode.java
  5. 0 28
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/component/JwtTokenEnhancer.java
  6. 0 82
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/config/Oauth2ServerConfig.java
  7. 0 33
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/config/RedisRepositoryConfig.java
  8. 0 40
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/config/WebSecurityConfig.java
  9. 0 23
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/constant/MessageConstant.java
  10. 0 11
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/constant/RedisConstant.java
  11. 0 42
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/controller/AuthController.java
  12. 0 30
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/controller/KeyPairController.java
  13. 0 31
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/domain/Oauth2TokenDto.java
  14. 0 89
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/domain/SecurityUser.java
  15. 0 22
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/domain/UserDTO.java
  16. 0 20
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/exception/Oauth2ExceptionHandler.java
  17. 0 32
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/service/ResourceServiceImpl.java
  18. 0 61
      huimv-smart-oauth2/src/main/java/com/huimv/oauth2/service/UserServiceImpl.java
  19. 0 0
      huimv-smart-oauth2/src/main/resources/application.yml
  20. 0 21
      micro-oauth2/micro-oauth2-api/pom.xml
  21. 0 15
      micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/Oauth2ApiApplication.java
  22. 0 18
      micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/controller/HelloController.java
  23. 0 26
      micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/controller/UserController.java
  24. 0 18
      micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/domain/UserDTO.java
  25. 0 31
      micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/holder/LoginUserHolder.java
  26. 0 16
      micro-oauth2/micro-oauth2-api/src/main/resources/application.yml
  27. 0 39
      micro-oauth2/micro-oauth2-auth/pom.xml
  28. 0 15
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/Oauth2AuthApplication.java
  29. 0 124
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/api/CommonResult.java
  30. 0 11
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/api/IErrorCode.java
  31. 0 28
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/api/ResultCode.java
  32. 0 28
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/component/JwtTokenEnhancer.java
  33. 0 82
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/config/Oauth2ServerConfig.java
  34. 0 33
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/config/RedisRepositoryConfig.java
  35. 0 40
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/config/WebSecurityConfig.java
  36. 0 23
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/constant/MessageConstant.java
  37. 0 11
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/constant/RedisConstant.java
  38. 0 42
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/controller/AuthController.java
  39. 0 30
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/controller/KeyPairController.java
  40. 0 31
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/domain/Oauth2TokenDto.java
  41. 0 89
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/domain/SecurityUser.java
  42. 0 22
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/domain/UserDTO.java
  43. 0 20
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/exception/Oauth2ExceptionHandler.java
  44. 0 32
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/service/ResourceServiceImpl.java
  45. 0 61
      micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/service/UserServiceImpl.java
  46. 0 23
      micro-oauth2/micro-oauth2-auth/src/main/resources/application.yml
  47. BIN
      micro-oauth2/micro-oauth2-auth/src/main/resources/jwt.jks
  48. 0 57
      micro-oauth2/micro-oauth2-gateway/pom.xml
  49. 0 15
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/Oauth2GatewayApplication.java
  50. 0 124
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/api/CommonResult.java
  51. 0 11
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/api/IErrorCode.java
  52. 0 28
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/api/ResultCode.java
  53. 0 46
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/authorization/AuthorizationManager.java
  54. 0 33
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/component/RestAuthenticationEntryPoint.java
  55. 0 34
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/component/RestfulAccessDeniedHandler.java
  56. 0 20
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/config/IgnoreUrlsConfig.java
  57. 0 33
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/config/RedisRepositoryConfig.java
  58. 0 66
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/config/ResourceServerConfig.java
  59. 0 12
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/constant/AuthConstant.java
  60. 0 10
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/constant/RedisConstant.java
  61. 0 50
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/filter/AuthGlobalFilter.java
  62. 0 42
      micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/filter/IgnoreUrlsRemoveJwtFilter.java
  63. 0 44
      micro-oauth2/micro-oauth2-gateway/src/main/resources/application.yml
  64. 0 103
      micro-oauth2/pom.xml

+ 0 - 15
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/Oauth2AuthApplication.java

@@ -1,15 +0,0 @@
-package com.huimv.oauth2;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-
-@EnableDiscoveryClient
-@SpringBootApplication
-public class Oauth2AuthApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(Oauth2AuthApplication.class, args);
-    }
-
-}

+ 0 - 124
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/api/CommonResult.java

@@ -1,124 +0,0 @@
-package com.huimv.oauth2.api;
-
-/**
- * 通用返回对象
- * Created by macro on 2019/4/19.
- */
-public class CommonResult<T> {
-    private long code;
-    private String message;
-    private T data;
-
-    protected CommonResult() {
-    }
-
-    protected CommonResult(long code, String message, T data) {
-        this.code = code;
-        this.message = message;
-        this.data = data;
-    }
-
-    /**
-     * 成功返回结果
-     *
-     * @param data 获取的数据
-     */
-    public static <T> CommonResult<T> success(T data) {
-        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
-    }
-
-    /**
-     * 成功返回结果
-     *
-     * @param data 获取的数据
-     * @param  message 提示信息
-     */
-    public static <T> CommonResult<T> success(T data, String message) {
-        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
-    }
-
-    /**
-     * 失败返回结果
-     * @param errorCode 错误码
-     */
-    public static <T> CommonResult<T> failed(IErrorCode errorCode) {
-        return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
-    }
-
-    /**
-     * 失败返回结果
-     * @param errorCode 错误码
-     * @param message 错误信息
-     */
-    public static <T> CommonResult<T> failed(IErrorCode errorCode,String message) {
-        return new CommonResult<T>(errorCode.getCode(), message, null);
-    }
-
-    /**
-     * 失败返回结果
-     * @param message 提示信息
-     */
-    public static <T> CommonResult<T> failed(String message) {
-        return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
-    }
-
-    /**
-     * 失败返回结果
-     */
-    public static <T> CommonResult<T> failed() {
-        return failed(ResultCode.FAILED);
-    }
-
-    /**
-     * 参数验证失败返回结果
-     */
-    public static <T> CommonResult<T> validateFailed() {
-        return failed(ResultCode.VALIDATE_FAILED);
-    }
-
-    /**
-     * 参数验证失败返回结果
-     * @param message 提示信息
-     */
-    public static <T> CommonResult<T> validateFailed(String message) {
-        return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
-    }
-
-    /**
-     * 未登录返回结果
-     */
-    public static <T> CommonResult<T> unauthorized(T data) {
-        return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
-    }
-
-    /**
-     * 未授权返回结果
-     */
-    public static <T> CommonResult<T> forbidden(T data) {
-        return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
-    }
-
-    public long getCode() {
-        return code;
-    }
-
-    public void setCode(long code) {
-        this.code = code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-
-    public void setMessage(String message) {
-        this.message = message;
-    }
-
-    public T getData() {
-        return data;
-    }
-
-    public void setData(T data) {
-        this.data = data;
-    }
-}

+ 0 - 11
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/api/IErrorCode.java

@@ -1,11 +0,0 @@
-package com.huimv.oauth2.api;
-
-/**
- * 封装API的错误码
- * Created by macro on 2019/4/19.
- */
-public interface IErrorCode {
-    long getCode();
-
-    String getMessage();
-}

+ 0 - 28
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/api/ResultCode.java

@@ -1,28 +0,0 @@
-package com.huimv.oauth2.api;
-
-/**
- * 枚举了一些常用API操作码
- * Created by macro on 2019/4/19.
- */
-public enum ResultCode implements IErrorCode {
-    SUCCESS(200, "操作成功"),
-    FAILED(500, "操作失败"),
-    VALIDATE_FAILED(404, "参数检验失败"),
-    UNAUTHORIZED(401, "暂未登录或token已经过期"),
-    FORBIDDEN(403, "没有相关权限");
-    private long code;
-    private String message;
-
-    private ResultCode(long code, String message) {
-        this.code = code;
-        this.message = message;
-    }
-
-    public long getCode() {
-        return code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-}

+ 0 - 28
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/component/JwtTokenEnhancer.java

@@ -1,28 +0,0 @@
-package com.huimv.oauth2.component;
-
-import com.macro.cloud.domain.SecurityUser;
-import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
-import org.springframework.security.oauth2.common.OAuth2AccessToken;
-import org.springframework.security.oauth2.provider.OAuth2Authentication;
-import org.springframework.security.oauth2.provider.token.TokenEnhancer;
-import org.springframework.stereotype.Component;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * JWT内容增强器
- * Created by macro on 2020/6/19.
- */
-@Component
-public class JwtTokenEnhancer implements TokenEnhancer {
-    @Override
-    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
-        SecurityUser securityUser = (SecurityUser) authentication.getPrincipal();
-        Map<String, Object> info = new HashMap<>();
-        //把用户ID设置到JWT中
-        info.put("id", securityUser.getId());
-        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(info);
-        return accessToken;
-    }
-}

+ 0 - 82
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/config/Oauth2ServerConfig.java

@@ -1,82 +0,0 @@
-package com.huimv.oauth2.config;
-
-import com.macro.cloud.component.JwtTokenEnhancer;
-import com.macro.cloud.service.UserServiceImpl;
-import lombok.AllArgsConstructor;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
-import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
-import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
-import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
-import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
-import org.springframework.security.oauth2.provider.token.TokenEnhancer;
-import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
-import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
-import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;
-
-import java.security.KeyPair;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 认证服务器配置
- * Created by macro on 2020/6/19.
- */
-@AllArgsConstructor
-@Configuration
-@EnableAuthorizationServer
-public class Oauth2ServerConfig extends AuthorizationServerConfigurerAdapter {
-
-    private final PasswordEncoder passwordEncoder;
-    private final UserServiceImpl userDetailsService;
-    private final AuthenticationManager authenticationManager;
-    private final JwtTokenEnhancer jwtTokenEnhancer;
-
-    @Override
-    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
-        clients.inMemory()
-                .withClient("client-app")
-                .secret(passwordEncoder.encode("123456"))
-                .scopes("all")
-                .authorizedGrantTypes("password", "refresh_token")
-                .accessTokenValiditySeconds(3600)
-                .refreshTokenValiditySeconds(86400);
-    }
-
-    @Override
-    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
-        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
-        List<TokenEnhancer> delegates = new ArrayList<>();
-        delegates.add(jwtTokenEnhancer);
-        delegates.add(accessTokenConverter());
-        enhancerChain.setTokenEnhancers(delegates); //配置JWT的内容增强器
-        endpoints.authenticationManager(authenticationManager)
-                .userDetailsService(userDetailsService) //配置加载用户信息的服务
-                .accessTokenConverter(accessTokenConverter())
-                .tokenEnhancer(enhancerChain);
-    }
-
-    @Override
-    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
-        security.allowFormAuthenticationForClients();
-    }
-
-    @Bean
-    public JwtAccessTokenConverter accessTokenConverter() {
-        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
-        jwtAccessTokenConverter.setKeyPair(keyPair());
-        return jwtAccessTokenConverter;
-    }
-
-    @Bean
-    public KeyPair keyPair() {
-        //从classpath下的证书中获取秘钥对
-        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "123456".toCharArray());
-        return keyStoreKeyFactory.getKeyPair("jwt", "123456".toCharArray());
-    }
-
-}

+ 0 - 33
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/config/RedisRepositoryConfig.java

@@ -1,33 +0,0 @@
-package com.huimv.oauth2.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-/**
- * Redis相关配置
- * Created by macro on 2020/6/19.
- */
-@Configuration
-@EnableRedisRepositories
-public class RedisRepositoryConfig {
-
-    @Bean
-    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
-        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
-        redisTemplate.setConnectionFactory(connectionFactory);
-        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
-        redisTemplate.setKeySerializer(stringRedisSerializer);
-        redisTemplate.setHashKeySerializer(stringRedisSerializer);
-        Jackson2JsonRedisSerializer<?> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
-        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
-        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
-        redisTemplate.afterPropertiesSet();
-        return redisTemplate;
-    }
-
-}

+ 0 - 40
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/config/WebSecurityConfig.java

@@ -1,40 +0,0 @@
-package com.huimv.oauth2.config;
-
-import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.security.crypto.password.PasswordEncoder;
-
-/**
- * SpringSecurity配置
- * Created by macro on 2020/6/19.
- */
-@Configuration
-@EnableWebSecurity
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-
-    @Override
-    protected void configure(HttpSecurity http) throws Exception {
-        http.authorizeRequests()
-                .requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
-                .antMatchers("/rsa/publicKey").permitAll()
-                .anyRequest().authenticated();
-    }
-
-    @Bean
-    @Override
-    public AuthenticationManager authenticationManagerBean() throws Exception {
-        return super.authenticationManagerBean();
-    }
-
-    @Bean
-    public PasswordEncoder passwordEncoder() {
-        return new BCryptPasswordEncoder();
-    }
-
-}

+ 0 - 23
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/constant/MessageConstant.java

@@ -1,23 +0,0 @@
-package com.huimv.oauth2.constant;
-
-/**
- * 消息常量
- * Created by macro on 2020/6/19.
- */
-public class MessageConstant {
-
-    public static final String LOGIN_SUCCESS = "登录成功!";
-
-    public static final String USERNAME_PASSWORD_ERROR = "用户名或密码错误!";
-
-    public static final String CREDENTIALS_EXPIRED = "该账户的登录凭证已过期,请重新登录!";
-
-    public static final String ACCOUNT_DISABLED = "该账户已被禁用,请联系管理员!";
-
-    public static final String ACCOUNT_LOCKED = "该账号已被锁定,请联系管理员!";
-
-    public static final String ACCOUNT_EXPIRED = "该账号已过期,请联系管理员!";
-
-    public static final String PERMISSION_DENIED = "没有访问权限,请联系管理员!";
-
-}

+ 0 - 11
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/constant/RedisConstant.java

@@ -1,11 +0,0 @@
-package com.huimv.oauth2.constant;
-
-/**
- * Redis常量
- * Created by macro on 2020/6/19.
- */
-public class RedisConstant {
-
-    public static final String RESOURCE_ROLES_MAP = "AUTH:RESOURCE_ROLES_MAP";
-
-}

+ 0 - 42
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/controller/AuthController.java

@@ -1,42 +0,0 @@
-package com.huimv.oauth2.controller;
-
-import com.macro.cloud.api.CommonResult;
-import com.macro.cloud.domain.Oauth2TokenDto;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.oauth2.common.OAuth2AccessToken;
-import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
-import org.springframework.web.HttpRequestMethodNotSupportedException;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.security.Principal;
-import java.util.Map;
-
-/**
- * 自定义Oauth2获取令牌接口
- * Created by macro on 2020/7/17.
- */
-@RestController
-@RequestMapping("/oauth")
-public class AuthController {
-
-    @Autowired
-    private TokenEndpoint tokenEndpoint;
-
-    /**
-     * Oauth2登录认证
-     */
-    @RequestMapping(value = "/token", method = RequestMethod.POST)
-    public CommonResult<Oauth2TokenDto> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
-        OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
-        Oauth2TokenDto oauth2TokenDto = Oauth2TokenDto.builder()
-                .token(oAuth2AccessToken.getValue())
-                .refreshToken(oAuth2AccessToken.getRefreshToken().getValue())
-                .expiresIn(oAuth2AccessToken.getExpiresIn())
-                .tokenHead("Bearer ").build();
-
-        return CommonResult.success(oauth2TokenDto);
-    }
-}

+ 0 - 30
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/controller/KeyPairController.java

@@ -1,30 +0,0 @@
-package com.huimv.oauth2.controller;
-
-import com.nimbusds.jose.jwk.JWKSet;
-import com.nimbusds.jose.jwk.RSAKey;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.security.KeyPair;
-import java.security.interfaces.RSAPublicKey;
-import java.util.Map;
-
-/**
- * 获取RSA公钥接口
- * Created by macro on 2020/6/19.
- */
-@RestController
-public class KeyPairController {
-
-    @Autowired
-    private KeyPair keyPair;
-
-    @GetMapping("/rsa/publicKey")
-    public Map<String, Object> getKey() {
-        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
-        RSAKey key = new RSAKey.Builder(publicKey).build();
-        return new JWKSet(key).toJSONObject();
-    }
-
-}

+ 0 - 31
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/domain/Oauth2TokenDto.java

@@ -1,31 +0,0 @@
-package com.huimv.oauth2.domain;
-
-import lombok.Builder;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * Oauth2获取Token返回信息封装
- * Created by macro on 2020/7/17.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Builder
-public class Oauth2TokenDto {
-    /**
-     * 访问令牌
-     */
-    private String token;
-    /**
-     * 刷新令牌
-     */
-    private String refreshToken;
-    /**
-     * 访问令牌头前缀
-     */
-    private String tokenHead;
-    /**
-     * 有效时间(秒)
-     */
-    private int expiresIn;
-}

+ 0 - 89
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/domain/SecurityUser.java

@@ -1,89 +0,0 @@
-package com.huimv.oauth2.domain;
-
-import lombok.Data;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * 登录用户信息
- * Created by macro on 2020/6/19.
- */
-@Data
-public class SecurityUser implements UserDetails {
-
-    /**
-     * ID
-     */
-    private Long id;
-    /**
-     * 用户名
-     */
-    private String username;
-    /**
-     * 用户密码
-     */
-    private String password;
-    /**
-     * 用户状态
-     */
-    private Boolean enabled;
-    /**
-     * 权限数据
-     */
-    private Collection<SimpleGrantedAuthority> authorities;
-
-    public SecurityUser() {
-
-    }
-
-    public SecurityUser(UserDTO userDTO) {
-        this.setId(userDTO.getId());
-        this.setUsername(userDTO.getUsername());
-        this.setPassword(userDTO.getPassword());
-        this.setEnabled(userDTO.getStatus() == 1);
-        if (userDTO.getRoles() != null) {
-            authorities = new ArrayList<>();
-            userDTO.getRoles().forEach(item -> authorities.add(new SimpleGrantedAuthority(item)));
-        }
-    }
-
-    @Override
-    public Collection<? extends GrantedAuthority> getAuthorities() {
-        return this.authorities;
-    }
-
-    @Override
-    public String getPassword() {
-        return this.password;
-    }
-
-    @Override
-    public String getUsername() {
-        return this.username;
-    }
-
-    @Override
-    public boolean isAccountNonExpired() {
-        return true;
-    }
-
-    @Override
-    public boolean isAccountNonLocked() {
-        return true;
-    }
-
-    @Override
-    public boolean isCredentialsNonExpired() {
-        return true;
-    }
-
-    @Override
-    public boolean isEnabled() {
-        return this.enabled;
-    }
-
-}

+ 0 - 22
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/domain/UserDTO.java

@@ -1,22 +0,0 @@
-package com.huimv.oauth2.domain;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.util.List;
-
-/**
- * Created by macro on 2020/6/19.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@AllArgsConstructor
-public class UserDTO{
-    private Long id;
-    private String username;
-    private String password;
-    private Integer status;
-    private List<String> roles;
-
-}

+ 0 - 20
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/exception/Oauth2ExceptionHandler.java

@@ -1,20 +0,0 @@
-package com.huimv.oauth2.exception;
-
-import com.macro.cloud.api.CommonResult;
-import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-/**
- * 全局处理Oauth2抛出的异常
- * Created by macro on 2020/7/17.
- */
-@ControllerAdvice
-public class Oauth2ExceptionHandler {
-    @ResponseBody
-    @ExceptionHandler(value = OAuth2Exception.class)
-    public CommonResult handleOauth2(OAuth2Exception e) {
-        return CommonResult.failed(e.getMessage());
-    }
-}

+ 0 - 32
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/service/ResourceServiceImpl.java

@@ -1,32 +0,0 @@
-package com.macro.cloud.service;
-
-import cn.hutool.core.collection.CollUtil;
-import com.macro.cloud.constant.RedisConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * 资源与角色匹配关系管理业务类
- * Created by macro on 2020/6/19.
- */
-@Service
-public class ResourceServiceImpl {
-
-    private Map<String, List<String>> resourceRolesMap;
-    @Autowired
-    private RedisTemplate<String,Object> redisTemplate;
-
-    @PostConstruct
-    public void initData() {
-        resourceRolesMap = new TreeMap<>();
-        resourceRolesMap.put("/api/hello", CollUtil.toList("ADMIN"));
-        resourceRolesMap.put("/api/user/currentUser", CollUtil.toList("ADMIN", "TEST"));
-        redisTemplate.opsForHash().putAll(RedisConstant.RESOURCE_ROLES_MAP, resourceRolesMap);
-    }
-}

+ 0 - 61
huimv-smart-oauth2/src/main/java/com/huimv/oauth2/service/UserServiceImpl.java

@@ -1,61 +0,0 @@
-package com.huimv.oauth2.service;
-
-import cn.hutool.core.collection.CollUtil;
-import com.macro.cloud.domain.SecurityUser;
-import com.macro.cloud.domain.UserDTO;
-import com.macro.cloud.constant.MessageConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AccountExpiredException;
-import org.springframework.security.authentication.CredentialsExpiredException;
-import org.springframework.security.authentication.DisabledException;
-import org.springframework.security.authentication.LockedException;
-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.password.PasswordEncoder;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * 用户管理业务类
- * Created by macro on 2020/6/19.
- */
-@Service
-public class UserServiceImpl implements UserDetailsService {
-
-    private List<UserDTO> userList;
-    @Autowired
-    private PasswordEncoder passwordEncoder;
-
-    @PostConstruct
-    public void initData() {
-        String password = passwordEncoder.encode("123456");
-        userList = new ArrayList<>();
-        userList.add(new UserDTO(1L,"macro", password,1, CollUtil.toList("ADMIN")));
-        userList.add(new UserDTO(2L,"andy", password,1, CollUtil.toList("TEST")));
-    }
-
-    @Override
-    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
-        List<UserDTO> findUserList = userList.stream().filter(item -> item.getUsername().equals(username)).collect(Collectors.toList());
-        if (CollUtil.isEmpty(findUserList)) {
-            throw new UsernameNotFoundException(MessageConstant.USERNAME_PASSWORD_ERROR);
-        }
-        SecurityUser securityUser = new SecurityUser(findUserList.get(0));
-        if (!securityUser.isEnabled()) {
-            throw new DisabledException(MessageConstant.ACCOUNT_DISABLED);
-        } else if (!securityUser.isAccountNonLocked()) {
-            throw new LockedException(MessageConstant.ACCOUNT_LOCKED);
-        } else if (!securityUser.isAccountNonExpired()) {
-            throw new AccountExpiredException(MessageConstant.ACCOUNT_EXPIRED);
-        } else if (!securityUser.isCredentialsNonExpired()) {
-            throw new CredentialsExpiredException(MessageConstant.CREDENTIALS_EXPIRED);
-        }
-        return securityUser;
-    }
-
-}

+ 0 - 0
huimv-smart-oauth2/src/main/resources/application.yml


+ 0 - 21
micro-oauth2/micro-oauth2-api/pom.xml

@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xmlns="http://maven.apache.org/POM/4.0.0"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>micro-oauth2</artifactId>
-        <groupId>com.macro.cloud</groupId>
-        <version>1.0.0</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>micro-oauth2-api</artifactId>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-    </dependencies>
-
-</project>

+ 0 - 15
micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/Oauth2ApiApplication.java

@@ -1,15 +0,0 @@
-package com.macro.cloud;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-
-@EnableDiscoveryClient
-@SpringBootApplication
-public class Oauth2ApiApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(Oauth2ApiApplication.class, args);
-    }
-
-}

+ 0 - 18
micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/controller/HelloController.java

@@ -1,18 +0,0 @@
-package com.macro.cloud.controller;
-
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 测试接口
- * Created by macro on 2020/6/19.
- */
-@RestController
-public class HelloController {
-
-    @GetMapping("/hello")
-    public String hello() {
-        return "Hello World.";
-    }
-
-}

+ 0 - 26
micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/controller/UserController.java

@@ -1,26 +0,0 @@
-package com.macro.cloud.controller;
-
-import com.macro.cloud.domain.UserDTO;
-import com.macro.cloud.holder.LoginUserHolder;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 获取登录用户信息接口
- * Created by macro on 2020/6/19.
- */
-@RestController
-@RequestMapping("/user")
-public class UserController{
-
-    @Autowired
-    private LoginUserHolder loginUserHolder;
-
-    @GetMapping("/currentUser")
-    public UserDTO currentUser() {
-        return loginUserHolder.getCurrentUser();
-    }
-
-}

+ 0 - 18
micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/domain/UserDTO.java

@@ -1,18 +0,0 @@
-package com.macro.cloud.domain;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.util.List;
-
-/**
- * Created by macro on 2020/6/19.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class UserDTO {
-    private Long id;
-    private String username;
-    private String password;
-    private List<String> roles;
-}

+ 0 - 31
micro-oauth2/micro-oauth2-api/src/main/java/com/macro/cloud/holder/LoginUserHolder.java

@@ -1,31 +0,0 @@
-package com.macro.cloud.holder;
-
-import cn.hutool.core.convert.Convert;
-import cn.hutool.json.JSONObject;
-import com.macro.cloud.domain.UserDTO;
-import org.springframework.stereotype.Component;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * 获取登录用户信息
- * Created by macro on 2020/6/17.
- */
-@Component
-public class LoginUserHolder {
-
-    public UserDTO getCurrentUser(){
-        //从Header中获取用户信息
-        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
-        HttpServletRequest request = servletRequestAttributes.getRequest();
-        String userStr = request.getHeader("user");
-        JSONObject userJsonObject = new JSONObject(userStr);
-        UserDTO userDTO = new UserDTO();
-        userDTO.setUsername(userJsonObject.getStr("user_name"));
-        userDTO.setId(Convert.toLong(userJsonObject.get("id")));
-        userDTO.setRoles(Convert.toList(String.class,userJsonObject.get("authorities")));
-        return userDTO;
-    }
-}

+ 0 - 16
micro-oauth2/micro-oauth2-api/src/main/resources/application.yml

@@ -1,16 +0,0 @@
-server:
-  port: 9501
-spring:
-  profiles:
-    active: dev
-  application:
-    name: micro-oauth2-api
-  cloud:
-    nacos:
-      discovery:
-        server-addr: localhost:8848
-management:
-  endpoints:
-    web:
-      exposure:
-        include: "*"

+ 0 - 39
micro-oauth2/micro-oauth2-auth/pom.xml

@@ -1,39 +0,0 @@
-<?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>micro-oauth2</artifactId>
-        <groupId>com.macro.cloud</groupId>
-        <version>1.0.0</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>micro-oauth2-auth</artifactId>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-security</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.cloud</groupId>
-            <artifactId>spring-cloud-starter-oauth2</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.nimbusds</groupId>
-            <artifactId>nimbus-jose-jwt</artifactId>
-            <version>8.16</version>
-        </dependency>
-        <!-- redis -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-redis</artifactId>
-        </dependency>
-    </dependencies>
-
-</project>

+ 0 - 15
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/Oauth2AuthApplication.java

@@ -1,15 +0,0 @@
-package com.macro.cloud;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-
-@EnableDiscoveryClient
-@SpringBootApplication
-public class Oauth2AuthApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(Oauth2AuthApplication.class, args);
-    }
-
-}

+ 0 - 124
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/api/CommonResult.java

@@ -1,124 +0,0 @@
-package com.macro.cloud.api;
-
-/**
- * 通用返回对象
- * Created by macro on 2019/4/19.
- */
-public class CommonResult<T> {
-    private long code;
-    private String message;
-    private T data;
-
-    protected CommonResult() {
-    }
-
-    protected CommonResult(long code, String message, T data) {
-        this.code = code;
-        this.message = message;
-        this.data = data;
-    }
-
-    /**
-     * 成功返回结果
-     *
-     * @param data 获取的数据
-     */
-    public static <T> CommonResult<T> success(T data) {
-        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
-    }
-
-    /**
-     * 成功返回结果
-     *
-     * @param data 获取的数据
-     * @param  message 提示信息
-     */
-    public static <T> CommonResult<T> success(T data, String message) {
-        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
-    }
-
-    /**
-     * 失败返回结果
-     * @param errorCode 错误码
-     */
-    public static <T> CommonResult<T> failed(IErrorCode errorCode) {
-        return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
-    }
-
-    /**
-     * 失败返回结果
-     * @param errorCode 错误码
-     * @param message 错误信息
-     */
-    public static <T> CommonResult<T> failed(IErrorCode errorCode,String message) {
-        return new CommonResult<T>(errorCode.getCode(), message, null);
-    }
-
-    /**
-     * 失败返回结果
-     * @param message 提示信息
-     */
-    public static <T> CommonResult<T> failed(String message) {
-        return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
-    }
-
-    /**
-     * 失败返回结果
-     */
-    public static <T> CommonResult<T> failed() {
-        return failed(ResultCode.FAILED);
-    }
-
-    /**
-     * 参数验证失败返回结果
-     */
-    public static <T> CommonResult<T> validateFailed() {
-        return failed(ResultCode.VALIDATE_FAILED);
-    }
-
-    /**
-     * 参数验证失败返回结果
-     * @param message 提示信息
-     */
-    public static <T> CommonResult<T> validateFailed(String message) {
-        return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
-    }
-
-    /**
-     * 未登录返回结果
-     */
-    public static <T> CommonResult<T> unauthorized(T data) {
-        return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
-    }
-
-    /**
-     * 未授权返回结果
-     */
-    public static <T> CommonResult<T> forbidden(T data) {
-        return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
-    }
-
-    public long getCode() {
-        return code;
-    }
-
-    public void setCode(long code) {
-        this.code = code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-
-    public void setMessage(String message) {
-        this.message = message;
-    }
-
-    public T getData() {
-        return data;
-    }
-
-    public void setData(T data) {
-        this.data = data;
-    }
-}

+ 0 - 11
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/api/IErrorCode.java

@@ -1,11 +0,0 @@
-package com.macro.cloud.api;
-
-/**
- * 封装API的错误码
- * Created by macro on 2019/4/19.
- */
-public interface IErrorCode {
-    long getCode();
-
-    String getMessage();
-}

+ 0 - 28
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/api/ResultCode.java

@@ -1,28 +0,0 @@
-package com.macro.cloud.api;
-
-/**
- * 枚举了一些常用API操作码
- * Created by macro on 2019/4/19.
- */
-public enum ResultCode implements IErrorCode {
-    SUCCESS(200, "操作成功"),
-    FAILED(500, "操作失败"),
-    VALIDATE_FAILED(404, "参数检验失败"),
-    UNAUTHORIZED(401, "暂未登录或token已经过期"),
-    FORBIDDEN(403, "没有相关权限");
-    private long code;
-    private String message;
-
-    private ResultCode(long code, String message) {
-        this.code = code;
-        this.message = message;
-    }
-
-    public long getCode() {
-        return code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-}

+ 0 - 28
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/component/JwtTokenEnhancer.java

@@ -1,28 +0,0 @@
-package com.macro.cloud.component;
-
-import com.macro.cloud.domain.SecurityUser;
-import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
-import org.springframework.security.oauth2.common.OAuth2AccessToken;
-import org.springframework.security.oauth2.provider.OAuth2Authentication;
-import org.springframework.security.oauth2.provider.token.TokenEnhancer;
-import org.springframework.stereotype.Component;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * JWT内容增强器
- * Created by macro on 2020/6/19.
- */
-@Component
-public class JwtTokenEnhancer implements TokenEnhancer {
-    @Override
-    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
-        SecurityUser securityUser = (SecurityUser) authentication.getPrincipal();
-        Map<String, Object> info = new HashMap<>();
-        //把用户ID设置到JWT中
-        info.put("id", securityUser.getId());
-        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(info);
-        return accessToken;
-    }
-}

+ 0 - 82
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/config/Oauth2ServerConfig.java

@@ -1,82 +0,0 @@
-package com.macro.cloud.config;
-
-import com.macro.cloud.component.JwtTokenEnhancer;
-import com.macro.cloud.service.UserServiceImpl;
-import lombok.AllArgsConstructor;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
-import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
-import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
-import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
-import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
-import org.springframework.security.oauth2.provider.token.TokenEnhancer;
-import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
-import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
-import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;
-
-import java.security.KeyPair;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 认证服务器配置
- * Created by macro on 2020/6/19.
- */
-@AllArgsConstructor
-@Configuration
-@EnableAuthorizationServer
-public class Oauth2ServerConfig extends AuthorizationServerConfigurerAdapter {
-
-    private final PasswordEncoder passwordEncoder;
-    private final UserServiceImpl userDetailsService;
-    private final AuthenticationManager authenticationManager;
-    private final JwtTokenEnhancer jwtTokenEnhancer;
-
-    @Override
-    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
-        clients.inMemory()
-                .withClient("client-app")
-                .secret(passwordEncoder.encode("123456"))
-                .scopes("all")
-                .authorizedGrantTypes("password", "refresh_token")
-                .accessTokenValiditySeconds(3600)
-                .refreshTokenValiditySeconds(86400);
-    }
-
-    @Override
-    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
-        TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
-        List<TokenEnhancer> delegates = new ArrayList<>();
-        delegates.add(jwtTokenEnhancer);
-        delegates.add(accessTokenConverter());
-        enhancerChain.setTokenEnhancers(delegates); //配置JWT的内容增强器
-        endpoints.authenticationManager(authenticationManager)
-                .userDetailsService(userDetailsService) //配置加载用户信息的服务
-                .accessTokenConverter(accessTokenConverter())
-                .tokenEnhancer(enhancerChain);
-    }
-
-    @Override
-    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
-        security.allowFormAuthenticationForClients();
-    }
-
-    @Bean
-    public JwtAccessTokenConverter accessTokenConverter() {
-        JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
-        jwtAccessTokenConverter.setKeyPair(keyPair());
-        return jwtAccessTokenConverter;
-    }
-
-    @Bean
-    public KeyPair keyPair() {
-        //从classpath下的证书中获取秘钥对
-        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("jwt.jks"), "123456".toCharArray());
-        return keyStoreKeyFactory.getKeyPair("jwt", "123456".toCharArray());
-    }
-
-}

+ 0 - 33
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/config/RedisRepositoryConfig.java

@@ -1,33 +0,0 @@
-package com.macro.cloud.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-/**
- * Redis相关配置
- * Created by macro on 2020/6/19.
- */
-@Configuration
-@EnableRedisRepositories
-public class RedisRepositoryConfig {
-
-    @Bean
-    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
-        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
-        redisTemplate.setConnectionFactory(connectionFactory);
-        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
-        redisTemplate.setKeySerializer(stringRedisSerializer);
-        redisTemplate.setHashKeySerializer(stringRedisSerializer);
-        Jackson2JsonRedisSerializer<?> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
-        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
-        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
-        redisTemplate.afterPropertiesSet();
-        return redisTemplate;
-    }
-
-}

+ 0 - 40
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/config/WebSecurityConfig.java

@@ -1,40 +0,0 @@
-package com.macro.cloud.config;
-
-import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.security.crypto.password.PasswordEncoder;
-
-/**
- * SpringSecurity配置
- * Created by macro on 2020/6/19.
- */
-@Configuration
-@EnableWebSecurity
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-
-    @Override
-    protected void configure(HttpSecurity http) throws Exception {
-        http.authorizeRequests()
-                .requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
-                .antMatchers("/rsa/publicKey").permitAll()
-                .anyRequest().authenticated();
-    }
-
-    @Bean
-    @Override
-    public AuthenticationManager authenticationManagerBean() throws Exception {
-        return super.authenticationManagerBean();
-    }
-
-    @Bean
-    public PasswordEncoder passwordEncoder() {
-        return new BCryptPasswordEncoder();
-    }
-
-}

+ 0 - 23
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/constant/MessageConstant.java

@@ -1,23 +0,0 @@
-package com.macro.cloud.constant;
-
-/**
- * 消息常量
- * Created by macro on 2020/6/19.
- */
-public class MessageConstant {
-
-    public static final String LOGIN_SUCCESS = "登录成功!";
-
-    public static final String USERNAME_PASSWORD_ERROR = "用户名或密码错误!";
-
-    public static final String CREDENTIALS_EXPIRED = "该账户的登录凭证已过期,请重新登录!";
-
-    public static final String ACCOUNT_DISABLED = "该账户已被禁用,请联系管理员!";
-
-    public static final String ACCOUNT_LOCKED = "该账号已被锁定,请联系管理员!";
-
-    public static final String ACCOUNT_EXPIRED = "该账号已过期,请联系管理员!";
-
-    public static final String PERMISSION_DENIED = "没有访问权限,请联系管理员!";
-
-}

+ 0 - 11
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/constant/RedisConstant.java

@@ -1,11 +0,0 @@
-package com.macro.cloud.constant;
-
-/**
- * Redis常量
- * Created by macro on 2020/6/19.
- */
-public class RedisConstant {
-
-    public static final String RESOURCE_ROLES_MAP = "AUTH:RESOURCE_ROLES_MAP";
-
-}

+ 0 - 42
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/controller/AuthController.java

@@ -1,42 +0,0 @@
-package com.macro.cloud.controller;
-
-import com.macro.cloud.api.CommonResult;
-import com.macro.cloud.domain.Oauth2TokenDto;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.oauth2.common.OAuth2AccessToken;
-import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
-import org.springframework.web.HttpRequestMethodNotSupportedException;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.security.Principal;
-import java.util.Map;
-
-/**
- * 自定义Oauth2获取令牌接口
- * Created by macro on 2020/7/17.
- */
-@RestController
-@RequestMapping("/oauth")
-public class AuthController {
-
-    @Autowired
-    private TokenEndpoint tokenEndpoint;
-
-    /**
-     * Oauth2登录认证
-     */
-    @RequestMapping(value = "/token", method = RequestMethod.POST)
-    public CommonResult<Oauth2TokenDto> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
-        OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
-        Oauth2TokenDto oauth2TokenDto = Oauth2TokenDto.builder()
-                .token(oAuth2AccessToken.getValue())
-                .refreshToken(oAuth2AccessToken.getRefreshToken().getValue())
-                .expiresIn(oAuth2AccessToken.getExpiresIn())
-                .tokenHead("Bearer ").build();
-
-        return CommonResult.success(oauth2TokenDto);
-    }
-}

+ 0 - 30
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/controller/KeyPairController.java

@@ -1,30 +0,0 @@
-package com.macro.cloud.controller;
-
-import com.nimbusds.jose.jwk.JWKSet;
-import com.nimbusds.jose.jwk.RSAKey;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.security.KeyPair;
-import java.security.interfaces.RSAPublicKey;
-import java.util.Map;
-
-/**
- * 获取RSA公钥接口
- * Created by macro on 2020/6/19.
- */
-@RestController
-public class KeyPairController {
-
-    @Autowired
-    private KeyPair keyPair;
-
-    @GetMapping("/rsa/publicKey")
-    public Map<String, Object> getKey() {
-        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
-        RSAKey key = new RSAKey.Builder(publicKey).build();
-        return new JWKSet(key).toJSONObject();
-    }
-
-}

+ 0 - 31
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/domain/Oauth2TokenDto.java

@@ -1,31 +0,0 @@
-package com.macro.cloud.domain;
-
-import lombok.Builder;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * Oauth2获取Token返回信息封装
- * Created by macro on 2020/7/17.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Builder
-public class Oauth2TokenDto {
-    /**
-     * 访问令牌
-     */
-    private String token;
-    /**
-     * 刷新令牌
-     */
-    private String refreshToken;
-    /**
-     * 访问令牌头前缀
-     */
-    private String tokenHead;
-    /**
-     * 有效时间(秒)
-     */
-    private int expiresIn;
-}

+ 0 - 89
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/domain/SecurityUser.java

@@ -1,89 +0,0 @@
-package com.macro.cloud.domain;
-
-import lombok.Data;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * 登录用户信息
- * Created by macro on 2020/6/19.
- */
-@Data
-public class SecurityUser implements UserDetails {
-
-    /**
-     * ID
-     */
-    private Long id;
-    /**
-     * 用户名
-     */
-    private String username;
-    /**
-     * 用户密码
-     */
-    private String password;
-    /**
-     * 用户状态
-     */
-    private Boolean enabled;
-    /**
-     * 权限数据
-     */
-    private Collection<SimpleGrantedAuthority> authorities;
-
-    public SecurityUser() {
-
-    }
-
-    public SecurityUser(UserDTO userDTO) {
-        this.setId(userDTO.getId());
-        this.setUsername(userDTO.getUsername());
-        this.setPassword(userDTO.getPassword());
-        this.setEnabled(userDTO.getStatus() == 1);
-        if (userDTO.getRoles() != null) {
-            authorities = new ArrayList<>();
-            userDTO.getRoles().forEach(item -> authorities.add(new SimpleGrantedAuthority(item)));
-        }
-    }
-
-    @Override
-    public Collection<? extends GrantedAuthority> getAuthorities() {
-        return this.authorities;
-    }
-
-    @Override
-    public String getPassword() {
-        return this.password;
-    }
-
-    @Override
-    public String getUsername() {
-        return this.username;
-    }
-
-    @Override
-    public boolean isAccountNonExpired() {
-        return true;
-    }
-
-    @Override
-    public boolean isAccountNonLocked() {
-        return true;
-    }
-
-    @Override
-    public boolean isCredentialsNonExpired() {
-        return true;
-    }
-
-    @Override
-    public boolean isEnabled() {
-        return this.enabled;
-    }
-
-}

+ 0 - 22
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/domain/UserDTO.java

@@ -1,22 +0,0 @@
-package com.macro.cloud.domain;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.util.List;
-
-/**
- * Created by macro on 2020/6/19.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@AllArgsConstructor
-public class UserDTO{
-    private Long id;
-    private String username;
-    private String password;
-    private Integer status;
-    private List<String> roles;
-
-}

+ 0 - 20
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/exception/Oauth2ExceptionHandler.java

@@ -1,20 +0,0 @@
-package com.macro.cloud.exception;
-
-import com.macro.cloud.api.CommonResult;
-import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-/**
- * 全局处理Oauth2抛出的异常
- * Created by macro on 2020/7/17.
- */
-@ControllerAdvice
-public class Oauth2ExceptionHandler {
-    @ResponseBody
-    @ExceptionHandler(value = OAuth2Exception.class)
-    public CommonResult handleOauth2(OAuth2Exception e) {
-        return CommonResult.failed(e.getMessage());
-    }
-}

+ 0 - 32
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/service/ResourceServiceImpl.java

@@ -1,32 +0,0 @@
-package com.macro.cloud.service;
-
-import cn.hutool.core.collection.CollUtil;
-import com.macro.cloud.constant.RedisConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * 资源与角色匹配关系管理业务类
- * Created by macro on 2020/6/19.
- */
-@Service
-public class ResourceServiceImpl {
-
-    private Map<String, List<String>> resourceRolesMap;
-    @Autowired
-    private RedisTemplate<String,Object> redisTemplate;
-
-    @PostConstruct
-    public void initData() {
-        resourceRolesMap = new TreeMap<>();
-        resourceRolesMap.put("/api/hello", CollUtil.toList("ADMIN"));
-        resourceRolesMap.put("/api/user/currentUser", CollUtil.toList("ADMIN", "TEST"));
-        redisTemplate.opsForHash().putAll(RedisConstant.RESOURCE_ROLES_MAP, resourceRolesMap);
-    }
-}

+ 0 - 61
micro-oauth2/micro-oauth2-auth/src/main/java/com/macro/cloud/service/UserServiceImpl.java

@@ -1,61 +0,0 @@
-package com.macro.cloud.service;
-
-import cn.hutool.core.collection.CollUtil;
-import com.macro.cloud.domain.SecurityUser;
-import com.macro.cloud.domain.UserDTO;
-import com.macro.cloud.constant.MessageConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AccountExpiredException;
-import org.springframework.security.authentication.CredentialsExpiredException;
-import org.springframework.security.authentication.DisabledException;
-import org.springframework.security.authentication.LockedException;
-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.password.PasswordEncoder;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * 用户管理业务类
- * Created by macro on 2020/6/19.
- */
-@Service
-public class UserServiceImpl implements UserDetailsService {
-
-    private List<UserDTO> userList;
-    @Autowired
-    private PasswordEncoder passwordEncoder;
-
-    @PostConstruct
-    public void initData() {
-        String password = passwordEncoder.encode("123456");
-        userList = new ArrayList<>();
-        userList.add(new UserDTO(1L,"macro", password,1, CollUtil.toList("ADMIN")));
-        userList.add(new UserDTO(2L,"andy", password,1, CollUtil.toList("TEST")));
-    }
-
-    @Override
-    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
-        List<UserDTO> findUserList = userList.stream().filter(item -> item.getUsername().equals(username)).collect(Collectors.toList());
-        if (CollUtil.isEmpty(findUserList)) {
-            throw new UsernameNotFoundException(MessageConstant.USERNAME_PASSWORD_ERROR);
-        }
-        SecurityUser securityUser = new SecurityUser(findUserList.get(0));
-        if (!securityUser.isEnabled()) {
-            throw new DisabledException(MessageConstant.ACCOUNT_DISABLED);
-        } else if (!securityUser.isAccountNonLocked()) {
-            throw new LockedException(MessageConstant.ACCOUNT_LOCKED);
-        } else if (!securityUser.isAccountNonExpired()) {
-            throw new AccountExpiredException(MessageConstant.ACCOUNT_EXPIRED);
-        } else if (!securityUser.isCredentialsNonExpired()) {
-            throw new CredentialsExpiredException(MessageConstant.CREDENTIALS_EXPIRED);
-        }
-        return securityUser;
-    }
-
-}

+ 0 - 23
micro-oauth2/micro-oauth2-auth/src/main/resources/application.yml

@@ -1,23 +0,0 @@
-server:
-  port: 9401
-spring:
-  profiles:
-    active: dev
-  application:
-    name: micro-oauth2-auth
-  cloud:
-    nacos:
-      discovery:
-        server-addr: localhost:8848
-  jackson:
-    date-format: yyyy-MM-dd HH:mm:ss
-  redis:
-    database: 0
-    port: 6379
-    host: localhost
-    password: 123456
-management:
-  endpoints:
-    web:
-      exposure:
-        include: "*"

BIN
micro-oauth2/micro-oauth2-auth/src/main/resources/jwt.jks


+ 0 - 57
micro-oauth2/micro-oauth2-gateway/pom.xml

@@ -1,57 +0,0 @@
-<?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>micro-oauth2</artifactId>
-        <groupId>com.macro.cloud</groupId>
-        <version>1.0.0</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>micro-oauth2-gateway</artifactId>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-webflux</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.cloud</groupId>
-            <artifactId>spring-cloud-starter-gateway</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.security</groupId>
-            <artifactId>spring-security-config</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.security</groupId>
-            <artifactId>spring-security-oauth2-resource-server</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.security</groupId>
-            <artifactId>spring-security-oauth2-client</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.security</groupId>
-            <artifactId>spring-security-oauth2-jose</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.nimbusds</groupId>
-            <artifactId>nimbus-jose-jwt</artifactId>
-            <version>8.16</version>
-        </dependency>
-        <!-- redis -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-redis</artifactId>
-        </dependency>
-        <!-- 自定义的元数据依赖 -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-configuration-processor</artifactId>
-            <optional>true</optional>
-        </dependency>
-    </dependencies>
-
-</project>

+ 0 - 15
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/Oauth2GatewayApplication.java

@@ -1,15 +0,0 @@
-package com.macro.cloud;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-
-@EnableDiscoveryClient
-@SpringBootApplication
-public class Oauth2GatewayApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(Oauth2GatewayApplication.class, args);
-    }
-
-}

+ 0 - 124
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/api/CommonResult.java

@@ -1,124 +0,0 @@
-package com.macro.cloud.api;
-
-/**
- * 通用返回对象
- * Created by macro on 2019/4/19.
- */
-public class CommonResult<T> {
-    private long code;
-    private String message;
-    private T data;
-
-    protected CommonResult() {
-    }
-
-    protected CommonResult(long code, String message, T data) {
-        this.code = code;
-        this.message = message;
-        this.data = data;
-    }
-
-    /**
-     * 成功返回结果
-     *
-     * @param data 获取的数据
-     */
-    public static <T> CommonResult<T> success(T data) {
-        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
-    }
-
-    /**
-     * 成功返回结果
-     *
-     * @param data 获取的数据
-     * @param  message 提示信息
-     */
-    public static <T> CommonResult<T> success(T data, String message) {
-        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
-    }
-
-    /**
-     * 失败返回结果
-     * @param errorCode 错误码
-     */
-    public static <T> CommonResult<T> failed(IErrorCode errorCode) {
-        return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
-    }
-
-    /**
-     * 失败返回结果
-     * @param errorCode 错误码
-     * @param message 错误信息
-     */
-    public static <T> CommonResult<T> failed(IErrorCode errorCode,String message) {
-        return new CommonResult<T>(errorCode.getCode(), message, null);
-    }
-
-    /**
-     * 失败返回结果
-     * @param message 提示信息
-     */
-    public static <T> CommonResult<T> failed(String message) {
-        return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
-    }
-
-    /**
-     * 失败返回结果
-     */
-    public static <T> CommonResult<T> failed() {
-        return failed(ResultCode.FAILED);
-    }
-
-    /**
-     * 参数验证失败返回结果
-     */
-    public static <T> CommonResult<T> validateFailed() {
-        return failed(ResultCode.VALIDATE_FAILED);
-    }
-
-    /**
-     * 参数验证失败返回结果
-     * @param message 提示信息
-     */
-    public static <T> CommonResult<T> validateFailed(String message) {
-        return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
-    }
-
-    /**
-     * 未登录返回结果
-     */
-    public static <T> CommonResult<T> unauthorized(T data) {
-        return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
-    }
-
-    /**
-     * 未授权返回结果
-     */
-    public static <T> CommonResult<T> forbidden(T data) {
-        return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
-    }
-
-    public long getCode() {
-        return code;
-    }
-
-    public void setCode(long code) {
-        this.code = code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-
-    public void setMessage(String message) {
-        this.message = message;
-    }
-
-    public T getData() {
-        return data;
-    }
-
-    public void setData(T data) {
-        this.data = data;
-    }
-}

+ 0 - 11
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/api/IErrorCode.java

@@ -1,11 +0,0 @@
-package com.macro.cloud.api;
-
-/**
- * 封装API的错误码
- * Created by macro on 2019/4/19.
- */
-public interface IErrorCode {
-    long getCode();
-
-    String getMessage();
-}

+ 0 - 28
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/api/ResultCode.java

@@ -1,28 +0,0 @@
-package com.macro.cloud.api;
-
-/**
- * 枚举了一些常用API操作码
- * Created by macro on 2019/4/19.
- */
-public enum ResultCode implements IErrorCode {
-    SUCCESS(200, "操作成功"),
-    FAILED(500, "操作失败"),
-    VALIDATE_FAILED(404, "参数检验失败"),
-    UNAUTHORIZED(401, "暂未登录或token已经过期"),
-    FORBIDDEN(403, "没有相关权限");
-    private long code;
-    private String message;
-
-    private ResultCode(long code, String message) {
-        this.code = code;
-        this.message = message;
-    }
-
-    public long getCode() {
-        return code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-}

+ 0 - 46
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/authorization/AuthorizationManager.java

@@ -1,46 +0,0 @@
-package com.macro.cloud.authorization;
-
-import cn.hutool.core.convert.Convert;
-import com.macro.cloud.constant.AuthConstant;
-import com.macro.cloud.constant.RedisConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.security.authorization.AuthorizationDecision;
-import org.springframework.security.authorization.ReactiveAuthorizationManager;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.web.server.authorization.AuthorizationContext;
-import org.springframework.stereotype.Component;
-import reactor.core.publisher.Mono;
-
-import java.net.URI;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * 鉴权管理器,用于判断是否有资源的访问权限
- * Created by macro on 2020/6/19.
- */
-@Component
-public class AuthorizationManager implements ReactiveAuthorizationManager<AuthorizationContext> {
-    @Autowired
-    private RedisTemplate<String,Object> redisTemplate;
-
-    @Override
-    public Mono<AuthorizationDecision> check(Mono<Authentication> mono, AuthorizationContext authorizationContext) {
-        //从Redis中获取当前路径可访问角色列表
-        URI uri = authorizationContext.getExchange().getRequest().getURI();
-        Object obj = redisTemplate.opsForHash().get(RedisConstant.RESOURCE_ROLES_MAP, uri.getPath());
-        List<String> authorities = Convert.toList(String.class,obj);
-        authorities = authorities.stream().map(i -> i = AuthConstant.AUTHORITY_PREFIX + i).collect(Collectors.toList());
-        //认证通过且角色匹配的用户可访问当前路径
-        return mono
-                .filter(Authentication::isAuthenticated)
-                .flatMapIterable(Authentication::getAuthorities)
-                .map(GrantedAuthority::getAuthority)
-                .any(authorities::contains)
-                .map(AuthorizationDecision::new)
-                .defaultIfEmpty(new AuthorizationDecision(false));
-    }
-
-}

+ 0 - 33
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/component/RestAuthenticationEntryPoint.java

@@ -1,33 +0,0 @@
-package com.macro.cloud.component;
-
-import cn.hutool.json.JSONUtil;
-import com.macro.cloud.api.CommonResult;
-import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.nio.charset.Charset;
-
-/**
- * 自定义返回结果:没有登录或token过期时
- * Created by macro on 2020/6/18.
- */
-@Component
-public class RestAuthenticationEntryPoint implements ServerAuthenticationEntryPoint {
-    @Override
-    public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
-        ServerHttpResponse response = exchange.getResponse();
-        response.setStatusCode(HttpStatus.OK);
-        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
-        String body= JSONUtil.toJsonStr(CommonResult.unauthorized(e.getMessage()));
-        DataBuffer buffer =  response.bufferFactory().wrap(body.getBytes(Charset.forName("UTF-8")));
-        return response.writeWith(Mono.just(buffer));
-    }
-}

+ 0 - 34
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/component/RestfulAccessDeniedHandler.java

@@ -1,34 +0,0 @@
-package com.macro.cloud.component;
-
-import cn.hutool.json.JSONUtil;
-import com.macro.cloud.api.CommonResult;
-import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.security.web.server.authorization.ServerAccessDeniedHandler;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.nio.charset.Charset;
-
-
-/**
- * 自定义返回结果:没有权限访问时
- * Created by macro on 2018/4/26.
- */
-@Component
-public class RestfulAccessDeniedHandler implements ServerAccessDeniedHandler {
-    @Override
-    public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException denied) {
-        ServerHttpResponse response = exchange.getResponse();
-        response.setStatusCode(HttpStatus.OK);
-        response.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
-        String body= JSONUtil.toJsonStr(CommonResult.forbidden(denied.getMessage()));
-        DataBuffer buffer =  response.bufferFactory().wrap(body.getBytes(Charset.forName("UTF-8")));
-        return response.writeWith(Mono.just(buffer));
-    }
-}

+ 0 - 20
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/config/IgnoreUrlsConfig.java

@@ -1,20 +0,0 @@
-package com.macro.cloud.config;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-/**
- * 网关白名单配置
- * Created by macro on 2020/6/17.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Component
-@ConfigurationProperties(prefix="secure.ignore")
-public class IgnoreUrlsConfig {
-    private List<String> urls;
-}

+ 0 - 33
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/config/RedisRepositoryConfig.java

@@ -1,33 +0,0 @@
-package com.macro.cloud.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-/**
- * Redis相关配置
- * Created by macro on 2020/6/19.
- */
-@Configuration
-@EnableRedisRepositories
-public class RedisRepositoryConfig {
-
-    @Bean
-    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
-        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
-        redisTemplate.setConnectionFactory(connectionFactory);
-        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
-        redisTemplate.setKeySerializer(stringRedisSerializer);
-        redisTemplate.setHashKeySerializer(stringRedisSerializer);
-        Jackson2JsonRedisSerializer<?> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
-        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
-        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
-        redisTemplate.afterPropertiesSet();
-        return redisTemplate;
-    }
-
-}

+ 0 - 66
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/config/ResourceServerConfig.java

@@ -1,66 +0,0 @@
-package com.macro.cloud.config;
-
-import cn.hutool.core.util.ArrayUtil;
-import com.macro.cloud.constant.AuthConstant;
-import com.macro.cloud.authorization.AuthorizationManager;
-import com.macro.cloud.component.RestAuthenticationEntryPoint;
-import com.macro.cloud.component.RestfulAccessDeniedHandler;
-import com.macro.cloud.filter.IgnoreUrlsRemoveJwtFilter;
-import lombok.AllArgsConstructor;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.convert.converter.Converter;
-import org.springframework.security.authentication.AbstractAuthenticationToken;
-import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
-import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
-import org.springframework.security.config.web.server.ServerHttpSecurity;
-import org.springframework.security.oauth2.jwt.Jwt;
-import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
-import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
-import org.springframework.security.oauth2.server.resource.authentication.ReactiveJwtAuthenticationConverterAdapter;
-import org.springframework.security.web.server.SecurityWebFilterChain;
-import reactor.core.publisher.Mono;
-
-/**
- * 资源服务器配置
- * Created by macro on 2020/6/19.
- */
-@AllArgsConstructor
-@Configuration
-@EnableWebFluxSecurity
-public class ResourceServerConfig {
-    private final AuthorizationManager authorizationManager;
-    private final IgnoreUrlsConfig ignoreUrlsConfig;
-    private final RestfulAccessDeniedHandler restfulAccessDeniedHandler;
-    private final RestAuthenticationEntryPoint restAuthenticationEntryPoint;
-    private final IgnoreUrlsRemoveJwtFilter ignoreUrlsRemoveJwtFilter;
-
-    @Bean
-    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
-        http.oauth2ResourceServer().jwt()
-                .jwtAuthenticationConverter(jwtAuthenticationConverter());
-        //自定义处理JWT请求头过期或签名错误的结果
-        http.oauth2ResourceServer().authenticationEntryPoint(restAuthenticationEntryPoint);
-        //对白名单路径,直接移除JWT请求头
-        http.addFilterBefore(ignoreUrlsRemoveJwtFilter, SecurityWebFiltersOrder.AUTHENTICATION);
-        http.authorizeExchange()
-                .pathMatchers(ArrayUtil.toArray(ignoreUrlsConfig.getUrls(),String.class)).permitAll()//白名单配置
-                .anyExchange().access(authorizationManager)//鉴权管理器配置
-                .and().exceptionHandling()
-                .accessDeniedHandler(restfulAccessDeniedHandler)//处理未授权
-                .authenticationEntryPoint(restAuthenticationEntryPoint)//处理未认证
-                .and().csrf().disable();
-        return http.build();
-    }
-
-    @Bean
-    public Converter<Jwt, ? extends Mono<? extends AbstractAuthenticationToken>> jwtAuthenticationConverter() {
-        JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
-        jwtGrantedAuthoritiesConverter.setAuthorityPrefix(AuthConstant.AUTHORITY_PREFIX);
-        jwtGrantedAuthoritiesConverter.setAuthoritiesClaimName(AuthConstant.AUTHORITY_CLAIM_NAME);
-        JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter();
-        jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter);
-        return new ReactiveJwtAuthenticationConverterAdapter(jwtAuthenticationConverter);
-    }
-
-}

+ 0 - 12
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/constant/AuthConstant.java

@@ -1,12 +0,0 @@
-package com.macro.cloud.constant;
-
-/**
- * Created by macro on 2020/6/19.
- */
-public class AuthConstant {
-
-    public static final String AUTHORITY_PREFIX = "ROLE_";
-
-    public static final String AUTHORITY_CLAIM_NAME = "authorities";
-
-}

+ 0 - 10
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/constant/RedisConstant.java

@@ -1,10 +0,0 @@
-package com.macro.cloud.constant;
-
-/**
- * Created by macro on 2020/6/19.
- */
-public class RedisConstant {
-
-    public static final String RESOURCE_ROLES_MAP = "AUTH:RESOURCE_ROLES_MAP";
-
-}

+ 0 - 50
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/filter/AuthGlobalFilter.java

@@ -1,50 +0,0 @@
-package com.macro.cloud.filter;
-
-import cn.hutool.core.util.StrUtil;
-import com.nimbusds.jose.JWSObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
-import org.springframework.cloud.gateway.filter.GlobalFilter;
-import org.springframework.core.Ordered;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.text.ParseException;
-
-/**
- * 将登录用户的JWT转化成用户信息的全局过滤器
- * Created by macro on 2020/6/17.
- */
-@Component
-public class AuthGlobalFilter implements GlobalFilter, Ordered {
-
-    private static Logger LOGGER = LoggerFactory.getLogger(AuthGlobalFilter.class);
-
-    @Override
-    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
-        String token = exchange.getRequest().getHeaders().getFirst("Authorization");
-        if (StrUtil.isEmpty(token)) {
-            return chain.filter(exchange);
-        }
-        try {
-            //从token中解析用户信息并设置到Header中去
-            String realToken = token.replace("Bearer ", "");
-            JWSObject jwsObject = JWSObject.parse(realToken);
-            String userStr = jwsObject.getPayload().toString();
-            LOGGER.info("AuthGlobalFilter.filter() user:{}",userStr);
-            ServerHttpRequest request = exchange.getRequest().mutate().header("user", userStr).build();
-            exchange = exchange.mutate().request(request).build();
-        } catch (ParseException e) {
-            e.printStackTrace();
-        }
-        return chain.filter(exchange);
-    }
-
-    @Override
-    public int getOrder() {
-        return 0;
-    }
-}

+ 0 - 42
micro-oauth2/micro-oauth2-gateway/src/main/java/com/macro/cloud/filter/IgnoreUrlsRemoveJwtFilter.java

@@ -1,42 +0,0 @@
-package com.macro.cloud.filter;
-
-import com.macro.cloud.config.IgnoreUrlsConfig;
-import com.macro.cloud.constant.AuthConstant;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.stereotype.Component;
-import org.springframework.util.AntPathMatcher;
-import org.springframework.util.PathMatcher;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
-import org.springframework.web.server.WebFilterChain;
-import reactor.core.publisher.Mono;
-
-import java.net.URI;
-import java.util.List;
-
-/**
- * 白名单路径访问时需要移除JWT请求头
- * Created by macro on 2020/7/24.
- */
-@Component
-public class IgnoreUrlsRemoveJwtFilter implements WebFilter {
-    @Autowired
-    private IgnoreUrlsConfig ignoreUrlsConfig;
-    @Override
-    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
-        ServerHttpRequest request = exchange.getRequest();
-        URI uri = request.getURI();
-        PathMatcher pathMatcher = new AntPathMatcher();
-        //白名单路径移除JWT请求头
-        List<String> ignoreUrls = ignoreUrlsConfig.getUrls();
-        for (String ignoreUrl : ignoreUrls) {
-            if (pathMatcher.match(ignoreUrl, uri.getPath())) {
-                request = exchange.getRequest().mutate().header("Authorization", "").build();
-                exchange = exchange.mutate().request(request).build();
-                return chain.filter(exchange);
-            }
-        }
-        return chain.filter(exchange);
-    }
-}

+ 0 - 44
micro-oauth2/micro-oauth2-gateway/src/main/resources/application.yml

@@ -1,44 +0,0 @@
-server:
-  port: 9201
-spring:
-  profiles:
-    active: dev
-  application:
-    name: micro-oauth2-gateway
-  cloud:
-    nacos:
-      discovery:
-        server-addr: localhost:8848
-    gateway:
-      routes: #配置路由路径
-        - id: oauth2-api-route
-          uri: lb://micro-oauth2-api
-          predicates:
-            - Path=/api/**
-          filters:
-            - StripPrefix=1
-        - id: oauth2-auth-route
-          uri: lb://micro-oauth2-auth
-          predicates:
-            - Path=/auth/**
-          filters:
-            - StripPrefix=1
-      discovery:
-        locator:
-          enabled: true #开启从注册中心动态创建路由的功能
-          lower-case-service-id: true #使用小写服务名,默认是大写
-  security:
-    oauth2:
-      resourceserver:
-        jwt:
-          jwk-set-uri: 'http://localhost:9401/rsa/publicKey' #配置RSA的公钥访问地址
-  redis:
-    database: 0
-    port: 6379
-    host: localhost
-    password: 123456
-secure:
-  ignore:
-    urls: #配置白名单路径
-      - "/actuator/**"
-      - "/auth/oauth/token"

+ 0 - 103
micro-oauth2/pom.xml

@@ -1,103 +0,0 @@
-<?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">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>com.macro.cloud</groupId>
-    <artifactId>micro-oauth2</artifactId>
-    <packaging>pom</packaging>
-    <version>1.0.0</version>
-    <modules>
-        <module>micro-oauth2-gateway</module>
-        <module>micro-oauth2-auth</module>
-        <module>micro-oauth2-api</module>
-    </modules>
-
-    <properties>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>1.8</maven.compiler.source>
-        <maven.compiler.target>1.8</maven.compiler.target>
-        <java.version>1.8</java.version>
-        <spring-cloud-alibaba.version>2.2.0.RELEASE</spring-cloud-alibaba.version>
-        <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
-        <spring-boot.version>2.3.0.RELEASE</spring-boot.version>
-        <hutool-version>5.3.5</hutool-version>
-    </properties>
-
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>com.alibaba.cloud</groupId>
-                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
-                <version>${spring-cloud-alibaba.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>org.springframework.cloud</groupId>
-                <artifactId>spring-cloud-dependencies</artifactId>
-                <version>${spring-cloud.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>${spring-boot.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
-    <dependencies>
-        <dependency>
-            <groupId>com.alibaba.cloud</groupId>
-            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-actuator</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.junit.vintage</groupId>
-                    <artifactId>junit-vintage-engine</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>cn.hutool</groupId>
-            <artifactId>hutool-all</artifactId>
-            <version>${hutool-version}</version>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
-
-    <repositories>
-        <repository>
-            <id>spring-milestones</id>
-            <name>Spring Milestones</name>
-            <url>https://repo.spring.io/milestone</url>
-        </repository>
-    </repositories>
-
-</project>