I am wondering what the best way is to setup a project that contains a Spring RESTful API along with the ability to serve up static Angularjs pages to consume the RESTful web service. The below implementation works but I am now looking to add security into the application and I am unsure how to apply Spring Security to both the REST Api and the static pages.
- Is the below setup correct for my end goal?
- How do I secure both the REST Api && the static pages?
I have the following project structure
Servlet Config
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
@ComponentScan
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.addFilter("corsFilter", new CORSFilter());
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebMvcConfig.class);
ctx.setServletContext(servletContext);
Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
dynamic.addMapping("/api/*");
dynamic.setLoadOnStartup(1);
}
}
Aucun commentaire:
Enregistrer un commentaire