예제 #1
0
 public long AddOrganization(Organization organization, out string msg)
 {
     try
     {
         return(_organizationRepository.AddOrganization(organization, out msg));
     }
     catch (Exception ex)
     {
         msg = "Processing Error Occurred! Please try again later";
         BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        public ActionResult CreateTenantWithSocialProvider(string OrganizationName, HttpPostedFileBase logoFile)
        {
            string organizationInternalName = SanitizeString(OrganizationName);

            if (this.IsOrganizationNameValid(organizationInternalName))
            {
                var ipName = ClaimHelper.GetCurrentUserClaim(Fabrikam.ClaimTypes.IdentityProvider).Value;
                if (ipName == SocialIdentityProviders.WindowsLiveId.HomeRealm)
                {
                    ipName = SocialIdentityProviders.WindowsLiveId.DisplayName;
                }
                Organization organization = new Organization {
                    Name = organizationInternalName, DisplayName = OrganizationName, HomeRealm = ipName, 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);

                var relayingPartyName = organizationInternalName;
                var realmAddress      = string.Format("https://localhost/f-shipping.7/{0}", organizationInternalName);
                var replyAddress      = string.Format("https://localhost/f-shipping.7/{0}/FederationResult", organizationInternalName);
                var ruleGroup         = string.Format("Default role group for {0}", organizationInternalName);
                var socialProviders   = new string[] { ipName };

                acsWrapper.AddRelyingParty(organizationInternalName, realmAddress, replyAddress, null, null, null, ruleGroup, socialProviders);

                var nameIdentifierValue = ClaimHelper.GetCurrentUserClaim(ClaimTypes.NameIdentifier).Value;

                CreateRulesForTenantWithSocialIP(organizationInternalName, ipName, acsWrapper, ruleGroup, nameIdentifierValue);

                return(View("CompleteEnrollment"));
            }
            return(View("EnrollWithSocialProvider", new EnrollmentViewModel {
                ErrorMessage = "Organization name not valid", OrganizationName = OrganizationName
            }));
        }
        // POST
        public ActionResult CreateTenantManually(string organizationName, string issuerName, string iPStsAddress, string adminClaimType, string adminClaimValue, HttpPostedFileBase certificateFile, HttpPostedFileBase logoFile, 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 = issuerName;
                byte[] signingCertBytes     = new byte[certificateFile.InputStream.Length];
                certificateFile.InputStream.Read(signingCertBytes, 0, (int)certificateFile.InputStream.Length);
                acsWrapper.AddIdentityProviderManually(identityProviderName, iPStsAddress, WebSSOProtocolType.WsFederation, signingCertBytes, null);

                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("EnrollManually", new EnrollmentViewModel {
                ErrorMessage = "Organization name not valid", OrganizationName = organizationName
            }));
        }
 public bool AddOrganization(Organization organization)
 {
     return(organizationRepository.AddOrganization(organization));
 }