internal static bool TryBuildOrganisation(OrganisationConfiguration organisationConfiguration, out Organization organisation)
        {
            organisation = new Organization();
            if (organisationConfiguration == null)
            {
                return(false);
            }
            try
            {
                organisationConfiguration.Names.Aggregate(organisation, (o, next) =>
                {
                    o.Names.Add(new LocalizedName(next.Name, next.Language));
                    o.DisplayNames.Add(new LocalizedName(next.DisplayName, next.Language));
                    return(o);
                });
                organisationConfiguration.Urls.Aggregate(organisation, (o, next) =>
                {
                    o.Urls.Add(new LocalizedUri(next.Url, next.Language));
                    return(o);
                });

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Example #2
0
        public static OrganisationConfiguration BuildOrganisationConfiguration()
        {
            var orgConfiguration = new OrganisationConfiguration
            {
                OrganisationContacts = new ContactConfiguration()
            };

            orgConfiguration.Names.Add(new LocalizedConfigurationEntry
            {
                Name        = "Company name",
                DisplayName = "Company Display name",
            });
            orgConfiguration.Urls.Add(new LocalizedUrlEntry {
                Url = new Uri("https://company.co.uk/")
            });

            var contact = new Kernel.Federation.MetaData.Configuration.Organisation.ContactPerson
            {
                ContactType = Kernel.Federation.MetaData.Configuration.Organisation.ContactType.Technical,
                ForeName    = "John",
                SurName     = "Doe",
            };

            contact.Emails.Add("*****@*****.**");
            contact.PhoneNumbers.Add("020123456");

            orgConfiguration.OrganisationContacts.PersonContact.Add(contact);
            return(orgConfiguration);
        }
Example #3
0
        public static OrganisationConfiguration BuikdOrganisationConfiguration()
        {
            var orgConfiguration = new OrganisationConfiguration
            {
                OrganisationContacts = new ContactConfiguration()
            };

            orgConfiguration.Names.Add(new LocalizedConfigurationEntry
            {
                Name        = "Apira LTD",
                DisplayName = "Flowz",
            });
            orgConfiguration.Urls.Add(new LocalizedUrlEntry {
                Url = new Uri("https://apira.co.uk/")
            });

            var contact = new Kernel.Federation.MetaData.Configuration.Organisation.ContactPerson
            {
                ContactType = Kernel.Federation.MetaData.Configuration.Organisation.ContactType.Technical,
                ForeName    = "John",
                SurName     = "Murphy",
            };

            contact.Emails.Add("*****@*****.**");
            contact.PhoneNumbers.Add("020xxx");

            orgConfiguration.OrganisationContacts.PersonContact.Add(contact);
            return(orgConfiguration);
        }
        private static OrganisationConfiguration BuidOrganisationConfiguration(OrganisationSettings organisationSettings)
        {
            var orgConfiguration = new OrganisationConfiguration
            {
                OrganisationContacts = new ContactConfiguration()
            };

            if (organisationSettings != null)
            {
                organisationSettings.Names.Aggregate(orgConfiguration.Names, (t, next) =>
                {
                    t.Add(new LocalizedConfigurationEntry
                    {
                        Name        = next.Name,
                        DisplayName = String.IsNullOrEmpty(next.DisplayName) ? next.Name : next.DisplayName,
                        Language    = new CultureInfo(next.Language)
                    });
                    return(t);
                });

                organisationSettings.Urls.Aggregate(orgConfiguration.Urls, (t, next) =>
                {
                    t.Add(new LocalizedUrlEntry {
                        Url = new Uri(next.Name), Language = new CultureInfo(next.Language)
                    });
                    return(t);
                });
                organisationSettings.Contacts.Aggregate(orgConfiguration.OrganisationContacts.PersonContact, (t, next) =>
                {
                    var contact = new Kernel.Federation.MetaData.Configuration.Organisation.ContactPerson
                    {
                        ContactType = next.ContactType,
                        ForeName    = next.Forename.Name,
                        SurName     = next.Surname.Name,
                    };
                    next.Emails.Aggregate(contact.Emails, (t1, next1) =>
                    {
                        contact.Emails.Add(next1.Name);
                        return(t1);
                    });

                    next.Phones.Aggregate(contact.PhoneNumbers, (t2, next2) =>
                    {
                        contact.PhoneNumbers.Add(next2.Number);
                        return(t2);
                    });

                    t.Add(contact);
                    return(t);
                });
            }
            return(orgConfiguration);
        }
        internal static void BuildContacts(ICollection <System.IdentityModel.Metadata.ContactPerson> contacts, OrganisationConfiguration organisationConfiguration)
        {
            if (contacts == null)
            {
                throw new ArgumentNullException("contacts");
            }
            if (organisationConfiguration == null || organisationConfiguration.OrganisationContacts == null || organisationConfiguration.OrganisationContacts.PersonContact == null)
            {
                return;
            }

            organisationConfiguration.OrganisationContacts.PersonContact.Aggregate(contacts, (c, next) =>
            {
                System.IdentityModel.Metadata.ContactType contactType;
                if (!Enum.TryParse <System.IdentityModel.Metadata.ContactType>(next.ContactType.ToString(), out contactType))
                {
                    throw new InvalidCastException(String.Format("No corespondenting value for Contact type: {0}.", next.ContactType));
                }
                var cp = new System.IdentityModel.Metadata.ContactPerson(contactType)
                {
                    Surname   = next.SurName,
                    GivenName = next.ForeName,
                };
                next.Emails.Aggregate(cp.EmailAddresses, (p, nextEmail) => { p.Add(nextEmail); return(p); });
                next.PhoneNumbers.Aggregate(cp.TelephoneNumbers, (p, nextNumber) => { p.Add(nextNumber); return(p); });
                c.Add(cp);
                return(c);
            });
        }
        private static SPSSODescriptorConfiguration BuildSPSSODescriptorConfiguration(SPDescriptorSettings sPDescriptor, OrganisationConfiguration organisation)
        {
            var sPSSODescriptorConfiguration = new SPSSODescriptorConfiguration
            {
                WantAssertionsSigned         = sPDescriptor.WantAssertionsSigned,
                ValidUntil                   = sPDescriptor.ValidUntil,
                Organisation                 = organisation,
                AuthenticationRequestsSigned = sPDescriptor.RequestSigned,
                CacheDuration                = MetadataHelper.TimeSpanFromDatapartEntry(sPDescriptor.CacheDuration),
                RoleDescriptorType           = typeof(ServiceProviderSingleSignOnDescriptor),
                ErrorUrl = new Uri(sPDescriptor.ErrorUrl)
            };

            sPDescriptor.NameIdFormats.Aggregate(sPSSODescriptorConfiguration, (c, next) =>
            {
                c.NameIdentifierFormats.Add(new Uri(next.Uri));
                return(c);
            });

            //logout services
            sPDescriptor.LogoutServices.Aggregate(sPSSODescriptorConfiguration.SingleLogoutServices, (t, next) =>
            {
                t.Add(new EndPointConfiguration
                {
                    Binding  = new Uri(next.Binding.Uri),
                    Location = new Uri(next.Url)
                });
                return(t);
            });
            //supported protocols
            sPDescriptor.Protocols.Aggregate(sPSSODescriptorConfiguration.ProtocolSupported, (t, next) =>
            {
                t.Add(new Uri(next.Uri));
                return(t);
            });

            //key descriptors

            sPDescriptor.Certificates.Aggregate(sPSSODescriptorConfiguration.KeyDescriptors, (t, next) =>
            {
                var keyDescriptorConfiguration = MetadataHelper.BuildKeyDescriptorConfiguration(next);
                t.Add(keyDescriptorConfiguration);
                return(t);
            });

            //assertion service
            sPDescriptor.AssertionServices.Aggregate(sPSSODescriptorConfiguration.AssertionConsumerServices, (t, next) =>
            {
                var indexedEndPointConfiguration = new IndexedEndPointConfiguration
                {
                    Index     = next.Index,
                    IsDefault = next.IsDefault,
                    Binding   = new Uri(next.Binding.Uri),
                    Location  = new Uri(next.Url)
                };
                t.Add(indexedEndPointConfiguration);
                return(t);
            });

            return(sPSSODescriptorConfiguration);
        }