我正在使用openSAML来验证来自身份提供者(IdP)的SAML响应。第一步,我将DOM响应从IdP转换为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 /文件夹中。这是一个Web应用程序项目。