1
임 파일 업로드를하려고 노력 (RestController를 통해 또한 컨트롤러와 시도했다) (404있어)하지만, 항상이 앞에 리버스 프록시SpringSecurity 뒤에 RestController에 파일 업로드를 할 수 없습니다
이 404 반환 이 앱의 엔트리 포인트는/v2/service입니다.
다른 모든 API 호출은이 파일 업로드를 제외하고는 정상적으로 작동합니다. 제발 조언.
내 구성
@Configuration
@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class, MultipartConfigElement.class })
@ConditionalOnProperty(prefix = "multipart", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(MultipartProperties.class)
public class MultipartAutoConfiguration {
@Autowired
private MultipartProperties multipartProperties = new MultipartProperties();
@Bean(name="multipartResolver")
public CommonsMultipartResolver getResolver() throws IOException{
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setMaxUploadSizePerFile(1242880);
return resolver;
}
@Bean
@ConditionalOnMissingBean
public MultipartConfigElement multipartConfigElement() {
return this.multipartProperties.createMultipartConfig();
}
@Bean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
@ConditionalOnMissingBean(MultipartResolver.class)
public StandardServletMultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}
}
그리고 내 컨트롤러 : (내가 모두가 나에게 (404)를 준, RestController 및 컨트롤러 시도)
@RestController
public class UploadController {
@Autowired
private ImageService imageService;
@RolesAllowed({ "ROLE_USER" })
@RequestMapping(value="/api/item/image/u", method=RequestMethod.POST)
public String handleFileUpload(@RequestPart("file") MultipartFile file) throws ImageSizeException, IOException{
System.out.println("Upload start : ");
returns "YEY";
}
}
내 봄 보안 설정의 조각 :
@Configuration
public class OAuth2ServerConfiguration {
private static final String RESOURCE_ID = "batmanservice";
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends
ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) {
// @formatter:off
resources.resourceId(RESOURCE_ID);
// @formatter:on
}
@Override
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/api").hasRole("USER")
.antMatchers("/batsearch").anonymous();
http.csrf().disable();
// @formatter:on
}
}
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends
AuthorizationServerConfigurerAdapter {
private TokenStore tokenStore = new InMemoryTokenStore();
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
private UserService userService;
@Autowired
private CustomUserDetailsService userDetailsService;
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer
.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
// @formatter:off
endpoints
.tokenStore(this.tokenStore)
.authenticationManager(this.authenticationManager)
.userDetailsService(this.userDetailsService);
// @formatter:on
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// @formatter:off
clients
.inMemory()
.withClient("batclient")
.authorizedGrantTypes("password", "authorization_code", "refresh_token")
.authorities("ROLE_USER")
.scopes("read", "write", "trust")
.accessTokenValiditySeconds(18000)
.resourceIds(RESOURCE_ID)
.secret("batmansecret");
// @formatter:on
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setSupportRefreshToken(true);
tokenServices.setTokenStore(this.tokenStore);
return tokenServices;
}
}
}
우편 배달부를 사용하여 테스트 한 결과는 다음과 같습니다. 0 이다는 :
POST /v2/service/api/item/image/u?access_token=9105dbcd-00a4-4614-aa69-a53e83bc356e HTTP/1.1
Host: localhost:8080
Authorization: Basic YzNidTRwcDBuZTpGRjAxNURFQUQwNjVBMEEw
Cache-Control: no-cache
Postman-Token: 2ad8977e-842e-c442-e480-9004b9d21854
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename=""
Content-Type:
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=""
------WebKitFormBoundary7MA4YWxkTrZu0gW--
@Himanshu. 사실 나는이 애플 리케이션 앞에있는 역방향 프록시 (따라서/v2/서비스) 언급하는 걸 깜빡. – xtrycatchx