Null Pointer Exception from UnmarshallerFactory while migrating from OpenSAML2.x to OpenSAML3.x
DD K
ddk05361 at gmail.com
Thu Aug 8 11:07:35 EDT 2019
Hi All,
Since I was using OpenSAML3 on a project which is based on OSGi seems there
was a problem during initialization so what I had to do is initialize them
myself. Hope this helps someone in the future.
Stack Overflow Resource -
https://stackoverflow.com/questions/37948303/opensaml3-resource-not-found-default-config-xml-in-osgi-container
Code Implementation:
public static void doBootstrap() {
if (!isBootStrapped) {
try {
InitializationService.initialize();
SAMLConfigurationInitializer initializer_1 = new
SAMLConfigurationInitializer();
initializer_1.init();
org.opensaml.saml.config.XMLObjectProviderInitializer
initializer_2 = new
org.opensaml.saml.config.XMLObjectProviderInitializer();
initializer_2.init();
org.opensaml.core.xml.config.XMLObjectProviderInitializer
initializer_3 = new
org.opensaml.core.xml.config.XMLObjectProviderInitializer();
initializer_3.init();
org.opensaml.core.xml.config.GlobalParserPoolInitializer
initializer_4 = new
org.opensaml.core.xml.config.GlobalParserPoolInitializer();
initializer_4.init();
isBootStrapped = true;
} catch (InitializationException e) {
log.error("Error in bootstrapping the OpenSAML2 library", e);
}
}
}
Thanks all for the answers,
Best Regards,
Deshan Koswatte
On Thu, Aug 8, 2019 at 10:11 AM DD K <ddk05361 at gmail.com> wrote:
> Hi Brent,
>
> I've been able to debug the process and found out that I have got null
> from unmarshallerFactory.getUnmarshaller(element) because there has been no
> unmarshaller registered to unmarshall the element. Can you suggest a way to
> manually register an unmarshaller for the element (any resource that i can
> refer). So my request is as follows:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <samlp:AuthnRequest AssertionConsumerServiceURL="
> http://localhost.com:8080/saml2-web-app-pickup-dispatch.com/home.jsp"
> Destination="https://localhost:9443/samlsso" ForceAuthn="false"
> ID="fnhigdbcehpepkchcpbacfooiadpciniicamhckg" IsPassive="true"
> IssueInstant="2019-08-08T04:40:07.949Z"
> ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
> Version="2.0"
> xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"><samlp:Issuer
> xmlns:samlp="urn:oasis:names:tc:SAML:2.0:assertion">
> saml2-web-app-pickup-dispatch.com</samlp:Issuer><saml2p:NameIDPolicy
> AllowCreate="true"
> Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
> SPNameQualifier="Issuer"
> xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"/><saml2p:RequestedAuthnContext
> Comparison="exact"
> xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"><saml:AuthnContextClassRef
> xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml2p:RequestedAuthnContext></samlp:AuthnRequest>
>
> Any answers answers would be appreciated,
> Thanks,
> Deshan Koswatte
>
> On Thu, Aug 8, 2019 at 4:21 AM Brent Putman <putmanb at georgetown.edu>
> wrote:
>
>>
>> On 8/6/19 1:30 AM, DD K wrote:
>>
>>
>> The exception is thrown from the code snippet at the commented line:
>>
>> public static XMLObject unmarshall(String authReqStr) throws IdentityException {
>> InputStream inputStream = null; try {
>> doBootstrap(); DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); inputStream = new ByteArrayInputStream(authReqStr.trim().getBytes(StandardCharsets.UTF_8)); Document document = docBuilder.parse(inputStream); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); // Exception thrown here } catch (Exception e) {
>> log.error("Error in constructing AuthRequest from the encoded String", e); throw IdentityException.error(
>> "Error in constructing AuthRequest from the encoded String ", e); } finally {
>> if (inputStream != null) {
>> try {
>> inputStream.close(); } catch (IOException e) {
>> log.error("Error while closing the stream", e); }
>> }
>> }
>> }
>>
>>
>>
>>
>> I don't see anything obviously wrong there. If it's throwing on that
>> line, it's likely that the unmarshaller is null, which means you didn't get
>> anything back from the unmarshallerFactory. That means something is likely
>> not working with your initialization of the library. I can't say anything
>> more than that. I'd suggest turning up logging to DEBUG or even TRACE on
>> some or all of the OpenSAML packages to see what is actually happening, for
>> example whether you are actually successfully reading and registering the
>> XMLObject builders, marshallers and unmarshallers.
>> --
>> To unsubscribe from this list send an email to
>> dev-unsubscribe at shibboleth.net
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/dev/attachments/20190808/fe7f50a7/attachment.html>
More information about the dev
mailing list