首页 文章

Spring boot mvc(rest)angularJS:添加安全性

提问于
浏览
0

我有一个单独的正面和背面的Web应用程序:

/project  
+--- /back
+--- /front

后面是使用Spring启动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 中的_1004685应该怎么做?默认情况下,Spring Security会生成默认登录表单 . 我不需要在应用程序的后面,因为它是负责显示loginPage的前端 . 如何跳过后面的登录页面?也许通过将用户名和密码放在JSON文件中,前端发送到后面?有人知道怎么做吗?

我正在使用Java配置Spring(不是XML配置) .

2 回答

相关问题