Skip to content

Commit

Permalink
chore: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
clean2001 committed Jul 10, 2024
2 parents 124b8c9 + f14ad8d commit 93856e2
Show file tree
Hide file tree
Showing 36 changed files with 268 additions and 117 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ project(":layer-api") {
// jpa
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

//Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

runtimeOnly 'com.mysql:mysql-connector-j'
}

Expand All @@ -94,6 +97,7 @@ project(":layer-common") {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
}

}
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions layer-api/src/main/java/org/layer/auth/jwt/JwtToken.java

This file was deleted.

11 changes: 11 additions & 0 deletions layer-api/src/main/java/org/layer/common/annotation/MemberId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.layer.common.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface MemberId {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.layer.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.layer.common.exception.BaseCustomException;
import org.layer.common.exception.ExceptionType;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand Down
6 changes: 2 additions & 4 deletions layer-api/src/main/java/org/layer/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import lombok.RequiredArgsConstructor;
import org.layer.auth.jwt.JwtAuthenticationFilter;
import org.layer.domain.jwt.JwtAuthenticationFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand Down Expand Up @@ -39,6 +39,7 @@ private void setHttp(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher("/api/auth/reissue-token")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/sign-up")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/oauth2/google")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/test")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/oauth2/kakao")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/test")).permitAll()
.anyRequest().authenticated()
Expand All @@ -52,7 +53,4 @@ private void permitSwaggerUri(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher("/swagger-ui/**")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/docs/**")).permitAll());
}



}
60 changes: 60 additions & 0 deletions layer-api/src/main/java/org/layer/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.layer.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.layer.common.annotation.MemberId;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.HandlerMethod;

import java.util.Arrays;

@Configuration
public class SwaggerConfig {

SecurityScheme apiAuth = new SecurityScheme()
.type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER)
.name("authorization-token");

SecurityRequirement addSecurityItem = new SecurityRequirement()
.addList("authorization-token");

@Bean
public OpenAPI openAPI(){
var info = new Info();
info.title("Layer API");
info.description("Layer API 문서에요.");
info.contact(
new Contact()
.email("[email protected]")
.name("떡잎마을방범대")
);
info.license(new License().name("MIT"));
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("authorization-token", apiAuth)
)
.addSecurityItem(addSecurityItem)
.info(info);
}

@Bean
public OperationCustomizer customizeOperation() {
return (operation, handlerMethod) -> {
HandlerMethod method = (HandlerMethod) handlerMethod;
method.getMethodParameters();
method.getMethodParameters();
if (Arrays.stream(method.getMethodParameters()).anyMatch(param -> param.hasParameterAnnotation(MemberId.class))) {
operation.getParameters().removeIf(param -> "memberId".equals(param.getName()));
}
return operation;
};
}
}
41 changes: 41 additions & 0 deletions layer-api/src/main/java/org/layer/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.layer.config;

import lombok.RequiredArgsConstructor;
import org.layer.resolver.MemberIdResolver;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

@Value("${webmvc.cors.allowedOrigins}")
private String allowedOrigins;

private final MemberIdResolver memberIdResolver;


@Bean
public WebMvcConfigurer corsConfigurer(){
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(allowedOrigins.split(","))
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}
};
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(memberIdResolver);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.layer.auth.api;
package org.layer.domain.auth.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.layer.auth.dto.controller.*;
import org.layer.auth.dto.service.SignInServiceResponse;
import org.layer.auth.dto.service.SignUpServiceResponse;
import org.layer.auth.service.AuthService;

import org.layer.domain.member.entity.Member;
import org.layer.domain.auth.controller.dto.*;
import org.layer.domain.auth.service.AuthService;
import org.layer.domain.auth.service.dto.SignInServiceResponse;
import org.layer.domain.auth.service.dto.SignUpServiceResponse;
import org.layer.domain.member.repository.MemberRepository;
import org.layer.oauth.service.GoogleService;
import org.layer.oauth.service.KakaoService;
Expand All @@ -18,8 +16,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/auth")
Expand Down Expand Up @@ -78,5 +74,4 @@ public String googleTest(@RequestParam("code") String code) {
public Object kakaoLogin(@RequestParam(value = "code", required = false) String code) {
return kakaoService.getToken(code);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.layer.auth.dto.controller;
package org.layer.domain.auth.controller.dto;

import org.layer.auth.dto.service.ReissueTokenServiceResponse;
import org.layer.domain.auth.service.dto.ReissueTokenServiceResponse;

public record ReissueTokenResponse(Long memberId, String accessToken, String refreshToken){
public static ReissueTokenResponse of(ReissueTokenServiceResponse rtsr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.layer.auth.dto.controller;
package org.layer.domain.auth.controller.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.layer.domain.member.entity.SocialType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.layer.auth.dto.controller;
package org.layer.domain.auth.controller.dto;

import org.layer.auth.dto.service.SignInServiceResponse;
import org.layer.domain.auth.service.dto.SignInServiceResponse;
import org.layer.domain.member.entity.MemberRole;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.layer.auth.dto.controller;
package org.layer.domain.auth.controller.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.layer.auth.dto.controller;
package org.layer.domain.auth.controller.dto;

import org.layer.auth.dto.service.SignUpServiceResponse;
import org.layer.domain.member.entity.Member;
import org.layer.domain.auth.service.dto.SignUpServiceResponse;
import org.layer.domain.member.entity.MemberRole;
import org.layer.domain.member.entity.SocialType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.layer.domain.auth.exception;

import lombok.RequiredArgsConstructor;
import org.layer.common.exception.ExceptionType;
import org.springframework.http.HttpStatus;

@RequiredArgsConstructor
public enum AuthExceptionType implements ExceptionType {

/**
* 400
*/
INVALID_SOCIAL_TYPE(HttpStatus.BAD_REQUEST, "지원하지 않는 방식의 로그인입니다."),
FORBIDDEN(HttpStatus.FORBIDDEN, "권한이 없습니다.");


private final HttpStatus status;
private final String message;

@Override
public HttpStatus httpStatus() {
return status;
}

@Override
public String message() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.layer.auth.exception;
package org.layer.domain.auth.exception;

import lombok.RequiredArgsConstructor;
import org.layer.common.exception.ExceptionType;
Expand Down Expand Up @@ -27,4 +27,4 @@ public HttpStatus httpStatus() {
public String message() {
return message;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
package org.layer.auth.service;
package org.layer.domain.auth.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.layer.auth.dto.controller.SignUpRequest;
import org.layer.auth.dto.service.ReissueTokenServiceResponse;
import org.layer.auth.dto.service.SignInServiceResponse;
import org.layer.auth.dto.service.SignUpServiceResponse;
import org.layer.auth.exception.AuthExceptionType;
import org.layer.auth.jwt.JwtToken;
import org.layer.common.exception.BaseCustomException;
import org.layer.domain.auth.controller.dto.SignUpRequest;
import org.layer.domain.auth.service.dto.ReissueTokenServiceResponse;
import org.layer.domain.auth.service.dto.SignInServiceResponse;
import org.layer.domain.auth.service.dto.SignUpServiceResponse;
import org.layer.domain.jwt.JwtToken;
import org.layer.domain.jwt.exception.AuthExceptionType;
import org.layer.domain.jwt.service.JwtService;
import org.layer.domain.member.entity.Member;
import org.layer.domain.member.entity.SocialType;
import org.layer.member.service.MemberService;
import org.layer.member.service.MemberUtil;
import org.layer.oauth.config.KakaoOAuthConfig;
import org.layer.domain.member.service.MemberService;
import org.layer.domain.member.service.MemberUtil;
import org.layer.oauth.dto.service.MemberInfoServiceResponse;
import org.layer.oauth.service.GoogleService;
import org.layer.oauth.service.KakaoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestClient;

import java.util.Map;

import static org.layer.auth.exception.AuthExceptionType.*;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -98,7 +91,7 @@ private MemberInfoServiceResponse getMemberInfo(SocialType socialType, String so
return switch (socialType) {
case KAKAO -> kakaoService.getMemberInfo(socialAccessToken);
case GOOGLE -> googleService.getMemberInfo(socialAccessToken);
default -> throw new BaseCustomException(INVALID_SOCIAL_TYPE);
default -> throw new BaseCustomException(AuthExceptionType.INVALID_SOCIAL_TYPE);
};
}

Expand All @@ -107,7 +100,7 @@ private MemberInfoServiceResponse getMemberInfo(SocialType socialType, String so
private void isValidMember(Long memberId) {
Member currentMember = memberUtil.getCurrentMember();
if(!currentMember.getId().equals(memberId)) {
throw new BaseCustomException(FORBIDDEN);
throw new BaseCustomException(AuthExceptionType.FORBIDDEN);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.layer.auth.dto.service;
package org.layer.domain.auth.service.dto;

import org.layer.auth.jwt.JwtToken;
import org.layer.domain.jwt.JwtToken;
import org.layer.domain.member.entity.Member;

public record ReissueTokenServiceResponse(Long memberId, JwtToken jwtToken) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.layer.auth.dto.service;
package org.layer.domain.auth.service.dto;

import org.layer.auth.jwt.JwtToken;
import org.layer.domain.jwt.JwtToken;
import org.layer.domain.member.entity.Member;
import org.layer.domain.member.entity.MemberRole;

Expand Down
Loading

0 comments on commit 93856e2

Please sign in to comment.