Ejemplo n.º 1
0
 private static void CreateIdentityProvider(string issuerName, string fedMetadataFile, ServiceManagementWrapper acsWrapper)
 {
     Console.Write(string.Format("Creating {0} identity provider....", issuerName));
     byte[] fedMetadata = File.ReadAllBytes(fedMetadataFile);
     acsWrapper.AddIdentityProvider(issuerName, fedMetadata);
     Console.WriteLine("done");
 }
        // POST
        public ActionResult CreateTenantFromFedMetadaFile(string organizationName, HttpPostedFileBase fedMetadataFile, HttpPostedFileBase logoFile, string adminClaimType, string adminClaimValue, string costCenterClaimType)
        {
            string organizationInternalName = this.SanitizeString(organizationName);

            if (this.IsOrganizationNameValid(organizationInternalName))
            {
                Organization organization = new Organization {
                    Name = organizationInternalName, DisplayName = organizationName, LogoPath = "~/Content/images/generic-logo.png"
                };

                if (logoFile != null && logoFile.ContentLength > 0)
                {
                    var imageFolderRelativePath = "~/Content/images/";
                    var imageFolderAbsolutePath = Server.MapPath("~/");
                    imageFolderAbsolutePath = string.Concat(imageFolderAbsolutePath, "..\\f-shipping.7\\Content\\images\\");
                    var fileName     = string.Concat(organizationInternalName, "-logo.png");
                    var fileFullPath = string.Concat(imageFolderAbsolutePath, fileName);
                    logoFile.SaveAs(fileFullPath);
                    organization.LogoPath = string.Concat(imageFolderRelativePath, fileName);
                }

                OrganizationRepository organizationRepository = new OrganizationRepository();
                organizationRepository.AddOrganization(organization);
                ServiceManagementWrapper acsWrapper = new ServiceManagementWrapper(acsServiceNamespace, acsUsername, acsPassword);

                // add the new IP
                var          identityProviderName = organizationInternalName;
                StreamReader sr = new StreamReader(fedMetadataFile.InputStream);
                byte[]       fedMetadataBytes = new byte[fedMetadataFile.InputStream.Length];
                fedMetadataFile.InputStream.Read(fedMetadataBytes, 0, (int)fedMetadataFile.InputStream.Length);
                acsWrapper.AddIdentityProvider(identityProviderName, fedMetadataBytes);

                var ruleGroup = string.Format("Default role group for {0}", organizationInternalName);

                this.CreateRelyingParty(organizationInternalName, identityProviderName, ruleGroup, acsWrapper);
                this.CreateRulesForTenantWithOwnIP(organizationInternalName, identityProviderName, acsWrapper, ruleGroup, adminClaimType, adminClaimValue, costCenterClaimType);

                return(View("CompleteEnrollment"));
            }
            return(View("EnrollWithFedMetadataFile", new EnrollmentViewModel {
                ErrorMessage = "Organization name not valid", OrganizationName = organizationName
            }));
        }