考虑在配置中定义“org.springframework.security.authentication.AuthenticationManager”类型的 bean

2024-01-07

我遵循了这里提到的一些建议,但它对我不起作用。因此,将问题放在这里

  1. 如何在自定义过滤器中使用 Java 配置注入 AuthenticationManager https://stackoverflow.com/questions/21633555/how-to-inject-authenticationmanager-using-java-configuration-in-a-custom-filter/21639553#21639553
  2. Spring 需要一个“AuthenticationManager”类型的 bean https://stackoverflow.com/questions/49473634/spring-required-a-bean-of-type-authenticationmanager

谁能指导我有什么问题以及如何解决这个问题?

Error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field authenticationManager in com.techprimers.security.springsecurityauthserver.config.AuthorizationServerConfig required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration.

授权服务器配置.java

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {

        security.tokenKeyAccess("permitAll()")
                .checkTokenAccess("isAuthenticated()");
    }


    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients
                .inMemory()
                .withClient("ClientId")
                .secret("secret")
                .authorizedGrantTypes("authorization_code")
                .scopes("user_info")
                .autoApprove(true);
    }


    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

        endpoints.authenticationManager(authenticationManager);
    }
}

资源服务器配置.java

@EnableResourceServer
@Configuration
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    @Qualifier("authenticationManagerBean")
    private AuthenticationManager authenticationManager;
    @Autowired
    private UserDetailsService customUserDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.requestMatchers()
                .antMatchers("/login", "/oauth/authorize")
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .formLogin()
                .permitAll();
    }


    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.parentAuthenticationManager(authenticationManager)
                .userDetailsService(customUserDetailsService);
    }
}

代码参考取自https://github.com/TechPrimers/spring-security-oauth-mysql-example https://github.com/TechPrimers/spring-security-oauth-mysql-example,仅将 Spring Boot 父版本更新为2.0.4.RELEASE,事情开始破裂。


这似乎是 Spring Boot 2.0 引入的“重大变化”之一。我相信您的案例描述于Spring Boot 2.0 迁移指南 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#authenticationmanager-bean.

In your WebSecurityConfigurerAdapter你需要重写的类authenticationManagerBean方法并注释它@Bean, i.e.:

@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

考虑在配置中定义“org.springframework.security.authentication.AuthenticationManager”类型的 bean 的相关文章

