Java.io.IOException: Invalid Spring Key Store Format SAML Security Extension

I successfully got the Spring Security SAML Extension sample application to run. Now I am trying to integrate it into the main application. Before I tried to integrate with my application, I created a sample application to integrate it, and it works great. In my sample application, I used the keystore from the downloaded sample application. Now I try to use the same keystore and I get the following error:

Called: org.springframework.beans.factory.BeanCreationException: Autowire method failed: public void org.springframework.security.saml.metadata.MetadataGenerator.setKeyManager (org.springframework.security.saml.key.KeyManager); org.springframework.beans.factory.BeanCreationException nested exception: error creating a bean with the name "keyManager" defined in the ServletContext resource [/WEB-INF/spring/securityContext.xml]: Activation of the bean could not; nested exception org.springframework.beans.BeanInstantiationException: failed bean class instance [org.springframework.security.saml.key.JKSKeyManager]: constructor threw an exception; The nested exception is java.lang.RuntimeException: Error initializing the keystore org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredMethodElement.inject (AutowiredAnnotationBeanPostProcessor.java=96) in org.sanjectationfunction InjectionMetadata.java:87) in org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ​​(AutowiredAnnotationBeanPostProcessor.java:289) ... 89 more Reasons: org.springfunctionExe.an error.bean.bean.bean. with the name "keyManager" defined in the ServletContext resource [/WEB-INF/spring/securityContext.xml]: Activation could not; nested exception org.springframework.beans.BeanInstantiationException: failed bean class instance [org.springframework.security.saml.key.JKSKeyManager]: constructor threw an exception; The nested exception is java.lang.RuntimeException: Error initializing the keystore org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor (ConstructorResolver.java:278) in org.springframework.beansCactoryFactoryFutableaputableaputableaputableap java: 1114) in org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java:1017) in org.springframeworkututaneananeananreanoweananaveanoweananeananreanoweananoutanoweananoutanowreanoweananoutanoweananoutanowaneanoweananoutanoweananoutanoweananoutanowreanoweeranutanoweeranutanoweanWananswer .beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:475) in org.springframework.beans.factory.support.AbstractBeanFactory.ortObject (AbstractBeanFactory.support.beava orgebehr. Defaultsingleton BeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:228) in org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:298) in org.springframework.beans.factory.supportBeanAbory.b 193) in org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates (DefaultListableBeanFactory.java:1017) in org.springframework.beans.factory.support.DefaultListableBeanFactoryListableBeanfableableebepableweistebeperveepefebeepableveebepolveablebepableveebepolveablebeepefebeepefebepableveebepolveablebepolveablebeefestorybeistebeefestablebeistebepolveablebepanfestablebistanbeeperfestablebistanbeablebestanbebepolveepefedepeveebepolveablebepanfestablebistanbeeprefestablebeistablebistanbeb .factory.support.DefaultListableBeanFactory.resolveDependency (DefaultListableBeanFactory.java:858) in org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredManodenanopenjunIndoorennotennotPreferennotAndiveennotivenotnotivenotnotenjectnorejunnotednotennotennotennotennotennotennoten .BeanInstantiationException: failed bean class instance [org.springfr amework.security.saml.key.JKSKeyManager]: the constructor threw an exception; The nested exception is java.lang.RuntimeException: Error initializing key store org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:164) in org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.instantiate) in org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor (ConstructorResolver.java:270) ... 103 more Causes: java.lang.RuntimeException: Error initializing the keystore org.springframework.security.saml.key.JKSKeyManager. initialize (JKSKeyManager.java:121) in org.springframework.security.saml.key.JKSKeyManager. (JKSKeyManager.java:79) at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) with sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:57.plava.plava.plav.plon.plon.plop.onplon.ploplon.plop.onplonclonplop.onplop.onplop.onplop.onplop.construment.conflector java.lang.reflect.Constructor.newInstance (Constructor.javaPoint26) in org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:148) ... 105 more Caused: java.io.IOException: Invalid key store format in sun.security.provider.JavaKeyStore.engineLoad (JavaKeyStore.java:650) in sun.security.provider.JavaKeyStore $ JKS.engineLoad (JavaKeyStore.java:55) in java.security.KeyStore.load (KeyStore.java:1214 ) in org.springframework.security.saml.key.JKSKeyManager.initialize (JKSKeyManager.java:117) ... 111 more

Here is the bean configuration for JKSKeyManager:

<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager"> <constructor-arg value="classpath:security/samlKeystore.jks" /> <constructor-arg type="java.lang.String" value="nalle123" /> <constructor-arg> <map> <entry key="apollo" value="nalle123" /> </map> </constructor-arg> <constructor-arg type="java.lang.String" value="apollo" /> </bean> 

Can someone help me with what causes this error?

+5
source share
3 answers

I had a similar problem; I decided that Maven was filtering my resources and adding that this solved the problem:

  <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.jks</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.jks</include> </includes> </resource> 
+4
source

I had the same problem. Maven copied the binary incorrectly.

I had to add the following to my maven-resources plugin:

 <nonFilteredFileExtensions> <nonFilteredFileExtension>jks</nonFilteredFileExtension> </nonFilteredFileExtensions> 

You can verify this by running the command in the target directory:

 keytool -list -keystore ~/<your_project_target_directory>/security/samlKeystore.jks 

When my maven copied the file incorrectly, I got:

 keytool error: java.io.IOException: Invalid keystore format 

As soon as I added nonFilteredFileExtension, I was immediately prompted to enter a password.

+2
source

You can start troubleshooting by replacing samlKeystore.jks directly in the deployed web archive, using one directly from SAML Spring sources. This can help you determine if the problem is in the keystore or in your code - most likely it is a keystore.

If you use Maven to create your application, make sure that the keystore is placed in the resources folder in your assembly, and not in java or webapp . Maven seeks to corrupt the keystore during construction if it is not placed in the resources folder.

-1
source

Source: https://habr.com/ru/post/1206275/


All Articles