java.lang.ClassNotFoundException : org. opensaml.DefaultBootstrap

标签 java classnotfoundexception saml saml-2.0 opensaml

我正在使用 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/

相关文章:

wcf - 使用 WIF 创建自定义 STS-IP 以及为什么不

java - 即使表中的数据不为零,使用简单算术运算和别名时 JDBC 查询也会返回零

java - 除法运算给出了错误的结果

java - 使用递归比较两个字符串(不区分大小写)

debugging - ClassNotFoundException Android Studio 调试

java - JUnit 与 Ant,另一个 java.lang.ClassNotFoundException

java - 如何计算二进制数字中1的数量?

尝试从 .jar 文件加载小程序时出现 java.lang.ClassNotFoundException

security - 了解 Shibboleth 和 SAML

c# - 使用 WIF 创建 SAML 身份验证请求