-
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.
* rename: 로그인 요청 dto @Schema 추가 * chore: server domain 환경 설정 external-api -> infra * chore: server domain property bean 등록 * chore: application-infra server 블럭 수정 * fix: swagger server url 환경변수 경로 수정 * chore: cors 설정 추가 * refactor: cors 설정 파일 분리 * rename: jwt security config -> security adpater config * chore: bcryptpasswordencoder -> passwordencoder * fix: 동일한 클래스명의 DTO @Schema name 속성 설정 * refactor: 운영 환경 별 security filter chain 설정 분리 * chore: external api 모듈 내 jackson nullable module 종속성 추가 * refactor: security auth config 분리 * refactor: security config swagger endpoint 프로필 별 설정 분리 * feat: simple granted authority 역직렬화 이슈로 custom granted authority 클래스 선언 * chore: external-api 내 jackson config 설정 * fix: security user details 역직렬화 문제 해결 * fix: security config 개발 환경 옵션 수정 * fix: custom granted authority equals 수정 * chore: docker hub 경로 수정
- Loading branch information
1 parent
6334e72
commit f925160
Showing
16 changed files
with
254 additions
and
74 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
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
48 changes: 48 additions & 0 deletions
48
...c/main/java/kr/co/pennyway/api/common/security/authentication/CustomGrantedAuthority.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,48 @@ | ||
package kr.co.pennyway.api.common.security.authentication; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.util.Assert; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
|
||
public final class CustomGrantedAuthority implements GrantedAuthority, Serializable { | ||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final String role; | ||
|
||
@JsonCreator | ||
public CustomGrantedAuthority(@JsonProperty("authority") String role) { | ||
Assert.hasText(role, "role must not be empty"); | ||
this.role = role; | ||
} | ||
|
||
@Override | ||
public String getAuthority() { | ||
return role; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj instanceof CustomGrantedAuthority cga) { | ||
return this.role.equals(cga.getAuthority()); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.role.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.role; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
pennyway-app-external-api/src/main/java/kr/co/pennyway/api/config/JacksonConfig.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,20 @@ | ||
package kr.co.pennyway.api.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.RequiredArgsConstructor; | ||
import org.openapitools.jackson.nullable.JsonNullableModule; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class JacksonConfig { | ||
@Bean | ||
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { | ||
return new Jackson2ObjectMapperBuilder() | ||
.serializationInclusion(JsonInclude.Include.ALWAYS) | ||
.modulesToInstall(new JsonNullableModule()) | ||
.indentOutput(true); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
pennyway-app-external-api/src/main/java/kr/co/pennyway/api/config/security/CorsConfig.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,33 @@ | ||
package kr.co.pennyway.api.config.security; | ||
|
||
import kr.co.pennyway.infra.common.properties.ServerProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class CorsConfig { | ||
private final ServerProperties serverProperties; | ||
|
||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration configuration = new CorsConfiguration(); | ||
configuration.setAllowedOrigins(List.of(serverProperties.getLocal(), serverProperties.getDev())); | ||
configuration.setAllowedMethods(List.of("GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE")); | ||
configuration.setAllowedHeaders(List.of("*")); | ||
configuration.setExposedHeaders(List.of(HttpHeaders.AUTHORIZATION, HttpHeaders.SET_COOKIE)); | ||
configuration.setMaxAge(3600L); | ||
configuration.setAllowCredentials(true); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", configuration); | ||
return source; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...app-external-api/src/main/java/kr/co/pennyway/api/config/security/SecurityAuthConfig.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,52 @@ | ||
package kr.co.pennyway.api.config.security; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import kr.co.pennyway.api.common.security.authentication.UserDetailServiceImpl; | ||
import kr.co.pennyway.api.common.security.handler.JwtAccessDeniedHandler; | ||
import kr.co.pennyway.api.common.security.handler.JwtAuthenticationEntryPoint; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider; | ||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.security.web.access.AccessDeniedHandler; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Configuration | ||
public class SecurityAuthConfig { | ||
private final UserDetailServiceImpl userDetailsService; | ||
private final ObjectMapper objectMapper; | ||
|
||
@Bean | ||
public PasswordEncoder bCryptPasswordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Bean | ||
public AccessDeniedHandler accessDeniedHandler() { | ||
return new JwtAccessDeniedHandler(objectMapper); | ||
} | ||
|
||
@Bean | ||
public AuthenticationEntryPoint authenticationEntryPoint() { | ||
return new JwtAuthenticationEntryPoint(objectMapper); | ||
} | ||
|
||
@Bean | ||
public DaoAuthenticationProvider daoAuthenticationProvider() { | ||
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); | ||
daoAuthenticationProvider.setUserDetailsService(userDetailsService); | ||
daoAuthenticationProvider.setPasswordEncoder(bCryptPasswordEncoder()); | ||
return daoAuthenticationProvider; | ||
} | ||
|
||
@Bean | ||
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception { | ||
return config.getAuthenticationManager(); | ||
} | ||
} |
Oops, something went wrong.