Skip to content

Commit

Permalink
merge: develop <- feature/cors-setting
Browse files Browse the repository at this point in the history
merge: develop <- feature/cors-setting
  • Loading branch information
LeeShinHaeng authored Jan 23, 2025
2 parents 74bf63b + 69b3fe0 commit 960f702
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "*"

jobs:
build-docker-image:
build-test:
runs-on: ubuntu-latest

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.List;

Expand All @@ -41,6 +44,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http,
@Qualifier("studentAuthenticationManager") AuthenticationManager studentAuthenticationManager,
@Qualifier("instructorAuthenticationManager") AuthenticationManager instructorAuthenticationManager) throws Exception {
http
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.csrf(AbstractHttpConfigurer::disable)
.formLogin(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
Expand Down Expand Up @@ -113,4 +117,24 @@ public BCryptPasswordEncoder bCryptPasswordEncoder() {
"/actuator/**",
"/v3/api-docs/**",
};

@Bean
public CorsConfigurationSource corsConfigurationSource() {
final CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*"));
configuration.setAllowedMethods(List.of(ALLOWED_METHODS));
configuration.setAllowedHeaders(List.of(ALLOWED_HEADERS));
configuration.setAllowCredentials(false);

final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}


private final String[] ALLOWED_METHODS = {
"HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"
};

private final String[] ALLOWED_HEADERS = {"Authorization", "Cache-Control", "Content-Type"};
}
2 changes: 1 addition & 1 deletion lms/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cloud:
bucket: ${AWS_S3_BUCKET}

server:
host: ${DEV_URL:http://localhost:8080}
host: ${DEV_URL:http://54.180.78.104:8080}
port: 8080

jwt:
Expand Down

0 comments on commit 960f702

Please # to comment.