我正在使用 openSAML 来验证来自身份提供商 (IdP) 的 SAML 响应。第一步,我将来自 IdP 的 DOM 响应转换为 openSAML XMLObject。我正在使用以下代码:
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");
此代码给了我 IllegalStateException: 无法获取 SAML 解码器。在谷歌搜索上我发现了这个:Opensaml error receiving correct unmarshaller Pegerto 建议引导解码器寄存器。因此,我添加了以下代码:
try {
DefaultBootstrap.bootstrap();
generator = new SecureRandomIdentifierGenerator();
} catch (Exception ex) {
ex.printStackTrace();
}
现在这是给:
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
我的代码中已经有 import org.opensaml.DefaultBootstrap;
并在我的类路径中添加了 opensaml-2.2.3.jar 。
有人可以帮我解决这个错误吗?
谢谢!
最佳答案
解决了!
jar 文件应位于 WEB-INF/lib/文件夹中。这是一个网络应用程序项目。
关于java.lang.ClassNotFoundException : org. opensaml.DefaultBootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30948256/