Skip to content

Commit

Permalink
[FIX] #122 user repository에 누락된 조회 쿼리 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Jan 27, 2024
1 parent 67bd1b4 commit 0081c1d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,75 +23,78 @@
@EnableWebSecurity
public class SecurityConfig {

private final JwtTokenProvider jwtTokenProvider;
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
private final JwtTokenProvider jwtTokenProvider;
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;

private static final String[] SWAGGER_URL = {
"/swagger-resources/**",
"/favicon.ico",
"/api-docs/**",
"/swagger-ui/**",
"/swagger-ui.html",
"/swagger-ui/index.html",
"/docs/swagger-ui/index.html",
"/swagger-ui/swagger-ui.css",
};
private static final String[] SWAGGER_URL = {
"/swagger-resources/**",
"/favicon.ico",
"/api-docs/**",
"/swagger-ui/**",
"/swagger-ui.html",
"/swagger-ui/index.html",
"/docs/swagger-ui/index.html",
"/swagger-ui/swagger-ui.css",
};

private static final String[] AUTH_WHITELIST = {
"/health"
};
private static final String[] AUTH_WHITELIST = {
"/health",
"meeting/v2/org-user/**"
};

@Bean
@Profile("dev")
SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf((csrfConfig) -> csrfConfig.disable())
.cors(Customizer.withDefaults())
.sessionManagement(
(sessionManagement) -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint));
return http.build();
}
@Bean
@Profile("dev")
SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf((csrfConfig) -> csrfConfig.disable())
.cors(Customizer.withDefaults())
.sessionManagement(
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint));
return http.build();
}

@Bean
@Profile("prod")
SecurityFilterChain prodSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf((csrfConfig) -> csrfConfig.disable())
.cors(Customizer.withDefaults())
.sessionManagement(
(sessionManagement) -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint));
return http.build();
}
@Bean
@Profile("prod")
SecurityFilterChain prodSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf((csrfConfig) -> csrfConfig.disable())
.cors(Customizer.withDefaults())
.sessionManagement(
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint));
return http.build();
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(
Arrays.asList("https://playground.sopt.org/", "http://localhost:3000/",
"https://sopt-internal-dev.pages.dev/"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE", "OPTIONS"));
configuration.addAllowedHeader("*");
configuration.setAllowCredentials(false);
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(
Arrays.asList("https://playground.sopt.org/", "http://localhost:3000/",
"https://sopt-internal-dev.pages.dev/"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PATCH", "DELETE", "OPTIONS"));
configuration.addAllowedHeader("*");
configuration.setAllowCredentials(false);

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

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package org.sopt.makers.crew.main.entity.user;

import java.util.Optional;
import org.sopt.makers.crew.main.common.exception.UnAuthorizedException;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Integer> {

Optional<User> findByOrgId(Integer orgId);

default User findByIdOrThrow(Integer userId) {
return findById(userId)
.orElseThrow(() -> new UnAuthorizedException());
}

default User findByOrgIdOrThrow(Integer orgUserId) {
return findByOrgId(orgUserId)
.orElseThrow(() -> new UnAuthorizedException());
}
}

0 comments on commit 0081c1d

Please sign in to comment.