Error creating bean with name 'org.springframework.security.saml.SAMLBootstrap#0' - spring-saml

I am adding SSO code in the webpage using SAML. And for this process I added the following code for Maven.
<!-- Spring Framework Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.1.2.RELEASE</version>
</dependency>
<!-- Spring Security SAML -->
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
And I added the following code in the application context xml.
<!-- Initialization of OpenSAML library -->
<bean class="org.springframework.security.saml.SAMLBootstrap" />
But I get the following error
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.saml.SAMLBootstrap#0' defined in class
path resource [conf/spring/root-context.xml]: Instantiation of bean
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.springframework.security.saml.SAMLBootstrap]: No
default constructor found; nested exception is
java.lang.NoClassDefFoundError:
org/springframework/beans/factory/access/BootstrapException
It appears certain jars are missing. How do I add this jar?
Thanks
Jae Kim

Bottom line is: update to 1.0.3.RELEASE solves the problem.
Explanation: class SAMLBootstrap throws (line 45) BootstrapException, which exists in spring-4 (spring-beans-4.2.4.RELEASE) but not in spring-5.
In spring-security-saml2-core-1.0.3.RELEASE the dependency in class BootstrapException is removed.

According to this issue https://github.com/spring-projects/spring-security-saml/issues/211
You just have to update saml library to the latest version
1.0.4.RELEASE

Related

Tomcat 10, Java 17 - JavaMailSender cannot cast one of elements of java.lang.Object[]

After migrating application to Spring Boot 3 and Java 17 I tried to deploy it to Tomcat 10.1.x.
The deployment failed with exception:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mailSender' defined in class path
resource [org/springframework/boot/autoconfig
ure/mail/MailSenderPropertiesConfiguration.class]: Failed to
instantiate [org.springframework.mail.javamail.JavaMailSenderImpl]:
Factory method 'mailSender' threw exception with message: arraycopy:
element type mismatch: can not cast one of the elements of
java.lang.Object[] to the type of the destination array,
jakarta.activation.MimeTypeRegistry
The issue turned out to be caused by CXF library having dependency on:
com.sun.activation:jakarta.activation.
The solution is to exclude it from cxf:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<exclusions>
<exclusion>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
</exclusion>
</exclusions>
</dependency>
Instead include directly the jakarta.activation-api as below:
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.1</version>
</dependency>
There might be other libraries with the same dependency in the application.
For above the approach with deploying application to webapps-javaee folder and allowing Tomcat to perform migration doesn't work.

ConfigClientOAuth2BoostrapConfiguration': Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: CLIENT_SECRET_BASIC

Upon running a security scan our service was detected with high vulnerability related to spring-security-oauth2-client(5.3.10.RELEASE).We tried following both the recommended fixes and tried upgrading it to version 5.6.9 or 5.7.5.But now our application is not starting and gives an error:
Error creating bean with name 'io.pivotal.spring.cloud.config.client.ConfigClientOAuth2BoostrapConfiguration': Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: CLIENT_SECRET_BASIC at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization
Versions we are using:
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-starter-config-client</artifactId>
<version>3.1.5.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.5.7</version>
</dependency>
I tried to play around with different dependency version but still its giving the same error

Spring Boot Elastic Search connection issue

Boot with Elastic Search using Spring Data JPA. To implement this, I created a sample Amazon account and launched sample Elasticsearch instance in the AWS console and got the details.
Now the problem is, the Spring BOOT Application is failing to due to connection issues to the AWS ElasticSearch. Not sure, I am adding the right dependencies.
AmazonElasticSearch Details :
https://search-elasticsearch-3wqyu7ekb7nymtxwosu7nxkbkq.us-east-2.es.amazonaws.com/
Pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
ElasticSearchConfiuration:
enter image description here
application.properties
elasticsearch.clustername = 008026978848:elasticsearch
elasticsearch.host = https://search-elasticsearch-3wqyu7ekb7nymtxwosu7nxkbkq.us-east-2.es.amazonaws.com/
elasticsearch.port = 9300
Exception Details
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/aws/elasticsearch/config/ElasticSearchConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.net.UnknownHostException: https://search-elasticsearch-3wqyu7ekb7nymtxwosu7nxkbkq.us-east-2.es.amazonaws.com/

Getting "Error creating bean with name 'springSecurityFilterChain'" in Spring Boot

I got this error when I run the application. I tried to solve this problem by reading several posts but it makes no sense.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
and
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
In the exception stack trace it seems not able to find the JAXB-API . Do you have this dependency to your project - jaxb-api.
Java 11 removed the Java EE modules: java.xml.bind (JAXB) - REMOVED
You can fix the issue by using alternate versions of the Java EE technologies. Simply add Maven dependencies that contain the classes you need:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
For Details Read This StackOverflow Answer

ClassNotFoundException: DirectoryService with apacheds-all already included

I am implemented LDAP authentication in my Spring Boot Application. The dependencies added are as follows:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
</dependency>
However I am still getting following ClassNotFoundException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]
Caused by: java.lang.NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
Caused by: java.lang.ClassNotFoundException: org.apache.directory.server.core.DirectoryService
My maven dependency tree clearly shows apacheds-all is added successfully.
Why am I still getting this error?
Spring Security doesn't support Apache DS 2.0. Instead, you need to use 1.5.5. Also, note that later 1.5.x versions are not supported due to breaking API changes.

Resources