Merge pull request #40 from HideyoshiNakazone/main

Fixes Infra Dispatcher
This commit is contained in:
2024-02-16 01:32:22 -03:00
committed by GitHub
43 changed files with 156 additions and 153 deletions

View File

@@ -36,7 +36,7 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Runs Infra-Hideyoshi.com Deployment Dispatcher - name: Runs Infra-Hideyoshi.com Deployment Dispatcher
run: | run: |
curl -X POST https://api.github.com/repos/HideyoshiNakazone/infra-hideyoshi.com/dispatches \ curl -X POST https://api.github.com/repos/HideyoshiSolutions/infra-hideyoshi.com/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \ -H 'Accept: application/vnd.github.everest-preview+json' \
-u ${{ secrets.ACTIONS_KEY }} \ -u ${{ secrets.ACTIONS_KEY }} \
--data '{"event_type": "refresh-deployments", "client_payload": { "deployments": "backend-deployment" }}' --data '{"event_type": "refresh-deployments", "client_payload": { "deployments": "backend-deployment" }}'

View File

@@ -1,6 +1,5 @@
package com.hideyoshi.backendportfolio.base.config; package com.hideyoshi.backendportfolio.base.config;
import antlr.actions.python.CodeLexer;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@@ -1,7 +1,6 @@
package com.hideyoshi.backendportfolio.base.config; package com.hideyoshi.backendportfolio.base.config;
import com.hideyoshi.backendportfolio.util.exception.AuthenticationInvalidException; import com.hideyoshi.backendportfolio.util.exception.AuthenticationInvalidException;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;

View File

