2017-03-24 13 views
2

Spring Securityとsolrコアで独自のカスタムセキュリティを実行していますが、何か間違っていたようですが、Beanプロパティ 'userDetailsS​​ervice'を設定しているときにBeanへの参照を解決できません

スタックトレース:

Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'authenticationManager' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'CustomUserDetails' is defined 
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:231) 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100) 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82) 

このsecurity-context.xmlファイル:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
     http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd"> 

    <security:global-method-security 
     secured-annotations="enabled"></security:global-method-security> 
    <security:http auto-config="true" realm="Protected Web" 
     pattern="/**" authentication-manager-ref="authenticationManager"> 
     <security:csrf disabled="true" /> 

     <security:intercept-url pattern="/index/**" access="hasAnyRole('ROLE_ADMIN','ROLE_USER')" /> 

     <security:intercept-url pattern="/rest/api/1.0/**" access="isAuthenticated()" /> 

     <security:intercept-url pattern="/**" access="permitAll" /> 

     <security:form-login login-page="/login" 
      username-parameter="j_username" login-processing-url="/j_spring_security_check" 
      password-parameter="j_password" authentication-failure-url="/login?error=1" 
      default-target-url="/index" always-use-default-target="true" /> 

     <security:logout invalidate-session="true" 
      delete-cookies="true" logout-url="/j_spring_security_logout" 
      logout-success-url="/login" /> 
     <security:session-management> 
      <security:concurrency-control 
       max-sessions="2" /> 
     </security:session-management> 
    </security:http> 



     <security:authentication-manager alias="authenticationManager"> 
     <security:authentication-provider user-service-ref="CustomUserDetails" /> 
    </security:authentication-manager> 

</beans> 

クラスCustomUserDetails

​​