随机推荐

  • 在 C++ 中使用 C# 接口或在 C# 中使用 C++ 接口

    我正在开发一个解决方案 其中有一个必须由 C 解决方案和 C 解决方案使用的接口 C 语言 我想知道 实现这一目标的最佳方法是什么 我在 C 项目中使用的 C 接口 我将在 C 项目中使用的 C 接口 您还可以指示我应该如何进行最佳解决方案
  • 张量流中的Python_io

    我在使用张量流时遇到问题 我想用TFRecordWriter 如下 with tf python io TFRecordWriter testing filename as tfrecord writer do sth 但我收到错误 Att
  • 如何求多个矩阵中对应元素的最大值?

    我有四个具有相同维度的矩阵 比方说 A 1 2 5 4 2 9 B 4 5 9 8 0 1 C 5 3 9 0 4 0 D 5 9 1 0 9 3 如何求四个矩阵中所有对应元素的最大值 在我的示例中 结果应如下所示 maxABCD 5 9
  • 如何在matlab中为条形图添加数据标签

    例如 代码 x 3 6 2 9 5 1 bar x 为此 我需要在每个栏的顶部添加数据标签 我知道我必须使用 TEXT 关键字 但我不知道如何实现它 这是一个简单的解决方案text x 3 6 2 9 5 1 bar x ylim 0 ma
  • 批量更新 Jenkins 项目的最佳方法是什么?

    我们有数百个 Jenkins 项目 大部分是从几个模板创建的 通常需要对所有项目进行相同的更改 例如今天我需要添加一个构建后步骤以在最后删除工作区 接下来 我需要更改将构建结果复制到 Nexus 存储库的共享驱动器的步骤 将此类批量更改应用
  • VSCode Intellisense 在 Javascript 代码上奇怪的自动完成

    我刚刚使用 VSCode 编写 JS 文件时遇到了一些奇怪的行为 看到我正在尝试访问hasOwnProperty 蓬松物体上的方法 VSCode 不会自动完成或建议我的代码行中的任何内容 此时我已经认为我做错了什么 并且我可能无法通过我的对
  • 使用jquery解析部分html字符串

    I use ajax 从我的服务器获取一些 HTML 页面 返回包含完整的 HTML 结果 但我只对该文档中的一个非常具体的 div 感兴趣 唯一给出的事情是我的 ajax success 函数返回一个 JSON 对象 我制作了一个 PHP
  • 如何在 Flask 中缓存大型机器学习模型?

    这是我面临的情况 我刚刚编写了一个 Flask 应用程序 人们可以输入他们想要的文本评论 我的应用程序将从我们的数据集中返回最相似的评论 所以基本上这是一个 NLP 项目 机器学习模型已经训练好了 现在的问题是该模型大约有 2 5GB 每次
  • 替换二维数组的列值中的子字符串

    我正在尝试使用str replace 删除 我的 出于value4数组数组中的元素 然而 str replace my myarray 并没有改变任何东西 Does str replace 不适用于二维数组 我的示例数据和编码尝试 arra
  • TransactionScope/SqlTransaction 超时扩展

    一旦事务开始 是否可以延长事务的超时 使用 SQL Server 超时对于 SQL Server 来说是 外部 的 因此 SQL Server 无法影响它 所以不幸的是 不
  • 如何将字典绑定到gridview?

    是否可以自动将字典绑定到 Gridview 我最接近的是 Dictionary
  • 浏览器是否跟踪活动计时器 ID?

    浏览器是否跟踪活动setInterval and setTimeout身份证 或者这完全取决于开发人员来跟踪 如果它确实跟踪它们 是否可以通过 BOM 访问 由开发人员来跟踪 您可以通过使用 setTimeout setInterval 函
  • bootstrap 3将文本内容换行在div内以进行水平对齐

    My post title here could be misleading first have a look at HTML i have currently 正如您所看到的 每一列的文本内容都会溢出到下一列 其次 它们中的每一个都不是
  • UITableViewCell 中的 UILabel 位置第一次尝试失败

    我刚刚开始接触 iOS 开发 所以我希望我能在这里获得正确的详细信息 我有一个UILabel 加载到通过 xib 创建的表格单元格中 实际上有几个标签 其中之一的长度不同 因此包装高度也不同 heightForRowAtIndexPath等
  • 为什么 jQuery UI 不隐藏具有隐藏父元素的元素?

    我一直在开发一个单页应用程序 并注意到我的下拉菜单有时在本应隐藏的情况下保持打开状态 我调查了为什么会发生这种情况 并发现如果父元素被隐藏 则使用扩展的 jQuery UI 隐藏元素hide功能毫无价值 This fiddle http j
  • 使用 rlang 创建带有双花括号 {{ 的函数(data.table 结构)

    是否可以使用 rlang 结构来执行函数data table 例如 没有数据表 library data table library dplyr iris 1 1 2 NA iris 3 3 4 NA test dt lt function
  • asynsPipe 生成 null 作为第一个值

    当在 Angular 中使用异步管道时 不会立即触发事件 http 请求或任何有延迟的可观察值 得到的第一个值是null为什么会发生这种情况 如何避免这种情况
  • 数据框的减法运算

    我有2个数据框df1 and df2 df1 lt data frame c1 c a b c d c2 c 1 2 3 4 df2 lt data frame c1 c c d e f c2 c 3 4 5 6 gt df1 c1 c2
  • Android:如何获取Fragment的视图

    在课堂上 我以编程方式添加一个片段 该片段包含一个按钮 我想要一个 onClick 实现 这是我的课程 public class ShareProduct extends SherlockFragmentActivity protected
  • 考虑在配置中定义“org.springframework.security.authentication.AuthenticationManager”类型的 bean

    我遵循了这里提到的一些建议 但它对我不起作用 因此 将问题放在这里 如何在自定义过滤器中使用 Java 配置注入 AuthenticationManager https stackoverflow com questions 2163355