@@ -8,10 +8,8 @@ import com.hideyoshi.backendportfolio.base.security.service.AuthService;
import com.hideyoshi.backendportfolio.util.exception.AuthenticationInvalidException; import com.hideyoshi.backendportfolio.util.exception.AuthenticationInvalidException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -24,7 +22,6 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.filter.ForwardedHeaderFilter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@@ -1,13 +1,9 @@
package com.hideyoshi.backendportfolio.base.security.filter; package com.hideyoshi.backendportfolio.base.security.filter;
import com.auth0.jwt.algorithms.Algorithm;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hideyoshi.backendportfolio.base.config.RestAuthenticationEntryPointConfig; import com.hideyoshi.backendportfolio.base.config.RestAuthenticationEntryPointConfig;
import com.hideyoshi.backendportfolio.base.security.service.AuthService; import com.hideyoshi.backendportfolio.base.security.service.AuthService;
import com.hideyoshi.backendportfolio.base.user.model.TokenDTO;
import com.hideyoshi.backendportfolio.base.user.model.UserDTO; import com.hideyoshi.backendportfolio.base.user.model.UserDTO;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
@@ -17,11 +13,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Log4j2 @Log4j2
public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter { public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter {

View File

@@ -19,7 +19,13 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
public class CustomAuthorizationFilter extends OncePerRequestFilter { public class CustomAuthorizationFilter extends OncePerRequestFilter {
public static String AUTHORIZATION_TYPE_STRING = "Bearer "; private static final List<String> notProtectedPaths = Arrays.asList(
"/user/login",
"/user/signup",
"/user/login/refresh"
);
private static final String AUTHORIZATION_TYPE_STRING = "Bearer ";
private final AuthService authService; private final AuthService authService;
@@ -62,11 +68,6 @@ public class CustomAuthorizationFilter extends OncePerRequestFilter {
} }
private Boolean isPathNotProtected(String path) { private Boolean isPathNotProtected(String path) {
List<String> notProtectedPaths = Arrays.asList(
"/user/login"
);
return notProtectedPaths.contains(path); return notProtectedPaths.contains(path);
} }

View File

@@ -10,7 +10,6 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;

View File

@@ -2,7 +2,6 @@ package com.hideyoshi.backendportfolio.base.security.oauth.mapper;
import com.hideyoshi.backendportfolio.base.user.entity.Provider; import com.hideyoshi.backendportfolio.base.user.entity.Provider;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.security.oauth2.core.user.OAuth2User;
@AllArgsConstructor @AllArgsConstructor

View File

@@ -2,7 +2,6 @@ package com.hideyoshi.backendportfolio.base.security.oauth.mapper;
import com.hideyoshi.backendportfolio.base.user.entity.Provider; import com.hideyoshi.backendportfolio.base.user.entity.Provider;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.security.oauth2.core.user.OAuth2User;
@AllArgsConstructor @AllArgsConstructor

View File

@@ -1,7 +1,6 @@
package com.hideyoshi.backendportfolio.base.security.oauth.mapper; package com.hideyoshi.backendportfolio.base.security.oauth.mapper;
import com.hideyoshi.backendportfolio.base.user.entity.Provider; import com.hideyoshi.backendportfolio.base.user.entity.Provider;
import org.springframework.security.oauth2.core.user.OAuth2User;
public interface OAuthMap { public interface OAuthMap {

View File

@@ -19,10 +19,6 @@ public enum OAuthMapper {
this.provider = provider; this.provider = provider;
} }
public Class getMap() {
return oAuthMap;
}
public static OAuthMapper byValue(String name) { public static OAuthMapper byValue(String name) {
for (OAuthMapper e : values()) { for (OAuthMapper e : values()) {
if (e.getProvider().getName().equals(name)) { if (e.getProvider().getName().equals(name)) {
@@ -32,4 +28,8 @@ public enum OAuthMapper {
throw new IllegalArgumentException("Argument not valid."); throw new IllegalArgumentException("Argument not valid.");
} }
public Class getMap() {
return oAuthMap;
}
} }

View File

@@ -45,21 +45,15 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
public class AuthServiceImpl implements AuthService { public class AuthServiceImpl implements AuthService {
private static final String AUTHORIZATION_TYPE_STRING = "Bearer ";
private final UserService userService;
private final StorageService storageService;
@Value("${com.hideyoshi.tokenSecret}") @Value("${com.hideyoshi.tokenSecret}")
private String TOKEN_SECRET; private String TOKEN_SECRET;
@Value("${com.hideyoshi.accessTokenDuration}") @Value("${com.hideyoshi.accessTokenDuration}")
private Integer ACCESS_TOKEN_DURATION; private Integer ACCESS_TOKEN_DURATION;
@Value("${com.hideyoshi.refreshTokenDuration}") @Value("${com.hideyoshi.refreshTokenDuration}")
private Integer REFRESH_TOKEN_DURATION; private Integer REFRESH_TOKEN_DURATION;
private static final String AUTHORIZATION_TYPE_STRING = "Bearer ";
private final UserService userService;
private final StorageService storageService;
@Autowired @Autowired
@Qualifier("handlerExceptionResolver") @Qualifier("handlerExceptionResolver")
private HandlerExceptionResolver resolver; private HandlerExceptionResolver resolver;

View File

@@ -2,12 +2,14 @@ package com.hideyoshi.backendportfolio.base.session.api;
import com.hideyoshi.backendportfolio.base.security.model.AuthDTO; import com.hideyoshi.backendportfolio.base.security.model.AuthDTO;
import com.hideyoshi.backendportfolio.base.session.service.SessionManagerService; import com.hideyoshi.backendportfolio.base.session.service.SessionManagerService;
import com.hideyoshi.backendportfolio.base.user.model.UserDTO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;

View File

@@ -1,7 +1,6 @@
package com.hideyoshi.backendportfolio.base.session.service; package com.hideyoshi.backendportfolio.base.session.service;
import com.hideyoshi.backendportfolio.base.security.model.AuthDTO; import com.hideyoshi.backendportfolio.base.security.model.AuthDTO;
import com.hideyoshi.backendportfolio.base.user.service.UserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

View File

@@ -14,10 +14,6 @@ public enum Provider {
this.name = name; this.name = name;
} }
public String getName() {
return name;
}
public static Provider byValue(String name) { public static Provider byValue(String name) {
for (Provider p : values()) { for (Provider p : values()) {
if (p.getName().equals(name)) { if (p.getName().equals(name)) {
@@ -27,4 +23,8 @@ public enum Provider {
throw new IllegalArgumentException("Argument not valid."); throw new IllegalArgumentException("Argument not valid.");
} }
public String getName() {
return name;
}
} }

View File

@@ -13,10 +13,6 @@ public enum Role {
this.description = description; this.description = description;
} }
public String getDescription() {
return this.description;
}
public static Role byValue(String description) { public static Role byValue(String description) {
for (Role r : values()) { for (Role r : values()) {
if (r.getDescription().equals(description)) { if (r.getDescription().equals(description)) {
@@ -26,4 +22,8 @@ public enum Role {
throw new IllegalArgumentException("Argument not valid."); throw new IllegalArgumentException("Argument not valid.");
} }
public String getDescription() {
return this.description;
}
} }

View File

@@ -64,12 +64,6 @@ public class User {
) )
private String roles; private String roles;
public void setRoles(List<Role> roles) {
this.roles = roles.stream()
.map(role -> role.getDescription())
.collect(Collectors.joining("&"));
}
public List<Role> getRoles() { public List<Role> getRoles() {
List<Role> roles = new ArrayList<>(); List<Role> roles = new ArrayList<>();
if (Objects.nonNull(this.roles) && !this.roles.isEmpty()) { if (Objects.nonNull(this.roles) && !this.roles.isEmpty()) {
@@ -80,4 +74,10 @@ public class User {
return roles; return roles;
} }
public void setRoles(List<Role> roles) {
this.roles = roles.stream()
.map(role -> role.getDescription())
.collect(Collectors.joining("&"));
}
} }

View File

@@ -3,7 +3,9 @@ package com.hideyoshi.backendportfolio.base.user.model;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*; import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;

View File

@@ -9,5 +9,6 @@ import java.util.Optional;
@Repository @Repository
public interface UserRepository extends JpaRepository<User, Long> { public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsername(String username); Optional<User> findByUsername(String username);
Optional<User> findByEmail(String email); Optional<User> findByEmail(String email);
} }

View File

@@ -0,0 +1,21 @@
package com.hideyoshi.backendportfolio.healthChecker.api;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Log4j2
@Controller
@RestController
@RequestMapping("/health")
public class HealthCheckerController {
@RequestMapping
public ResponseEntity<String> healthCheck() {
log.info("Health check requested");
return ResponseEntity.ok("Health check successful!");
}
}

View File

@@ -2,7 +2,9 @@ package com.hideyoshi.backendportfolio.microservice.storageService.model;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter @Getter
@NoArgsConstructor @NoArgsConstructor

View File

@@ -2,7 +2,9 @@ package com.hideyoshi.backendportfolio.microservice.storageService.model;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter @Getter
@NoArgsConstructor @NoArgsConstructor

View File

@@ -1,7 +1,6 @@
package com.hideyoshi.backendportfolio.microservice.storageService.service; package com.hideyoshi.backendportfolio.microservice.storageService.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.hideyoshi.backendportfolio.microservice.storageService.config.StorageServiceConfig; import com.hideyoshi.backendportfolio.microservice.storageService.config.StorageServiceConfig;
import com.hideyoshi.backendportfolio.microservice.storageService.enums.FileTypeEnum; import com.hideyoshi.backendportfolio.microservice.storageService.enums.FileTypeEnum;
@@ -10,8 +9,8 @@ import com.hideyoshi.backendportfolio.microservice.storageService.model.StorageS
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;

View File

@@ -61,11 +61,6 @@ public enum UserResourceGuardEnum {
this.accessType = accessType; this.accessType = accessType;
} }
public abstract Boolean hasAccess(
UserService userService,
ObjectMapper objectMapper,
HttpServletRequest request);
public static UserResourceGuardEnum byValue(String accessType) { public static UserResourceGuardEnum byValue(String accessType) {
for (UserResourceGuardEnum o : values()) { for (UserResourceGuardEnum o : values()) {
if (o.getAccessType().equals(accessType)) { if (o.getAccessType().equals(accessType)) {
@@ -106,4 +101,9 @@ public enum UserResourceGuardEnum {
return true; return true;
} }
public abstract Boolean hasAccess(
UserService userService,
ObjectMapper objectMapper,
HttpServletRequest request);
} }

View File

@@ -1,7 +1,5 @@
package com.hideyoshi.backendportfolio.util.validator.email.valid; package com.hideyoshi.backendportfolio.util.validator.email.valid;
import com.hideyoshi.backendportfolio.util.validator.email.valid.EmailValidator;
import javax.validation.Constraint; import javax.validation.Constraint;
import javax.validation.Payload; import javax.validation.Payload;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;

View File

@@ -10,9 +10,8 @@ import java.util.regex.Pattern;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PasswordValidator implements ConstraintValidator<ValidPassword, String> { public class PasswordValidator implements ConstraintValidator<ValidPassword, String> {
Provider provider;
private final String PASSWORD_PATTERN = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$"; private final String PASSWORD_PATTERN = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$";
Provider provider;
@Override @Override
public void initialize(ValidPassword constraintAnnotation) { public void initialize(ValidPassword constraintAnnotation) {

View File

@@ -2,7 +2,6 @@ package com.hideyoshi.backendportfolio;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
@DataJpaTest @DataJpaTest
class BackendPortfolioApplicationTests { class BackendPortfolioApplicationTests {

View File

@@ -1,6 +1,5 @@
package com.hideyoshi.backendportfolio.base.user.service; package com.hideyoshi.backendportfolio.base.user.service;
import com.hideyoshi.backendportfolio.base.security.service.AuthService;
import com.hideyoshi.backendportfolio.base.user.entity.Provider; import com.hideyoshi.backendportfolio.base.user.entity.Provider;
import com.hideyoshi.backendportfolio.base.user.entity.Role; import com.hideyoshi.backendportfolio.base.user.entity.Role;
import com.hideyoshi.backendportfolio.base.user.entity.User; import com.hideyoshi.backendportfolio.base.user.entity.User;
@@ -10,7 +9,10 @@ import com.hideyoshi.backendportfolio.util.exception.BadRequestException;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.*; import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.BDDMockito;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
@@ -24,7 +26,6 @@ import java.util.Optional;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@DataJpaTest @DataJpaTest