Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] : health check API 추가 #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package devocean.tickit.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/health-check")
@RequiredArgsConstructor
public class HealthCheckController {
@GetMapping
public String healthCheck() {
return "Good :)";
}
}
62 changes: 24 additions & 38 deletions src/main/java/devocean/tickit/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,39 @@
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

import java.util.Arrays;
import java.util.Collections;

@RequiredArgsConstructor
@EnableWebSecurity
@Configuration
@EnableWebSecurity
public class SecurityConfig {

private String apiVersion = "/api/v1";

private String[] attendeeList = {
"/user", "/users/**",
"/events", "/events/**",
"/wallets", "/wallets/**",
"/albums", "/albums/**",
"/tickets", "/tickets/**",
"/mypage", "/mypage/**",

};

private String[] hostList = {
"/participants", "/participants/**",
};

public String[] getVersionedList(String[] apiList) {
return Arrays.stream(apiList)
.map(path -> apiVersion + path)
.toArray(String[]::new);
// CORS 설정
CorsConfigurationSource corsConfigurationSource() {
return request -> {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedHeaders(Collections.singletonList("*"));
config.setAllowedMethods(Collections.singletonList("*"));
config.setAllowedOriginPatterns(Collections.singletonList("*")); // 허용할 origin
config.setAllowCredentials(true);
return config;
};
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.httpBasic(HttpBasicConfigurer::disable)
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.
httpBasic(HttpBasicConfigurer::disable)
.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource())) // CORS 설정 추가
.csrf(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
.sessionManagement(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((auth) -> {
auth
.requestMatchers(getVersionedList(attendeeList)).permitAll()
.requestMatchers(getVersionedList(hostList)).permitAll()
// 역할 검증이 필요한 uri 추가하기 .permit
.anyRequest().authenticated();
})
// jwtFilter를 UsernamePasswordAuthenticationFilter 앞에 추가할 것
.authorizeHttpRequests(authorize ->
authorize
.requestMatchers("/**").permitAll()
);

;
return http.build();
return httpSecurity.build();
}
}
}