외부 static resource 서비스 추가

master
mjkhan21 1 year ago
parent 8210977f0d
commit cb904e14ba

@ -1,5 +1,7 @@
package cokr.xit.base.boot; package cokr.xit.base.boot;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -18,6 +20,7 @@ import cokr.xit.base.security.authentication.web.AuthenticationExtraDetailsSourc
import cokr.xit.base.security.authentication.web.AuthenticationFailure; import cokr.xit.base.security.authentication.web.AuthenticationFailure;
import cokr.xit.base.security.authentication.web.AuthenticationSuccess; import cokr.xit.base.security.authentication.web.AuthenticationSuccess;
import cokr.xit.base.security.authentication.web.LogoutSuccess; import cokr.xit.base.security.authentication.web.LogoutSuccess;
import cokr.xit.foundation.boot.StaticResourceConfig;
import cokr.xit.foundation.web.ExceptionController; import cokr.xit.foundation.web.ExceptionController;
/**spring security /**spring security
@ -26,6 +29,11 @@ import cokr.xit.foundation.web.ExceptionController;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
public class SecurityConfig { public class SecurityConfig {
@Autowired
private ExceptionController exceptionController;
@Resource(name = "staticResource")
private StaticResourceConfig staticResource;
/**SecurityFilterChain . /**SecurityFilterChain .
* @param http http-security * @param http http-security
* @return SecurityFilterChain * @return SecurityFilterChain
@ -34,7 +42,7 @@ public class SecurityConfig {
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(conf -> http.authorizeHttpRequests(conf ->
conf.antMatchers("/resources/**", "/files/**", "/login.do", "/logout.do", "/error/*.do").permitAll() conf.antMatchers("/login.do", "/logout.do", "/error/*.do").permitAll()
.antMatchers("/**/*.do").access(authorizationManager()) .antMatchers("/**/*.do").access(authorizationManager())
.anyRequest().authenticated() .anyRequest().authenticated()
) )
@ -65,16 +73,13 @@ public class SecurityConfig {
return http.build(); return http.build();
} }
@Autowired
private ExceptionController exceptionController;
/**WebSecurityCustomizer .<br /> /**WebSecurityCustomizer .<br />
* url /resources/** . * url /resources/** .
* @return WebSecurityCustomizer * @return WebSecurityCustomizer
*/ */
@Bean @Bean
public WebSecurityCustomizer webSecurityCustomizer() { public WebSecurityCustomizer webSecurityCustomizer() {
return conf -> conf.ignoring().antMatchers("/resources/**"); return conf -> conf.ignoring().antMatchers(staticResource.getURLs(null));
} }
/**AuthenticationSuccess( ) . /**AuthenticationSuccess( ) .

Loading…
Cancel
Save