Skip to content

Commit

Permalink
feature: admin 권한 path 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
choihuk committed Dec 13, 2023
1 parent 6fd55a1 commit 1ae0670
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package aplus.insurancesystem.common.config;

import java.util.Arrays;
import java.util.List;

import org.springframework.context.annotation.Bean;
Expand All @@ -14,13 +15,16 @@
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import aplus.insurancesystem.common.security.AplusAccessDeniedHandler;
import aplus.insurancesystem.common.security.AplusAuthenticationFailureHandler;
import aplus.insurancesystem.common.security.AplusAuthenticationSuccessHandler;
import aplus.insurancesystem.common.security.RoleToPath;
import aplus.insurancesystem.domain.customer.entity.customer.Role;

@Configuration
@EnableWebSecurity
Expand Down Expand Up @@ -55,10 +59,13 @@ public AuthenticationEntryPoint authenticationEntryPoint() {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((auth) -> auth
// .requestMatchers("/customer/**").hasRole(Role.CUSTOMER.name())
// .requestMatchers("/admin").hasRole(Role.ADMIN.name())
.requestMatchers("/**").permitAll()
.anyRequest().authenticated()
.requestMatchers(
Arrays.stream(RoleToPath.ADMIN_URL.values())
.map(path -> new AntPathRequestMatcher(path.getUrl(), path.getMethod()))
.toArray(AntPathRequestMatcher[]::new)
).hasRole(Role.ADMIN.name())
.requestMatchers("/**").permitAll()
.anyRequest().authenticated()
)
.csrf(AbstractHttpConfigurer::disable)
.cors((cors) -> cors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
package aplus.insurancesystem.common.security;

import static org.springframework.http.HttpMethod.*;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

public class RoleToPath {

private static final String CUSTOMER_URL = "/customers";
private static final String INSURANCE_URL = "/insurances";
private static final String TERMS_URL = "/terms";
private static final String CONTRACT_URL = "/contracts";
private static final String PAYMENT_URL = "/payments";
private static final String INSURANCE_APPLICATION_URL = "/insurance-applications";
private static final String BASE_URL = "/api";

private static final String CUSTOMER_URL = BASE_URL + "/customers";
private static final String INSURANCE_URL = BASE_URL + "/insurances";
private static final String INSURANCE_APPLICATION_URL = BASE_URL + "/insurance-applications";
private static final String SURVEY_URL = BASE_URL + "/survey";
private static final String COMPENSATION_CLAIM = BASE_URL + "/compensation-claim";

@Getter
@RequiredArgsConstructor
public enum ADMIN_URL {
CUSTOMER_GRANT_AUTHORITY(CUSTOMER_URL + "/{id}/admin", GET.name()),
CUSTOMER_ALL(CUSTOMER_URL + "/all", GET.name()),
CUSTOMER_CONTRACT_MAINTENANCE(CUSTOMER_URL + "/contract-maintenance", GET.name()),
INSURANCE_DESIGN(INSURANCE_URL + "/design", POST.name()),
INSURANCE_REGISTER(INSURANCE_URL + "/{id}/register", POST.name()),
INSURANCE_MODIFY(INSURANCE_URL + "/{id}", PUT.name()),
INSURANCE_DELETE(INSURANCE_URL + "/{id}", DELETE.name()),
SURVEY(SURVEY_URL + "/{ccid}", POST.name()),
COMPENSATION_CLAIM_ALL(COMPENSATION_CLAIM + "/all", GET.name()),
INSURANCE_APPLICATION(INSURANCE_APPLICATION_URL, GET.name()),
INSURANCE_APPLICATION_APPROVAL(INSURANCE_APPLICATION_URL + "/{id}/approval", POST.name()),
INSURANCE_APPLICATION_REJECTION(INSURANCE_APPLICATION_URL + "/{id}/rejection", POST.name());

private final String url;
private final String method;
}
}

0 comments on commit 1ae0670

Please sign in to comment.