gpt4 book ai didi

java - 如何使用 Spring Security 命名空间设置和配置 ProviderManager?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:21:37 26 4
gpt4 key购买 nike

Spring 文档说 ProviderManagerAuthenticationManager 的默认实现,但是 ProviderManager 的实例由安全性自动创建和连接命名空间?

换句话说,这样的配置会自动创建一个ProviderManager的实例吗:

<authentication-manager>
<authentication-provider>
<password-encoder hash="md5"/>
<jdbc-user-service data-source-ref="dataSource"/>
</authentication-provider>
</authentication-manager>

否则,我需要做什么(或声明)?

假设我想插入我自己的 AuthenticationManager 实现,我将如何使用命名空间配置它?

我还想指定应在 ProviderManager 中注册哪个 AuthenticationProvider。我找到了以下配置代码:

<bean id="authenticationManager"
class="org.springframework.security.authentication.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider"/>
<ref local="anonymousAuthenticationProvider"/>
</list>
</property>
</bean>

但这就够了吗?声明 AuthenticationProvider 列表的正确方法是什么?关于这个问题的文档不是很清楚和完整。

最佳答案

In other words, will such configuration automatically create an instance of ProviderManager:

根据附录B2部分,答案是肯定的。

Assuming I would want to plug my own implementation of AuthenticationManager, how would I configure this using the namespace?

根据 B.3.1 节:

<global-method-security authentication-manager-ref="..." >

What is the right way to declare the list of AuthenticationProvider?

来自blog post , 而不是使用 <authentication-manager> ... </authentication-manager> ,应该使用类似这样的东西:

<bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager">
<property name="providers">
<list>
<ref bean="authenticationProvider" />
<ref bean="anonymousProvider" />
</list>
</property>
</bean>

<bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="passwordEncoder">
<bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
</property>
<property name="userDetailsService" ref="userService" />
</bean>

<bean id="anonymousProvider" class="org.springframework.security.authentication.AnonymousAuthenticationProvider">
<property name="key" value="SomeUniqueKeyForThisApplication" />
</bean>

关于java - 如何使用 Spring Security 命名空间设置和配置 ProviderManager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581058/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com