app-context.xmlファイル:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     id="WebApp_ID" version="3.0"> 
     <display-name>secturv2</display-name> 

     <context-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value> 
       /WEB-INF/solr-config.xml, 
       /WEB-INF/Spring-Quartz.xml, 
       /WEB-INF/spring/security-context.xml, 
       /WEB-INF/spring/postgres-config.xml 

      </param-value> 
     </context-param> 
    <!--, /WEB-INF/spring/postgres-config.xml --> 
     <listener> 
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
     </listener> 
     <listener> 
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
     </listener> 

     <servlet> 
      <servlet-name>dispatcher</servlet-name> 
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
      <init-param> 
       <param-name>contextConfigLocation</param-name> 
       <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
      </init-param> 
      <load-on-startup>1</load-on-startup> 
     </servlet> 

     <servlet-mapping> 
      <servlet-name>dispatcher</servlet-name> 
      <url-pattern>/</url-pattern> 
     </servlet-mapping> 

     <servlet-mapping> 
      <servlet-name>jsp</servlet-name> 
      <url-pattern>*.html</url-pattern> 
     </servlet-mapping> 

     <!-- Spring Security --> 
     <filter> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
     </filter> 

     <filter-mapping> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <url-pattern>/*</url-pattern> 
     </filter-mapping> 

    <!-- Sesiones de Hibernate --> 
     <filter> 
      <filter-name>OpenSessionInViewFilter</filter-name> 
      <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> 
      <init-param> 
       <param-name>sessionFactoryBeanName</param-name> 
       <param-value>sfTurismo</param-value> 
      </init-param> 
     </filter> 
     <filter-mapping> 
      <filter-name>OpenSessionInViewFilter</filter-name> 
      <url-pattern>/*</url-pattern> 
     </filter-mapping> 

     <error-page> 
      <error-code>401</error-code> 
      <location>/error</location> 
     </error-page> 

     <error-page> 
      <error-code>403</error-code> 
      <location>/error</location> 
     </error-page> 

     <error-page> 
      <error-code>500</error-code> 
      <location>/error</location> 
     </error-page> 

    </web-app> 

EDIT: 'userDetailsS​​ervice' Beanのプロパティを設定しながら、私は

を得ていることBeanへの参照を解決できない理由」

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

    <annotation-driven /> 
    <context:component-scan base-package="mx.sectur.turismo" /> 
    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
     up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 
    <resources location="/views/" mapping="/**" /> 

    <beans:bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" /> 

    <beans:bean 
     class="org.springframework.data.repository.support.DomainClassConverter"> 
     <beans:constructor-arg ref="conversionService" /> 
    </beans:bean> 

    <mvc:annotation-driven conversion-service="conversionService"> 
     <mvc:argument-resolvers> 
      <beans:bean 
       class="org.springframework.data.web.PageableHandlerMethodArgumentResolver"> 
       <beans:property name="maxPageSize" value="10"></beans:property> 
      </beans:bean> 
     </mvc:argument-resolvers> 
    </mvc:annotation-driven> 

    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <interceptors> 
     <beans:bean id="webContentInterceptor" 
      class="org.springframework.web.servlet.mvc.WebContentInterceptor"> 
      <beans:property name="cacheSeconds" value="0" /> 
      <beans:property name="useExpiresHeader" value="true" /> 
      <beans:property name="useCacheControlHeader" value="true" /> 
      <beans:property name="useCacheControlNoStore" value="true" /> 
     </beans:bean> 
    </interceptors> 

</beans:beans> 

servlet-context.xmlファイルを追加しました

メッセージ?

+1

いただきましたが、私はこの '<コンテキスト:コンポーネント・スキャンベースパッケージ= "mx.sectur.turismo" />'を持つCustomerUserDetailsクラス – Dhiraj

答えて

4

これらの問題は、間違った名前を使用しているBeanを参照していることが原因です。

デフォルトでは、この

@Service("CustomUserDetails") 
public class CustomUserDetails implements UserDetailsService 

よう@Service注釈によって作成されたBeanの名前を上書きしてください、春はケースに部品の最初の文字が低下します - 「customUserDetails」から「CustomUserDetails」から。また、このコンポーネントを「customUserDetails」という名前で取得できます。

あなたは

<security:authentication-manager alias="authenticationManager"> 
     <security:authentication-provider user-service-ref="customUserDetails" /> 
    </security:authentication-manager> 

以下のようにデフォルトの名前を上書きしたくない場合ので、あなたはまた、問題を引き起こしている可能性があります。この概念

他の事はあるより良く理解するためthisリンクを参照してくださいコードの下に変更することができますservice beanが初期化されているWebアプリケーションコンテキスト内にあるservelet-xmlで駆動される注釈を定義しました。主なアプリケーションのコンテキストでセキュリティコンテキストを定義しています。したがって、名前を付けたファイルを作成し、 をそのファイルに移動してください。

+0

類似の質問については、このリンクを参照してください。http://stackoverflow.com/questions/22744666/unable-to-identify-authentication-provider-user-service-ref-in-spring-security – Dhiraj

+2

更新された回答を探します。あなたは無意識にこれに入り込んでいます。主なアプリケーション・コンテキストとサーブレット・コンテキストの範囲を理解しようとします。 – Dhiraj

+0

待って、私はちょっと混乱している、別のファイルに駆動注釈をシフトする必要がありますか? –

0

私は春に新しいですが、あなたの春のアプリケーションコンテキストファイルは、私がかつて同様の問題があったthis-

<bean id="userDetailsService" class="com.package.CustomUserDetails "/> 
+1

のパッケージで、このファイルの\t「/WEB-INF /春/ appServlet /サーブレットを-context.xml ' –

+1

ああ!しかし、あなたがサーブレットファイルのために投稿したスニペットにはそれが含まれていませんでした。 – nazia

0

のようなものを必要とするように見えます。

ClassPathXmlApplicationContextがコンテキストコンフィグレーションファイルをロードするためには、アプリケーションコンテキストファイルがresourcesフォルダ内に存在する必要があります。

関連する問題