Skip to content

Commit

Permalink
CI/CD Test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaeAg committed Dec 20, 2023
1 parent 8817927 commit 16e2c85
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 375 deletions.
18 changes: 18 additions & 0 deletions ThirdSeminar/Dockerfile
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"]
13 changes: 8 additions & 5 deletions ThirdSeminar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ dependencies {
implementation 'mysql:mysql-connector-java:8.0.32'

//security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
// implementation 'org.springframework.boot:spring-boot-starter-security'
// testImplementation 'org.springframework.security:spring-security-test'

// AWS sdk
implementation("software.amazon.awssdk:bom:2.21.0")
implementation("software.amazon.awssdk:s3:2.21.0")

implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'
// implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5'
// implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
// implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'

// CI/CD 구축
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

tasks.named('test') {
Expand Down
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);
// }
//}
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 {
//}
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("*");
// }
// };
// }
//}
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);
// }
//}
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);
// }
//}
Loading

0 comments on commit 16e2c85

Please sign in to comment.