java - 在 Spring Security 中使用 InMemoryDaoImpl

标签 java authentication spring-security authorization

我正在尝试实现自定义过滤器、身份验证提供程序以直接从请求对用户进行身份验证。但是我收到以下异常。

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'signedRequestAuthenticationProvider' defined in   ServletContext resource [/WEB-INF/applicationContext.xml]: 
 Cannot resolve reference to bean      'org.springframework.security.core.userdetails.memory.InMemoryDaoImpl' 
  while setting bean 
property 'userDetailsService'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.core.userdetails.memory.InMemoryDaoImpl' 
 is defined at  org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

我的应用程序上下文是

   <bean id="signedRequestAuthenticationProvider" class="src.SignedUsernamePasswordAuthenticationProvider">
       <property name="userDetailsService" ref="org.springframework.security.core.userdetails.memory.InMemoryDaoImpl"/>
   </bean>

我的 security.xml 读取

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/login*" access="hasRole('ROLE_ANONYMOUS')"/>
            <intercept-url pattern="/*" access="hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')"/>

            <form-login login-page="/login.jsp"/>
            <custom-filter ref="requestHeaderFilter" before="FORM_LOGIN_FILTER"/>
   </http>

   <authentication-manager alias="authenticationManager">
    <authentication-provider ref="signedRequestAuthenticationProvider"/>
            <authentication-provider>
        <user-service>
            <user authorities="ROLE_USER" name="guest" password="guest"/>
                            <user authorities="ROLE_ADMIN" name="vinoth" password="vinoth"/>
        </user-service>
    </authentication-provider>
</authentication-manager>

我错过了什么吗?

最佳答案

org.springframework.security.core.userdetails.memory.InMemoryDaoImpl 不是 bean 标识符,因此您不能在 ref 属性中使用它。您需要使用 id 显式引入标识符:

<bean id="signedRequestAuthenticationProvider" class="src.SignedUsernamePasswordAuthenticationProvider">
    <property name="userDetailsService" ref="userService"/>
</bean>
<小时/>
<authentication-manager alias="authenticationManager">
    <authentication-provider ref="signedRequestAuthenticationProvider"/>
    <authentication-provider>
        <user-service id = "userService">
            <user authorities="ROLE_USER" name="guest" password="guest"/>
            <user authorities="ROLE_ADMIN" name="vinoth" password="vinoth"/>
        </user-service>
    </authentication-provider>
</authentication-manager>

关于java - 在 Spring Security 中使用 InMemoryDaoImpl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5406441/

相关文章:

android - 为什么大多数人在retrofit中使用拦截器添加认证头?

php - jquery mobile登录和访问/拒绝页面

javascript - Firebase登录成功后如何链接到下一页?

java - 如何使用 Spring security 解除方法的保护

java - Spring 安全: issues 403 after authorization with single granted

java - 使用 Jackson ObjectMapper 的 ClassNotFound 异常

java - 通过 GET 方法重定向到 j_spring_security_check

java - Arraylist 不断抛出 IndexOutOfBounds

java - 检查使用 JAVA(一个 jsp)选中了哪些复选框

使用 OAuth2 的 Java Spring (Maven) REST API