I am using openSAML to authenticate SAML Response from an Identity Provider (IdP). As the first step, I am converting the DOM response from the IdP to a openSAML XMLObject. I am using the following code:
Base64 base64 = new Base64();
byte[] base64DecodedResponse = base64.decode(responseMessage);
ByteArrayInputStream is = new ByteArrayInputStream(base64DecodedResponse);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(is);
Element element = document.getDocumentElement();
UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
if (unmarshaller == null)
throw new IllegalStateException("Could not obtain a SAML unmarshaller");
XMLObject obj = unmarshaller.unmarshall(element);
if (obj == null || !(obj instanceof Response))
throw new IllegalStateException("Unmarshaller return not SAML response");
This code gave me IllegalStateException: Could not obtain a SAML unmarshaller. On googling I found this : Opensaml error receiving correct unmarshaller where Pegerto suggested bootstrapping the unmarshaller registers. So, I added the following code:
try {
DefaultBootstrap.bootstrap();
generator = new SecureRandomIdentifierGenerator();
} catch (Exception ex) {
ex.printStackTrace();
}
Now this is giving:
Jun 19, 2015 2:58:30 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/testSAML] threw exception [javax.servlet.ServletException:
java.lang.NoClassDefFoundError: org/opensaml/DefaultBootstrap] with root cause
java.lang.ClassNotFoundException: org.opensaml.DefaultBootstrap
I already have import org.opensaml.DefaultBootstrap;
in my code
and added opensaml-2.2.3.jar in my classpath.
Can someone help me with this error?
Thanks!
Solved!
The jar files should be in the WEB-INF/lib/ folder. It is a web application project.