内存和自定义提供程序一起

Xtreme Biker:

我正在设置Spring Security(v4.0.1)Web应用程序。我想拥有两个身份验证提供程序,一个“内存中”提供程序来管理管理员帐户,一个自定义身份验证提供程序,它引用我自己的实现。系统应该首先尝试针对“内存中”提供程序进行身份验证,然后针对第二个定制用户进行身份验证。我的代码如下所示:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth, 
    AuthenticationProvider provider) throws Exception {
    auth.inMemoryAuthentication()
            .withUser("admin")
            .password("s3cr3t")
            .authorities("ADMIN");
    auth.authenticationProvider(provider);
}

但是,此代码使框架首先尝试我的自定义实现。这有点有意义,因为该AuthenticationManagerBuilder#authenticationProvider方法在内部AuthenticationManagerBuilder#inMemoryAuthentication配置Provider的同时将Provider添加到内部List 我如何设法使其正常工作?

拉尼兹:

您可以InMemoryUserDetailsManagerConfigurer手动创建自己的文件,并告诉它在AuthenticationManagerBuilder完成配置时对其进行自我配置,这样它就可以AuthenticationProvider在自定义配置之前进行安装

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth,
        AuthenticationProvider provider) throws Exception {

    inMemoryConfigurer()
        .withUser("admin")
            .password("s3cr3t")
            .authorities("ADMIN")
        .and()
        .configure(auth);
    auth.authenticationProvider(provider);
}

private InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder>
        inMemoryConfigurer() {
    return new InMemoryUserDetailsManagerConfigurer<>();
}

通常情况是,将InMemoryUserDetailsManagerConfigurer创建,并将其添加到在AuthenticationManager构建定制时应应用的配置程序列表中(即在安装自定义之后)AuthenticationProvider

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

<ReferenceArrayInput />不能与我的自定义数据提供程序一起使用(棱镜)

如何将Firebase自定义身份验证与openID提供程序一起使用?

验证程序要求不能与自定义验证程序一起使用

与正在重定向的自定义Http提供程序一起使用时,APP_INITIALIZER引发“无法实例化循环依赖项!ApplicationRef_”

将phpseclib与自定义外壳程序一起使用

将自定义DataContractResolver与多个程序集一起使用

将自定义 Python 类与 Django 应用程序一起使用

IIS和自定义成员资格提供程序+自定义角色提供程序的问题

将ng-option与排序和自定义文本一起使用

了解opsworks和自定义菜谱如何一起工作

将failWith与Servant和自定义monad堆栈一起使用

将 std::ranges 算法与自定义容器和迭代器一起使用

python seaborn:一起自定义线图和散点图(也是图例)

insertRowsAtIndexPaths与自定义单元格UITableView和UITableViewAutomaticDimension一起跳转

了解PreventDefault和DefaultPrevented如何与自定义事件一起使用

为什么 headerTransparent 和自定义参数 headerTitle 不能一起工作?

Xamarin 表单自定义 GridView Tap 和 Long Tap 不能一起工作

SSL无法通过Heroku和PointDNS与自定义域一起使用

将LoginView和LogoutView与自定义模板一起使用

自定义RewriteRule无法与WordPress一起使用?

将标识与自定义属性一起使用

将咖啡与自定义EditText一起使用

与自定义对象一起使用自动套用

将SqlCommandProvider与自定义超时一起使用

与 ARRAYFORMULA 一起使用的自定义表格功能

使IClassifier与自定义内容类型一起使用

自定义标题不与$ _SERVER一起显示

将%dopar%与自定义函数一起使用

Ajax:与自定义变量一起发送formData