Philosophie de mon application est venue de cette article. Selon ce que je faisais classe Configuration:Obtenir 403 erreur avec GWT + Spring Security
@Configuration
public class SpringForGwtConfig {
@Bean
public HandlerMapping simpleUrlHandlerMapping() {
SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping();
Map<String, Controller> map = new HashMap<>();
map.put("/notes/notes.rpc", notesGwtController());
simpleUrlHandlerMapping.setUrlMap(map);
return simpleUrlHandlerMapping;
}
@Bean
public ServletRegistrationBean gwtServlet() {
return new ServletRegistrationBean(notesGwtController(), "/notes/notes.rpc");
}
@Bean
public NotesGwtController notesGwtController() {
NotesGwtController notesGwtController = new NotesGwtController();
notesGwtController.setRemoteService(notesService());
return notesGwtController;
}
@Bean
public NotesGwtService notesService() {
return new NotesGwtServiceImpl();
}
}
et le contrôleur qui utilise (je l'espère) modèle « stratégie » pour les demandes de codage et de décodage à (de) ressort servlet répartiteur.
public class NotesGwtController extends RemoteServiceServlet implements Controller, ServletContextAware {
private ServletContext servletContext;
private RemoteService remoteService;
private Class remoteServiceClass;
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
super.doPost(request, response);
return null;
}
@Override
public String processCall(String payload) throws SerializationException {
try {
RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass);
// delegate work to the spring injected service
return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters());
} catch (IncompatibleRemoteServiceException exception) {
getServletContext()
.log(
"An IncompatibleRemoteServiceException was thrown while processing this call.",
exception
);
return RPC.encodeResponseForFailure(null, exception);
}
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
public void setRemoteService(RemoteService remoteService) {
this.remoteService = remoteService;
this.remoteServiceClass = this.remoteService.getClass();
}
}
J'ai donc contrôleur de sécurité, qui cartes ("/ notes") et de le rendre (grâce à thymeleaf) à localhost: 8080/notes.html. Et la page retourne. C'est cool. Mais quand j'ouvre la console dans le navigateur, il contient cette erreur: POST http://localhost:8080/notes/notes/notes.rpc 403() Cette erreur ne me laisse pas faire des demandes asynchrones au service de RPC gwt.
Dans ma configuration de sécurité I ajouté cartographie:
http
.authorizeRequests()
.antMatchers("/").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')")
.antMatchers("/api/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/notes").authenticated()
.antMatchers("/notes/notes.rpc").anonymous()
Mais l'erreur n'a pas disparu. Donc, la question est "pourquoi est-ce?" et "Peut être" ma "philosophie pas si bien?"