在具体
我想只为特定的URL模式进行HTTP基本身份验证.
详细地
我正在为我的应用程序创建一个API接口,需要通过简单的HTTP基本身份验证进行身份验证.但是其他网页不应该使用HTTP basic,而应该使用普通的表单登录.
当前配置 - 不工作
@Override
protected void configure(HttpSecurity http) throws Exception {
http //HTTP Security
.csrf().disable() //Disable CSRF
.authorizeRequests() //Authorize Request Configuration
.antMatchers("/connect/**").permitAll()
.antMatchers("/", "/register").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/api/**").hasRole("API")
.anyRequest().authenticated()
.and() //HTTP basic Authentication only for API
.antMatcher("/api/**").httpBasic()
.and() //Login Form configuration for all others
.formLogin().loginPage("/login").permitAll()
.and() //Logout Form configuration
.logout().permitAll();
}
Run Code Online (Sandbox Code Playgroud) 在我的团队中,我们使用Spring Boot编写了Spring应用程序+ SAPUI5门户.Web应用程序分为三个不同的位置,例如:
webapp: - app1 - app2 - app3
为了访问这些应用程序,我们实现了登录页面.根据用户角色,我们将用户重定向到确切的应用.
我的spring应用程序安全性如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/app1/**/*.*")
.permitAll()
.antMatchers("/register.html")
.permitAll()
//
.antMatchers("/app2/*.*")
.hasRole("USER")
//
//
.antMatchers("/login*")
.permitAll()
.antMatchers("/soap/*")
.permitAll()
.antMatchers("/postLogin")
.authenticated()
//
.antMatchers("/app3/*")
//.permitAll()
.hasRole("ADMIN")
//
.anyRequest()
.authenticated()
// log in
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=loginError")
.defaultSuccessUrl("/postLogin")
// logout
.and().logout().logoutUrl("/**/logout")
.logoutSuccessUrl("/login").deleteCookies("JSESSIONID").and()
.csrf()
.disable()
Run Code Online (Sandbox Code Playgroud)
当然我们上课有重定向.现在我们必须提供每个应用程序,不同的登录页面.我尝试将spring security配置为在不同页面上接受多个登录表单,但它不起作用.可能吗?我阅读了文档,但它没有结果.