2016-07-04 2 views
0

안녕하세요, 내 애플리케이션의/resources 폴더에 프런트 엔드를 포함하려고합니다. 내 디렉토리 구조는 다음과 같다 :스프링 보안은/resources 아래의 파일에 액세스 할 수 없습니다.

src 
    main 
    java // backend located here 
    webapp 
    resource //my html/css/js 

내가 백엔드의 보안을 위해 OAuth를 사용하고 있습니다 : ResourceServerConfigurerAdapter.java

@Configuration 

    @EnableResourceServer 
    public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 

     @Override 
     public void configure(final HttpSecurity http) throws Exception { 

      http.authorizeRequests() 
        .antMatchers("/resources/**").permitAll().and() 
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) 
        .and().authorizeRequests().anyRequest().authenticated(); 

     } 
    } 

ResourceWebConfig

MethodSecurityConfig.java

@Configuration 
@EnableGlobalMethodSecurity(prePostEnabled = true) 
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration { 

    @Override 
    protected MethodSecurityExpressionHandler createExpressionHandler() { 
     return new OAuth2MethodSecurityExpressionHandler(); 
    } 

} 

.java

@Configuration 
@EnableWebMvc 
@ComponentScan({"eu.emif.resource.web"}) 
public class ResourceWebConfig extends WebMvcConfigurerAdapter { 
    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     registry 
       .addResourceHandler("/resources/**") 
       .addResourceLocations("(/resources/"); 
    } 
} 

은 내가

<oauth> 
<error_description> 
Full authentication is required to access this resource 
</error_description> 
<error>unauthorized</error> 
</oauth> 

도움말이 많이 주시면 감사하겠습니다 얻고있다 http://localhost:8082/style.css 또는 http://localhost:8082/resources/style.css 로 이동하려고 할 때마다.

+0

당신이 받는다는 사용하고 있습니까? – Keshav

+0

예 내 백엔드가 Maven을 사용합니다. –

답변

1

변경 다음과 같이하는 디렉토리 구조 :

src 
    main 
    java // backend located here 
    resources(By default these files are not added in deployment assembly and mostly used for loading java resources like xml file,properies file etc.) 
    webapp 
    resource(create new folder here and put your frontend(html/js/css) files here) 
+0

그는 지금 그걸 찾은 것 같지만 아직 허가받지 못하고 있습니다. 내 질문을 업데이트했습니다. –

+0

http://stackoverflow.com/questions/26881296/spring-security-oauth2-full-authentication-is-required-to-access-this-resource. – Keshav