我使用spring-boot-starter 0.5.0.M6和spring security来构建我的应用程序,其中包含:
"/ admin / "**:任何人都可以访问角色ADMIN,基于表单的登录
"/ api / "**:任何人都应该可以访问角色API,http基本登录
我的第一次尝试是:
@Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/resources/**").permitAll() .antMatchers("/admin/**").hasRole("ADMIN") .and() .formLogin() .defaultSuccessUrl("/admin/home") .loginPage("/login") .permitAll() .and() .logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET")) .permitAll(); http .authorizeRequests() .antMatchers("/api/**").hasRole("API") .and() .httpBasic(); }
用这种方法:
所有"/ admin/"和"/ api / "都可以使用基本和基于表单的登录进行身份验证.这不是一个关键问题.
发生任何安全问题时,例如:身份验证失败或授权失败,将显示登录表单.这是一个关键问题,我想如果/ api/**认证失败或授权失败,它会显示带有401/403状态代码的基本认证弹出窗口.
然后我尝试使用解决方案https://github.com/spring-projects/spring-security-javaconfig/blob/master/samples-web.md#sample-multi-http-web-configuration
,但我只能确保其中任何一个/api/**
,/admin/**
但不是两个,取决于我注释的那个@Order
.
请帮我一把
非常感谢