ComponentSpace

Forums



Deserialization issue


Deserialization issue

Author
Message
[email protected]
martin.dye@comensura.co.uk
New Member
New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)

Group: Forum Members
Posts: 4, Visits: 29
I'm having issues deserializing a saml.json file, the error is:

Document
NameValueType
$exception{"The SAML configuration couldn't be deserialized."}ComponentSpace.Saml2.Exceptions.SamlException

Document
NameValueType
InnerException{"Object reference not set to an instance of an object."}System.Exception {System.NullReferenceException}

The code I'm running is:

  public void ConfigureServices(IServiceCollection services)

<snipped other service configurations>

    string jsonConfigName = "saml-simple.json";
    string samlConfigPath = @"C:\Projects\SamlTest";

    string jsonFilePath = System.IO.Path.Combine(samlConfigPath, jsonConfigName);
    string samlConfigText = System.IO.File.ReadAllText(jsonFilePath);

    var configurations = Newtonsoft.Json.JsonConvert.DeserializeObject<SamlConfigurations>(samlConfigText);

    // Always fails.
    services.AddSaml(samlConfigurations =>
    {
      samlConfigurations.Configurations = ConfigurationDeserializer.Deserialize(jsonConfigName, samlConfigPath).Configurations;
    });

    // Works
    services.AddSaml(samlConfigurations =>
    {
      samlConfigurations.Configurations = configurations.Configurations;
    });

... and the JSON contents of the file is:

{
"$schema": "https://www.componentspace.com/schemas/saml-config-schema-v1.0.json",
"Configurations": [
  {
  "ID": "test1",
  "LocalServiceProviderConfiguration": {
   "Name": "https://ExampleServiceProvider",
   "Description": "Example Service Provider",
   "AssertionConsumerServiceUrl": "https://localhost:44360/SAML/AssertionConsumerService",
   "SingleLogoutServiceUrl": "https://localhost:44360/SAML/SingleLogoutService",
   "ArtifactResolutionServiceUrl": "https://localhost:44360/SAML/ArtifactResolutionService",
   "LocalCertificates": [
    {
    "FileName": "certificates/sp.pfx",
    "Password": "password"
    }
   ]
  },
  "PartnerIdentityProviderConfigurations": [
   {
    "Name": "https://ExampleIdentityProvider",
    "Description": "Example Identity Provider",
    "SignAuthnRequest": true,
    "SignLogoutRequest": true,
    "SignLogoutResponse": true,
    "WantLogoutRequestSigned": true,
    "WantLogoutResponseSigned": true,
    "SingleSignOnServiceUrl": "https://localhost:44313/SAML/SingleSignOnService",
    "SingleLogoutServiceUrl": "https://localhost:44313/SAML/SingleLogoutService",
    "ArtifactResolutionServiceUrl": "https://localhost:44313/SAML/ArtifactResolutionService",
    "PartnerCertificates": [
    {
     "FileName": "certificates/idp.cer"
    }
    ]
   }
  ]
  }
]
}

As you can see, this isn't a big problem now, because I used the Newtonsoft library directly, but it would be best to use the supplied method for deserialisation.

Am I missing some additional configuration settings? 
[email protected]
martin.dye@comensura.co.uk
New Member
New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)New Member (7 reputation)

Group: Forum Members
Posts: 4, Visits: 29
[email protected] - 11/13/2020
I'm having issues deserializing a saml.json file, the error is:

Document
NameValueType
$exception{"The SAML configuration couldn't be deserialized."}ComponentSpace.Saml2.Exceptions.SamlException

Document
NameValueType
InnerException{"Object reference not set to an instance of an object."}System.Exception {System.NullReferenceException}

The code I'm running is:

  public void ConfigureServices(IServiceCollection services)

<snipped other service configurations>

    string jsonConfigName = "saml-simple.json";
    string samlConfigPath = @"C:\Projects\SamlTest";

    string jsonFilePath = System.IO.Path.Combine(samlConfigPath, jsonConfigName);
    string samlConfigText = System.IO.File.ReadAllText(jsonFilePath);

    var configurations = Newtonsoft.Json.JsonConvert.DeserializeObject<SamlConfigurations>(samlConfigText);

    // Always fails.
    services.AddSaml(samlConfigurations =>
    {
      samlConfigurations.Configurations = ConfigurationDeserializer.Deserialize(jsonConfigName, samlConfigPath).Configurations;
    });

    // Works
    services.AddSaml(samlConfigurations =>
    {
      samlConfigurations.Configurations = configurations.Configurations;
    });

... and the JSON contents of the file is:

{
"$schema": "https://www.componentspace.com/schemas/saml-config-schema-v1.0.json",
"Configurations": [
  {
  "ID": "test1",
  "LocalServiceProviderConfiguration": {
   "Name": "https://ExampleServiceProvider",
   "Description": "Example Service Provider",
   "AssertionConsumerServiceUrl": "https://localhost:44360/SAML/AssertionConsumerService",
   "SingleLogoutServiceUrl": "https://localhost:44360/SAML/SingleLogoutService",
   "ArtifactResolutionServiceUrl": "https://localhost:44360/SAML/ArtifactResolutionService",
   "LocalCertificates": [
    {
    "FileName": "certificates/sp.pfx",
    "Password": "password"
    }
   ]
  },
  "PartnerIdentityProviderConfigurations": [
   {
    "Name": "https://ExampleIdentityProvider",
    "Description": "Example Identity Provider",
    "SignAuthnRequest": true,
    "SignLogoutRequest": true,
    "SignLogoutResponse": true,
    "WantLogoutRequestSigned": true,
    "WantLogoutResponseSigned": true,
    "SingleSignOnServiceUrl": "https://localhost:44313/SAML/SingleSignOnService",
    "SingleLogoutServiceUrl": "https://localhost:44313/SAML/SingleLogoutService",
    "ArtifactResolutionServiceUrl": "https://localhost:44313/SAML/ArtifactResolutionService",
    "PartnerCertificates": [
    {
     "FileName": "certificates/idp.cer"
    }
    ]
   }
  ]
  }
]
}

As you can see, this isn't a big problem now, because I used the Newtonsoft library directly, but it would be best to use the supplied method for deserialisation.

Am I missing some additional configuration settings? 

Sorry to answer my own question, I realise now the jsonPath is "The JSON path expression identifying the location of the SAML configuration in the file." as per the instructions!
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)ComponentSpace Development (3.9K reputation)

Group: Administrators
Posts: 2.8K, Visits: 8.8K
No Worries. Thanks Martin.

Regards
ComponentSpace Development
GO


Similar Topics


Execution: 0.000. 2 queries. Compression Enabled.
Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....









Forums, Documentation & Knowledge Base - ComponentSpace


Search