-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
2,250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package db.domain.fault; | ||
|
||
import db.common.BaseEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Entity | ||
@Table(name = "fault") | ||
@SuperBuilder | ||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FaultEntity extends BaseEntity { | ||
|
||
private LocalDateTime guaranteeAt; | ||
|
||
@Column(length = 200, nullable = false) | ||
private String description; | ||
|
||
@Column(nullable = false) | ||
private Long receivingId; | ||
|
||
@Column(nullable = false) | ||
private Long userId; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package db.domain.fault; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FaultRepository extends JpaRepository<FaultEntity, Long> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' | ||
id 'io.spring.dependency-management' | ||
} | ||
|
||
group = 'org.fx' | ||
version = '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation platform('org.junit:junit-bom:5.10.0') | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-security' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
|
||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' | ||
|
||
implementation 'io.jsonwebtoken:jjwt-api:0.11.5' | ||
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' | ||
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
|
||
implementation project(":db") | ||
implementation project(":global") | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
bootJar { | ||
enabled = true | ||
} | ||
|
||
jar { | ||
enabled = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fault; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class FaultApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(FaultApplication.class, args); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
fault/src/main/java/fault/common/config/entrypoint/CustomAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fault.common.config.entrypoint; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import global.api.Api; | ||
import global.errorcode.ErrorCode; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) | ||
throws IOException, ServletException { | ||
|
||
Api<Object> body = Api.ERROR(ErrorCode.MISSING_REQUIRED_HEADER); | ||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
OutputStream responseStream = response.getOutputStream(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.writeValue(responseStream, body); | ||
responseStream.flush(); | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
fault/src/main/java/fault/common/config/jpa/JpaConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package fault.common.config.jpa; | ||
|
||
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
@Configuration | ||
@EntityScan(basePackages = {"db"}) | ||
@EnableJpaRepositories(basePackages = {"db"}) | ||
public class JpaConfig { | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
fault/src/main/java/fault/common/config/security/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package fault.common.config.security; | ||
|
||
import fault.domain.users.security.jwt.filter.JwtAuthFilter; | ||
import fault.domain.users.security.jwt.service.TokenService; | ||
import fault.domain.users.security.service.AuthorizationService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.security.servlet.PathRequest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.Customizer; | ||
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication; | ||
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.WebSecurityCustomizer; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
|
||
@Configuration | ||
@EnableWebSecurity // security νμ±ν | ||
@EnableGlobalAuthentication | ||
@RequiredArgsConstructor | ||
public class SecurityConfig { | ||
|
||
private final AuthenticationEntryPoint authEntryPoint; | ||
|
||
private final AuthorizationService authorizationService; | ||
private final TokenService tokenService; | ||
|
||
private final List<String> WHITE_LIST = List.of("/swagger-ui.html", "/swagger-ui/**", | ||
"/v3/api-docs/**", "/open-api/**"); | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { | ||
|
||
httpSecurity.cors(cors -> cors.disable()) | ||
.addFilterBefore(new JwtAuthFilter(authorizationService, tokenService), | ||
UsernamePasswordAuthenticationFilter.class) | ||
.csrf((csrfConfig) -> csrfConfig.disable()) // 1λ² | ||
.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy( | ||
SessionCreationPolicy.STATELESS)).authorizeHttpRequests(it -> { | ||
it.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() | ||
.requestMatchers(WHITE_LIST.toArray(new String[0])).permitAll().anyRequest() | ||
.authenticated() | ||
; | ||
}).formLogin(AbstractHttpConfigurer::disable).httpBasic(AbstractHttpConfigurer::disable) | ||
.httpBasic(basic -> basic.authenticationEntryPoint(authEntryPoint)) | ||
.exceptionHandling(Customizer.withDefaults()) | ||
; | ||
|
||
return httpSecurity.build(); | ||
} | ||
|
||
@Bean | ||
public BCryptPasswordEncoder encoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Bean | ||
public WebSecurityCustomizer webSecurityCustomizer() { | ||
return (web) -> web.ignoring().requestMatchers(WHITE_LIST.toArray(new String[0])); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
fault/src/main/java/fault/common/customvalidation/CustomValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package fault.common.customvalidation; | ||
|
||
import global.api.Api; | ||
import jakarta.validation.ValidationException; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.BeanPropertyBindingResult; | ||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.validation.Validator; | ||
import org.springframework.validation.beanvalidation.SpringValidatorAdapter; | ||
|
||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CustomValidator implements Validator { | ||
|
||
private final SpringValidatorAdapter validator; | ||
|
||
@Override | ||
public boolean supports(Class<?> clazz) { | ||
return Api.class.equals(clazz); | ||
} | ||
|
||
@Override | ||
public void validate(Object target, Errors errors) { | ||
if (target instanceof Api) { | ||
Api<?> api = (Api<?>) target; | ||
Object body = api.getBody(); | ||
validator.validate(body, errors); | ||
|
||
//TODO κ²ν νμ | ||
if (errors.hasGlobalErrors()) { | ||
throw new ValidationException(errors.getAllErrors().toString()); | ||
} | ||
|
||
if (errors.hasFieldErrors()) { | ||
FieldError fieldError = errors.getFieldError(); | ||
String field = Objects.requireNonNull(fieldError).getField(); | ||
Object rejectedValue = fieldError.getRejectedValue(); | ||
|
||
if (Objects.requireNonNull(rejectedValue).equals("")) { | ||
throw new ValidationException("[ " + field + " ] " + "μ(λ) λΉ κ°μΌμ μμ΅λλ€."); | ||
} | ||
|
||
throw new ValidationException( | ||
"μλͺ»λ μ λ ₯μ λλ€. [ " + field + " ] " + "μ μ λ ₯ κ·μΉ νμΈ ν μ¬ μμ²λ°λλλ€. μ¬μ©μ μ λ ₯κ° : " + rejectedValue); | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* 1. * -> μ κ·Όμ νμ | ||
* 2. * -> λ°ν νμ | ||
* 3. (.., @global.annotation.ApiValid (*), ..) -> @ApiValidλ₯Ό μ¬μ©νλ λ©μλμ νλΌλ―Έν° μ 체 | ||
*/ | ||
@Before("execution(* *(.., @global.annotation.ApiValid (*), ..))") | ||
public void apiValidAspect(JoinPoint joinPoint) { | ||
Object[] args = joinPoint.getArgs(); | ||
for(Object arg : args) { | ||
if(arg instanceof Api) { | ||
Errors errors = new BeanPropertyBindingResult(args[0], "api"); // μ¬μ€μ dummy errors | ||
this.validate(arg, errors); | ||
break; | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
fault/src/main/java/fault/common/error/FaultErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package fault.common.error; | ||
|
||
import global.errorcode.ErrorCodeIfs; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum FaultErrorCode implements ErrorCodeIfs { | ||
|
||
|
||
; | ||
|
||
private final Integer httpCode; | ||
private final Integer errorCode; | ||
private final String description; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
fault/src/main/java/fault/common/error/GoodsErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fault.common.error; | ||
|
||
import global.errorcode.ErrorCodeIfs; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum GoodsErrorCode implements ErrorCodeIfs { | ||
|
||
GOODS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1200, "λ¬Όνμ΄ μ‘΄μ¬νμ§ μμ΅λλ€."), | ||
INVALID_GOODS_STATUS(HttpStatus.BAD_REQUEST.value(),1201,"μλͺ»λ λ¬Όν μνμ λλ€."), | ||
INVALID_GOODS_STRATEGY(HttpStatus.BAD_REQUEST.value(), 1202, "μμ²μ μ’ λ₯κ° μλͺ»λμμ΅λλ€."), | ||
NOT_OWNER(HttpStatus.NOT_ACCEPTABLE.value(), 1203, "μμ μκ° μλλλ€.") | ||
; | ||
|
||
private final Integer httpCode; | ||
private final Integer errorCode; | ||
private final String description; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
fault/src/main/java/fault/common/error/ImageErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fault.common.error; | ||
|
||
import global.errorcode.ErrorCodeIfs; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ImageErrorCode implements ErrorCodeIfs { | ||
|
||
IMAGE_STORAGE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1300, "μ΄λ―Έμ§λ₯Ό μ μ₯ν μ μμ΅λλ€."), | ||
NULL_POINT(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1301, "NULL POINT μ λλ€."), | ||
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1302, "μμ²νμ μ΄λ―Έμ§λ₯Ό μ°Ύμ μ μμ΅λλ€."), | ||
IMAGE_STORAGE_PATH_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1303, "μ λ‘λλ νμΌμ΄ μ μ₯λ λλ ν°λ¦¬λ₯Ό μμ±ν μ μμ΅λλ€.") | ||
; | ||
|
||
private final Integer httpCode; | ||
private final Integer errorCode; | ||
private final String description; | ||
|
||
} |
Oops, something went wrong.