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

无法在spring boot security中使用基本auth登录

楚知
2023-03-14

当我试图使用inmemory用户名和密码登录时,它总是抛出无效。

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .csrf().disable()
        .authorizeRequests()
        .anyRequest()
        .authenticated()
        .and()
        .httpBasic();
    }
    
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth)
            throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }

在此处输入图像描述

即使我输入了正确的用户名和密码,这个对话框也总是会出现。

共有1个答案

安明亮
2023-03-14

这里是configureGlobal(.....)我们需要使用像BCryptPasswordEncoder那样的passwordEncoder,或者如果我们不想使用任何密码编码器,那么我们必须编写像password(“{noop}password”){noop}意味着使用NoOpPasswordEncoder来验证此密码。

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

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication()
    .withUser("user").password("{noop}password").roles("USER");
}
 类似资料:
  • 我使用的是Laravel5.0。我只想使用用户名(无密码)登录,因为我正在使用单点登录访问我的Laravel项目,因此如果用户单点登录成功,它将检查我的数据库,以确定登录用户的用户名是否已注册。 我已经找了一整天,但我仍然找到了线索。 我有一个错误: 传递给Illumb\Auth\Guard::login()的参数1必须实现接口Illumb\Contracts\Auth\Authenticatab

  • 我正在使用laravel 5.4,Auth::login($user)显示类型错误: 传递给Illumb\Auth\SessionGuard::login()的参数1必须实现接口Illumb\Contracts\Authenticatable,给定的Illumb\Database\Eloquent\Builder实例,在第294行的/home/vendor/laravel/framework/sr

  • null 是否有任何不使用基于表单的auth的条件?

  • 我们正在使用WP JWT Auth插件从wp rest API将用户登录到WordPress。WP JWT Auth插件需要密码才能获取令牌,现在当我们集成Facebook登录时,我不确定如何让用户登录,因为我们不会有来自Facebook的密码。 有什么建议吗?

  • 我在Windows 10上使用Git for Windows,我使用GitExtension作为我的GUI。为了向各种Git存储库进行身份验证,我使用putty/pageant并将我的密钥加载到其中。GitExtension以某种方式与此配合使用。最近,我在https://gitlab.example.com遇到了一个Git存储库,GitExtension试图在其中执行并告诉我:我还尝试使用git

  • 我使用Python中的Selenium模块登录Quora。它在Facebook上很好用,但在Quora上尝试时,我在行出现了一个错误: 回溯(最近调用最后一次):文件“”,第1行,在password.send_keys('my_password')文件“C:\python27\lib\site-packages\selenium\webdriver\remote\webdriment.py”,第2