I found that I was using incomplete securityContext.xml file
Spring SAML implementation cannot resolve reference to bean
-
17-01-2022 - |
سؤال
On my Vaadin application project I want to integrate spring-security-SAML extension. I downloaded source code from spring security extension page. Based on manual I packaged extension using mvn package and deployed it on local maven repository using mvn deploy command. Everything goes right. A compiled extension appeared on the maven repository. So I included it into project pom.xml file as dependency like this:
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.0-RC1-SNAPSHOT</version>
</dependency>
After that I updated maven project and found spring-security-saml2-core-1.0.0-RC1-SNAPSHOT.jar inside maven dependency directory (I am using eclipse IDE with Maven). The next thing what I did, was appLicationContext.xml file editing. applicationContext.xml file is included throught the web.xml. So I added lines below to appLicationContext.xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="org.springframework.security.saml"/>
<security:http entry-point-ref="samlEntryPoint">
<security:intercept-url pattern="/*" access="IS_AUTHENTICATED_FULLY"/>
<security:custom-filter before="FIRST" ref="metadataGeneratorFilter"/>
<security:custom-filter after="BASIC_AUTH_FILTER" ref="samlFilter"/>
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="samlAuthenticationProvider"/>
</security:authentication-manager>
<bean id="samlAuthenticationProvider" class="org.springframework.security.saml.SAMLAuthenticationProvider">
</bean>
<bean id="samlEntryPoint" class="org.springframework.security.saml.SAMLEntryPoint">
<property name="defaultProfileOptions">
<bean class="org.springframework.security.saml.websso.WebSSOProfileOptions">
<property name="includeScoping" value="false"/>
</bean>
</property>
</bean>
<bean id="metadataGeneratorFilter" class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
<constructor-arg>
<bean class="org.springframework.security.saml.metadata.MetadataGenerator"/>
</constructor-arg>
</bean>
After such changes on the file, I compiled my project into war archive and tried to upload it to glassfish server. But then I got an error:
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0':
Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '(inner bean)':
FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'samlAuthenticationProvider' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.
I found several topics with such problem but different libraries. No one could help me to solve my problem. It looks like that org.springframework.security.saml.SAMLAuthenticationProvider could not be found or resolved on the war archive. But I checked it manually and found it on the WEB-INF/lib folder spring-security-saml2-core-1.0.0-RC1-SNAPSHOT.jar. Also I checked inside jar archive and found SAMLAuthenticationProvider.class. Does anyone can help me to solve my problem. Maybe there are people that has experience with Spring security and saml extension.
المحلول