-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
394 additions
and
375 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,18 @@ | ||
# baseimage -> 컨테이너의 내 에플리케이션이 돌아갈 수 있는 환경을 제공해주는 이미지 | ||
# 현재는 애플리케이션을 실행할 수 있도록 amd64/amazoncorretto:17를 baseImage로 뒀는데요! | ||
# amazoncorretto:17 이미지는 Linux를 base 이미지로 두고있기 때문에 | ||
# amazoncorretto:17 이미지를 baseimage로 두면 linux에 JDK corretto 배포판이 설치된 환경이 제공됩니다. | ||
FROM amd64/amazoncorretto:17 | ||
|
||
# baseimage를 바탕으로 다음 설정들을 진행하게 됩니다. | ||
|
||
# RUN, CMD, ENTRYPOINT 등 명령어들이 실행될 컨테이너 속 작업 디렉토리 설정 | ||
WORKDIR /app | ||
|
||
# COPY {Dockerfile을 기준으로 container에 넣고자 하는 내용의 경로} {container내에 복사할 경로} | ||
# host machine의 파일/디렉토리를 컨테이너 내 경로에 복사 | ||
COPY ./build/libs/seminar-0.0.1-SNAPSHOT.jar /app/seminar.jar | ||
|
||
# 컨테이너가 실행될 때 실행할 명령어 지정 | ||
# 위에서 workdir를 /app으로 지정해줬기 때문에 해당 명령어는 /app에서 실행됨 | ||
CMD ["java", "-Duser.timezone=Asia/Seoul", "-jar", "seminar.jar"] |
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
40 changes: 20 additions & 20 deletions
40
ThirdSeminar/src/main/java/com/server/dosopt/seminar/config/BCryptPasswordConfig.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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package com.server.dosopt.seminar.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
@Configuration | ||
public class BCryptPasswordConfig { | ||
|
||
// salt 할 때 보안 강도를 어느정도로 할지 설정 | ||
// 높을수록 세지는데, 어느정도 높아지면 비슷함 | ||
// default가 10 | ||
private static final int STRENGTH = 10; | ||
|
||
@Bean | ||
public PasswordEncoder bCryptPasswordEncoder() { | ||
return new BCryptPasswordEncoder(STRENGTH); | ||
} | ||
} | ||
//package com.server.dosopt.seminar.config; | ||
// | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
//import org.springframework.security.crypto.password.PasswordEncoder; | ||
// | ||
//@Configuration | ||
//public class BCryptPasswordConfig { | ||
// | ||
// // salt 할 때 보안 강도를 어느정도로 할지 설정 | ||
// // 높을수록 세지는데, 어느정도 높아지면 비슷함 | ||
// // default가 10 | ||
// private static final int STRENGTH = 10; | ||
// | ||
// @Bean | ||
// public PasswordEncoder bCryptPasswordEncoder() { | ||
// return new BCryptPasswordEncoder(STRENGTH); | ||
// } | ||
//} |
18 changes: 9 additions & 9 deletions
18
ThirdSeminar/src/main/java/com/server/dosopt/seminar/config/JpaAuditingConfig.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package com.server.dosopt.seminar.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class JpaAuditingConfig { | ||
} | ||
//package com.server.dosopt.seminar.config; | ||
// | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
// | ||
//@Configuration | ||
//@EnableJpaAuditing | ||
//public class JpaAuditingConfig { | ||
//} |
136 changes: 68 additions & 68 deletions
136
ThirdSeminar/src/main/java/com/server/dosopt/seminar/config/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 |
---|---|---|
@@ -1,69 +1,69 @@ | ||
package com.server.dosopt.seminar.config; | ||
|
||
import com.server.dosopt.seminar.config.jwt.CustomAccessDeniedHandler; | ||
import com.server.dosopt.seminar.config.jwt.CustomJwtAuthenticationEntryPoint; | ||
import com.server.dosopt.seminar.config.jwt.JwtAuthenticationFilter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfig { | ||
|
||
private final JwtAuthenticationFilter jwtAuthenticationFilter; | ||
private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; | ||
private final CustomAccessDeniedHandler customAccessDeniedHandler; | ||
|
||
private static final String[] AUTH_WHITELIST = { | ||
"/sign-up", | ||
"/sign-in" | ||
}; | ||
|
||
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter, CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint, CustomAccessDeniedHandler customAccessDeniedHandler) { | ||
this.jwtAuthenticationFilter = jwtAuthenticationFilter; | ||
this.customJwtAuthenticationEntryPoint = customJwtAuthenticationEntryPoint; | ||
this.customAccessDeniedHandler = customAccessDeniedHandler; | ||
} | ||
|
||
|
||
@Bean | ||
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
return http | ||
.csrf().disable() | ||
.formLogin().disable() | ||
.httpBasic().disable() | ||
// .sessionManagement() | ||
// .sessionCreationPolicy(STATELESS) | ||
//package com.server.dosopt.seminar.config; | ||
// | ||
//import com.server.dosopt.seminar.config.jwt.CustomAccessDeniedHandler; | ||
//import com.server.dosopt.seminar.config.jwt.CustomJwtAuthenticationEntryPoint; | ||
//import com.server.dosopt.seminar.config.jwt.JwtAuthenticationFilter; | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
//import org.springframework.security.web.SecurityFilterChain; | ||
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
//import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
// | ||
// | ||
//@Configuration | ||
//@EnableWebSecurity | ||
//public class SecurityConfig { | ||
// | ||
// private final JwtAuthenticationFilter jwtAuthenticationFilter; | ||
// private final CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint; | ||
// private final CustomAccessDeniedHandler customAccessDeniedHandler; | ||
// | ||
// private static final String[] AUTH_WHITELIST = { | ||
// "/sign-up", | ||
// "/sign-in" | ||
// }; | ||
// | ||
// public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter, CustomJwtAuthenticationEntryPoint customJwtAuthenticationEntryPoint, CustomAccessDeniedHandler customAccessDeniedHandler) { | ||
// this.jwtAuthenticationFilter = jwtAuthenticationFilter; | ||
// this.customJwtAuthenticationEntryPoint = customJwtAuthenticationEntryPoint; | ||
// this.customAccessDeniedHandler = customAccessDeniedHandler; | ||
// } | ||
// | ||
// | ||
// @Bean | ||
// SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
// return http | ||
// .csrf().disable() | ||
// .formLogin().disable() | ||
// .httpBasic().disable() | ||
//// .sessionManagement() | ||
//// .sessionCreationPolicy(STATELESS) | ||
//// .and() | ||
// .exceptionHandling() | ||
// .authenticationEntryPoint(customJwtAuthenticationEntryPoint) | ||
// .accessDeniedHandler(customAccessDeniedHandler) | ||
// .and() | ||
.exceptionHandling() | ||
.authenticationEntryPoint(customJwtAuthenticationEntryPoint) | ||
.accessDeniedHandler(customAccessDeniedHandler) | ||
.and() | ||
.authorizeHttpRequests() | ||
.requestMatchers(AUTH_WHITELIST).permitAll() | ||
.anyRequest().authenticated() | ||
.and() | ||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public WebMvcConfigurer corsConfigurer() { | ||
return new WebMvcConfigurer() { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("*") | ||
.allowedOriginPatterns("*") | ||
.allowedMethods("*"); | ||
} | ||
}; | ||
} | ||
} | ||
// .authorizeHttpRequests() | ||
// .requestMatchers(AUTH_WHITELIST).permitAll() | ||
// .anyRequest().authenticated() | ||
// .and() | ||
// .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) | ||
// .build(); | ||
// } | ||
// | ||
// @Bean | ||
// public WebMvcConfigurer corsConfigurer() { | ||
// return new WebMvcConfigurer() { | ||
// @Override | ||
// public void addCorsMappings(CorsRegistry registry) { | ||
// registry.addMapping("/**") | ||
// .allowedOrigins("*") | ||
// .allowedOriginPatterns("*") | ||
// .allowedMethods("*"); | ||
// } | ||
// }; | ||
// } | ||
//} |
44 changes: 22 additions & 22 deletions
44
...Seminar/src/main/java/com/server/dosopt/seminar/config/jwt/CustomAccessDeniedHandler.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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
package com.server.dosopt.seminar.config.jwt; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.web.access.AccessDeniedHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
|
||
@Component | ||
public class CustomAccessDeniedHandler implements AccessDeniedHandler { | ||
@Override | ||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { | ||
setResponse(response); | ||
} | ||
|
||
private void setResponse(HttpServletResponse response) { | ||
response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
} | ||
} | ||
//package com.server.dosopt.seminar.config.jwt; | ||
// | ||
//import jakarta.servlet.ServletException; | ||
//import jakarta.servlet.http.HttpServletRequest; | ||
//import jakarta.servlet.http.HttpServletResponse; | ||
//import org.springframework.security.access.AccessDeniedException; | ||
//import org.springframework.security.web.access.AccessDeniedHandler; | ||
//import org.springframework.stereotype.Component; | ||
// | ||
//import java.io.IOException; | ||
// | ||
//@Component | ||
//public class CustomAccessDeniedHandler implements AccessDeniedHandler { | ||
// @Override | ||
// public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { | ||
// setResponse(response); | ||
// } | ||
// | ||
// private void setResponse(HttpServletResponse response) { | ||
// response.setStatus(HttpServletResponse.SC_FORBIDDEN); | ||
// } | ||
//} |
40 changes: 20 additions & 20 deletions
40
...src/main/java/com/server/dosopt/seminar/config/jwt/CustomJwtAuthenticationEntryPoint.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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package com.server.dosopt.seminar.config.jwt; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CustomJwtAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { | ||
setResponse(response); | ||
} | ||
|
||
private void setResponse(HttpServletResponse response) { | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
} | ||
} | ||
//package com.server.dosopt.seminar.config.jwt; | ||
// | ||
//import jakarta.servlet.http.HttpServletRequest; | ||
//import jakarta.servlet.http.HttpServletResponse; | ||
//import org.springframework.security.core.AuthenticationException; | ||
//import org.springframework.security.web.AuthenticationEntryPoint; | ||
//import org.springframework.stereotype.Component; | ||
// | ||
//@Component | ||
//public class CustomJwtAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
// | ||
// @Override | ||
// public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { | ||
// setResponse(response); | ||
// } | ||
// | ||
// private void setResponse(HttpServletResponse response) { | ||
// response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
// } | ||
//} |
Oops, something went wrong.