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

我把基本身份验证放在Spring启动中,但是我们如何在没有身份验证登录的情况下访问一些Api

吉栋
2023-03-14

根据标题,我在spring boot中加入了一些基本的身份验证,但是我们如何在没有身份验证登录的情况下访问一些API呢

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
      .authorizeRequests()
      .anyRequest()
      .authenticated()
      .and()
      .httpBasic();
}

共有2个答案

殳睿
2023-03-14

过滤掉 API 并允许所有 API 无需身份验证

示例

.antMatchers(GET, “/home”,“/health”).permitAll()

这将允许在2个endpoint上对所有请求进行GET请求,即使没有身份验证

完整示例

   http
        .authorizeRequests()
        .antMatchers(GET, "/home","/health").permitAll()
        .anyRequest()
        .authenticated()
        .and()
        .httpBasic();

注意:需要考虑订购

卜泓
2023-03-14
http.ignoring().antMatchers("/authFailure");

我们可以像上面一样忽略特定的URL路径。

看看这个。

 类似资料:
  • 我所期望的是:当用户从表单登录时,它可以调用restful服务,而无需经过基本身份验证(因为它已经经过身份验证)。我的想法是,角色为'role_user'的用户也应该调用restful服务。但是,当我从表单登录后,我也被提示进行基本身份验证,试图从浏览器调用restful服务。 有没有得到我所期望的?

  • 使用,https://github.com/firebase/FirebaseUI-Android/tree/master/codelabs/chat作为登录的参考,我在键入时似乎遇到了问题 我只能键入Auth的提供者,而不能键入,为什么会这样,它提示我键入社会提供者。

  • http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd“>

  • 我正在尝试使用OAuth2实现开发一个带有Spring Security性的rest api。但是如何删除基本身份验证呢。我只想向body发送用户名和密码,并在postman上获取令牌。 要删除基本身份验证,并从邮递员的get token中发送body标记中的用户名密码吗 我遇到了一些问题{"错误":"未经授权","error_description":"没有客户端身份验证。尝试添加适当的身份验证

  • 但我对spring-boot/java还是个新手...有谁能帮我把这条路走对吗? 多谢了。

  • 我在我的微服务中使用Spring Security基本身份验证来验证客户端,我向消费者提供了我将返回响应作为响应实体 我扩展了BasicAuthenticationEntryPoint,将自己的身份验证入口点自定义为MyBasicAuthenticationEntryPoint。然后抛出一个异常并尝试从@ExceptionHandler处理。但是,这不起作用。此外,我用@ControllerAdv