【发布时间】:2015-04-26 15:14:50
【问题描述】:
我想知道最好的方法是设置一个包含 Spring RESTful API 以及提供静态 Angularjs 页面以使用 RESTful Web 服务的能力的项目。以下实现有效,但我现在希望在应用程序中添加安全性,但我不确定如何将 Spring Security 应用于 REST Api 和静态页面。
- 以下设置是否适合我的最终目标?
- 如何保护 REST Api 和静态页面?
我有以下项目结构
Servlet 配置
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);
}
}
【问题讨论】:
标签: angularjs spring rest maven spring-security