当前位置: 首页 > 知识库问答 >
问题:

在Spring Security中使用Spring-boot-starter混合HttpBasic和FormLogin

赵越
2023-03-14

我使用带有spring security的spring-boot-starter 0.5.0.M6构建我的应用程序,该应用程序包含:

  1. “/ADMIN/”**:任何具有角色ADMIN的人都可以访问,基于表单的登录
  2. “/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();
}
    null

请帮我一把。

多谢

共有1个答案

靳涵亮
2023-03-14

对于api部分,请使用以下代码。请注意,第一个ant匹配器限制了这个安全配置所过滤的范围。这是我一开始从你的参考资料中不明白的部分。

@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        // the ant matcher is what limits the scope of this configuration.
        http.antMatcher("/api/**").authorizeRequests()
            .antMatchers("/api/**").authenticated()
            .and().httpBasic().realmName("Sourcing API");
    }
}
 类似资料:
  • 我正在尝试一个安全Webflux配置,在这里我可以使用httpBasic登录一些资源,并使用oAuth登录其他资源 到目前为止,我还不知道该怎么做;似乎,在非反应性的方式中,可以使用某种领域名称或其他什么来实现,但在反应性的方式中,这并不存在,我认为这是因为它与线程的工作流或与web过滤器链中的工作流相关 但是我现在在科特林有以下几点, 检查noAuthPaths和basicAuthPaths是否

  • 引入 Maven 依赖 <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> <version>${shardingsphere.version}</version> </d

  • 引入 Maven 依赖 <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> <version>${shardingsphere.version}</version> </d

  • 引入 Maven 依赖 <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> <version>${shardingsphere.version}</version> </d

  • 1.导入jar包 web.xml spring-security.xml

  • 我们面临的问题是关于大小,我们意识到spring-boot-started占用了大量MB,而我们有另一个应用程序只使用:和,大小从50MB跳到10MB。 假设我们只使用Tomcat,除了使用的开发之外,如果删除会发生什么?我是否可以拥有一个只有和但仍然能够在开发过程中使用的应用程序?