【发布时间】:2015-09-01 00:52:58
【问题描述】:
我有一个前后分开的 Web 应用程序:
/project
+--- /back
+--- /front
背面使用Spring boot + Spring MVC开发,正面使用AngularJS开发。
我正在尝试为后/前之间的通信设置安全性。我做了什么:
- create a ConfigSecurity class which extends from WebSecurityConfigurerAdapter
- create a SpringWebMvcInitializer which extends from AbstractAnnotationConfigDispatcherServletInitializer and call ConfigSecurity
- create a SecurityWebInitializer class which extends AbstractSecurityWebApplicationInitializer
我的 ConfigSecurity 如下所示:
@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ConfigSecurity extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/demo/**","/home").permitAll()
.anyRequest().fullyAuthenticated()
.and()
.formLogin().loginPage("...")
.and()
.httpBasic();
}
}
我的问题:
在
configureGlobal()中,我可以设置用户名和密码来访问我受保护的网址,但如果不是只有一个用户,我该怎么办?我的意思是,我想授予在我的数据库中注册的所有用户的访问权限。既然后端和前端只是和REST通信(通过JSON文件),那么
ConfigSecurity中的formLogin()应该怎么做呢?默认情况下,Spring Security 会生成一个默认登录表单。我不需要它在应用程序的后面,因为它是负责显示 loginPage 的前面。如何跳过后面的登录页面?也许通过将用户名和密码放在前面发送到后面的 JSON 文件中?有人知道怎么做吗?
我正在为 Spring 使用 Java 配置(不是 XML 配置)。
【问题讨论】:
-
请查看本教程spring.io/blog/2015/01/12/… 它应该解释如何从 AngularJS 应用程序登录。
标签: angularjs spring spring-mvc spring-security spring-boot