gpt4 book ai didi

security - Spring - 安全 : how are login username and password bound to the authentication-provider?

转载 作者:行者123 更新时间:2023-12-04 14:36:46 25 4
gpt4 key购买 nike

我是 Spring 和 Spring 安全的新手,

我已经了解 bean 是如何在 xml 文件中创建和引用的,
我需要在我的应用程序中使用 spring 来提供安全性。

我在 web.xml 中包含了一个自定义 applicationContext-security.xml 文件: contextConfigLocation

在这个文件中,我使用截获了 url 模式

<intercept-url pattern='/**.something' access="IS_AUTHENTICATED_FULLY"/>

内部元素。

我已将登录表单设置为
现在,如果一个页面未经授权,它会显示我的自定义 Login.html 页面。

现在对于我面临的问题:
  • 如何指定我的登录表单以将其值传递给 spring ?
  • 如何使用我自己的 authentication-provider ?

  • 我试过这个:
    <authentication-provider user-service-ref="userDetailsService"/>
    <beans:bean id = "userDetailsService" class ="com.somepath.CustomAuthenticationProvider">
    <custom-authentication-provider/>
    </beans:bean>

    其中 CustomAuthenticationProvider 实现 AuthenticationProvider

    但代码抛出错误:
    创建名为 '_filterChainProxy' 的 bean 时出错 .... 未注册 UserDetailsS​​ervice

    请帮忙

    最佳答案

    1:如何指定我的登录表单以将其值传递给 spring ?
    在 web.xml 中为 Spring Security 设置标准 Spring 过滤器后,使用 <http> 配置的一些默认设置标签。 AuthenticationProcessingFilter 的一个实例作为过滤器链的一部分为您创建。
    我的默认 AuthenticationProcessingFilter设置为读取 j_username 和 j_password 作为用户名/密码 token 。
    为了覆盖这一点,通过执行以下操作将您的自定义 AuthenticationProcessingFilter 替换为默认值:

    <bean id=“myAuthFilter” class=“org.springframework.security.ui.webapp.AuthenticationProcessingFilter” >
    <security:custom-filter position=“AUTHENTICATION_PROCESSING_FILTER”/><!–-replace the default one-–>
    <property name=“usernameParameter” value=“myUsername”/><!-- myUsername is the name of the input tag where user enter their username on the HTML page -->
    <property name=“passwordParameter” value=“myPassword” /><!–- myPassword is the name of the input tag where user enter their password on the HTML page -–>
    </bean>
    有关更多详细信息,另请参阅 AuthenticationProcessingFilter 的 JavaDoc:
    http://static.springsource.org/spring-security/site/apidocs/org/springframework/security/ui/webapp/AuthenticationProcessingFilter.html
    2:如何使用自己的身份验证提供程序?
    使用以下代码:
    <bean id="myAuthenticationProvider" class="com.something.MyAuthenticationProvider">
    <security:custom-authentication-provider />
    </bean>
    <security:custom-authentication-provider />是让 spring 知道这是一个自定义提供程序的标签,并且身份验证管理器应该在其提供程序链中使用它。
    来源: http://static.springsource.org/spring-security/site/docs/2.0.x/reference/appendix-namespace.html#d4e3379
    3:关于代码抛出'_filterChainProxy'的问题......没有注册UserDetailsS​​ervice......'
    com.somepath.CustomAuthenticationProvider实现 UserDetailService 接口(interface)?

    关于security - Spring - 安全 : how are login username and password bound to the authentication-provider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1599487/

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