İlkbahar MVC projemde basit bir form aracılığıyla bir dosya yüklemeye çalışıyorum.Dosya İadesi Yükleniyor 403 Hata - Bahar MVC
HTML Form:
<form method="POST" enctype="multipart/form-data" action="/upload">
<label>Select File</label>
<input type="file" name="file"/>
</form>
My Denetleyici:
@Controller
public class FileController {
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(
@RequestParam("name") String name,
@RequestParam("file") MultipartFile file){
if (!file.isEmpty()) {
try {
//do stuff
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
}
Güvenlik Yapılandırma: Bir 403: Forbidden
hatası alıyorum ve benim 403.html yönlendirildi am Ancak
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/upload").permitAll()
.and()
.exceptionHandling().accessDeniedPage("/403")
}
}
görmek her süre
Şimdiye kadar ayrı bir sınıfta başlatılır Bahar Güvenlik filtresi önce MultipartFilter
belirterek çalıştı, ancak ettik hayır şans
public class SecurityApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
insertFilters(servletContext, new MultipartFilter());
}
}
Herhangi bir fikir?
GÜNCELLEME:
@Configuration
@Import({ WebSecurityConfig.class })
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
System.out.println(":::Starting My App:::");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(WebMVCConfig.class);
context.setServletContext(servletContext);
context.setConfigLocation("com.myApp.configuration");
}
}
Ben 403 hata ile aşağıdaki döndürür servlet isteği niteliklerin bir listesi var benim WebAppInitializer dahildir:
javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
__spring_security_scpf_applied
org.springframework.web.servlet.DispatcherServlet.THEME_SOURCE
SPRING_SECURITY_403_EXCEPTION
org.springframework.web.servlet.DispatcherServlet.THEME_RESOLVER
springMacroRequestContext
themes
thymeleafEvaluationContext
org.springframework.security.web.FilterChainProxy.APPLIED
_csrf
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.FILTERED
[email protected]ED
beans
springRequestContext
org.springframework.web.servlet.HandlerMapping.introspectTypeLevelMapping
org.springframework.web.servlet.DispatcherServlet.FLASH_MAP_MANAGER
org.springframework.web.servlet.DispatcherServlet.CONTEXT
org.springframework.core.convert.ConversionService
execInfo
org.springframework.web.servlet.HandlerMapping.pathWithinHandlerMapping
org.springframework.web.context.request.async.WebAsyncManager.WEB_ASYNC_MANAGER
org.springframework.web.servlet.resource.ResourceUrlProvider
org.springframework.web.servlet.DispatcherServlet.OUTPUT_FLASH_MAP
org.springframework.web.servlet.HandlerMapping.bestMatchingPattern
org.springframework.security.web.csrf.CsrfToken
org.springframework.web.servlet.DispatcherServlet.LOCALE_RESOLVER
Güncelleme # 2: Bu kesinlikle bir CSRF konudur ; Ben benim WebSecurityConfig
yılında şunlardır yaptığımda herhangi 403
.csrf().disable()
web.xml dosyanızı nasıl yapılandırdınız veya DispatcherServlet için WebApplicationInitializer'ı kullanıyor musunuz? Bu kodu gönderebilir misin? Ayrıca, html formunu yüklemek için kullandığınız URL'den de bahset. – Raghu
Bu bir CSRF hatası mı? – holmis83
@Raghu WebAppInitializer'ımı ekledim - formumun URL'si, tüm Thymeleaf görünümlerinin çözüldüğü/WEB-INF/html klasöründe. Ve holmis83 Evet olduğuna inanıyorum –