Ejemplo n.º 1
0
        protected void No_Click(object sender, EventArgs e)
        {
            this.RegisterAsyncTask(
                new PageAsyncTask(
                    async ct => {
                if (ProviderEndpoint.PendingRequest == null)
                {
                    return;
                }

                if (ProviderEndpoint.PendingAuthenticationRequest != null)
                {
                    ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = false;
                }
                else
                {
                    ProviderEndpoint.PendingAnonymousRequest.IsApproved = false;
                }
                Debug.Assert(
                    ProviderEndpoint.PendingRequest.IsResponseReady, "Setting authentication should be all that's necessary.");
                var provider = new ProviderEndpoint();
                var response = await provider.PrepareResponseAsync();
                await response.SendAsync();
            }));
        }
Ejemplo n.º 2
0
        public void SimpleEnabled()
        {
            ProviderEndpoint pe = new ProviderEndpoint();

            Assert.IsTrue(pe.Enabled);
            pe.Enabled = false;
            Assert.IsFalse(pe.Enabled);
        }
Ejemplo n.º 3
0
        protected void Yes_Click(object sender, EventArgs e)
        {
            this.RegisterAsyncTask(
                new PageAsyncTask(
                    async ct => {
                if (!Page.IsValid || ProviderEndpoint.PendingRequest == null)
                {
                    return;
                }

                if (this.OAuthPanel.Visible)
                {
                    string grantedScope = null;
                    if (this.oauthPermission.Checked)
                    {
                        // This SIMPLE sample merely uses the realm as the consumerKey,
                        // but in a real app this will probably involve a database lookup to translate
                        // the realm to a known consumerKey.
                        grantedScope = string.Empty;                                         // we don't scope individual access rights on this sample
                    }

                    OAuthHybrid.ServiceProvider.AttachAuthorizationResponse(ProviderEndpoint.PendingRequest, grantedScope);
                }

                var sregRequest             = ProviderEndpoint.PendingRequest.GetExtension <ClaimsRequest>();
                ClaimsResponse sregResponse = null;
                if (sregRequest != null)
                {
                    sregResponse = this.profileFields.GetOpenIdProfileFields(sregRequest);
                    ProviderEndpoint.PendingRequest.AddResponseExtension(sregResponse);
                }
                var papeRequest             = ProviderEndpoint.PendingRequest.GetExtension <PolicyRequest>();
                PolicyResponse papeResponse = null;
                if (papeRequest != null)
                {
                    papeResponse = new PolicyResponse();
                    papeResponse.NistAssuranceLevel = NistAssuranceLevel.InsufficientForLevel1;
                    ProviderEndpoint.PendingRequest.AddResponseExtension(papeResponse);
                }

                if (ProviderEndpoint.PendingAuthenticationRequest != null)
                {
                    ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = true;
                }
                else
                {
                    ProviderEndpoint.PendingAnonymousRequest.IsApproved = true;
                }
                Debug.Assert(
                    ProviderEndpoint.PendingRequest.IsResponseReady, "Setting authentication should be all that's necessary.");

                var provider = new ProviderEndpoint();
                var response = await provider.PrepareResponseAsync();
                await response.SendAsync();
            }));
        }
Ejemplo n.º 4
0
        protected void cancelButton_Click(object sender, EventArgs e)
        {
            var req = ProviderEndpoint.PendingAuthenticationRequest;

            if (req != null)
            {
                req.IsAuthenticated = false;
                ProviderEndpoint.SendResponse();
            }
        }
Ejemplo n.º 5
0
        public ActionResult EditProviderEndpoint(int id, int endpointId, ProviderEndpointModel model)
        {
            // Edit endpoint details
            ProviderEndpoint endpoint = _applications.EditEndpoint(id, endpointId, model, LoggedInUser);

            // Setup status
            Toastr.Success("Changes to endpoint were successfully saved.");

            // Return result
            return(RedirectToAction("Details", new { endpointId = endpoint.ApplicationId }));
        }
        public static ProviderEndpointModel ToModel(this ProviderEndpoint endpoint)
        {
            var result = new ProviderEndpointModel();

            result.Name          = endpoint.Name;
            result.Uri           = endpoint.ServiceUri;
            result.Description   = endpoint.Description;
            result.ID            = endpoint.ID;
            result.LastUpdatedAt = endpoint.UpdatedAt;
            result.IsActive      = endpoint.IsActive;
            return(result);
        }
Ejemplo n.º 7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     // The user may have just completed a login.  If they're logged in, see if we can complete the OpenID login.
     if (User.Identity.IsAuthenticated && ProviderEndpoint.PendingAuthenticationRequest != null)
     {
         Util.ProcessAuthenticationChallenge(ProviderEndpoint.PendingAuthenticationRequest);
         if (ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated.HasValue)
         {
             ProviderEndpoint.SendResponse();
         }
     }
 }
Ejemplo n.º 8
0
        protected override async Task ProcessRequestAsync(HttpContext context)
        {
            var      providerEndpoint = new ProviderEndpoint();
            IRequest request          = await providerEndpoint.Provider.GetRequestAsync(new HttpRequestWrapper(context.Request), context.Response.ClientDisconnectedToken);

            if (request != null)
            {
                // Some OpenID requests are automatable and can be responded to immediately.
                // But authentication requests cannot be responded to until something on
                // this site decides whether to approve or disapprove the authentication.
                if (!request.IsResponseReady)
                {
                    // We store the request in the user's session so that
                    // redirects and user prompts can appear and eventually some page can decide
                    // to respond to the OpenID authentication request either affirmatively or
                    // negatively.
                    ProviderEndpoint.PendingRequest = request as IHostProcessedRequest;

                    // We delegate that approval process to our utility method that we share
                    // with our other Provider sample page server.aspx.
                    if (ProviderEndpoint.PendingAuthenticationRequest != null)
                    {
                        Code.Util.ProcessAuthenticationChallenge(ProviderEndpoint.PendingAuthenticationRequest);
                    }
                    else if (ProviderEndpoint.PendingAnonymousRequest != null)
                    {
                        Code.Util.ProcessAnonymousRequest(ProviderEndpoint.PendingAnonymousRequest);
                    }

                    // As part of authentication approval, the user may need to authenticate
                    // to this Provider and/or decide whether to allow the requesting RP site
                    // to log this user in.  If any UI needs to be presented to the user,
                    // the previous call to ProcessAuthenticationChallenge MAY not return
                    // due to a redirect to some ASPX page.
                }

                // Whether this was an automated message or an authentication message,
                // if there is a response ready to send back immediately, do so.
                if (request.IsResponseReady)
                {
                    // We DON'T use ProviderEndpoint.SendResponse because
                    // that only sends responses to requests in PendingAuthenticationRequest,
                    // but we don't set that for associate and other non-checkid requests.
                    var response = await providerEndpoint.Provider.PrepareResponseAsync(request, context.Response.ClientDisconnectedToken);

                    // Make sure that any PendingAuthenticationRequest that MAY be set is cleared.
                    ProviderEndpoint.PendingRequest = null;

                    await response.SendAsync(new HttpContextWrapper(context));
                }
            }
        }
Ejemplo n.º 9
0
 protected void No_Click(object sender, EventArgs e)
 {
     if (ProviderEndpoint.PendingAuthenticationRequest != null)
     {
         ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated = false;
     }
     else
     {
         ProviderEndpoint.PendingAnonymousRequest.IsApproved = false;
     }
     Debug.Assert(ProviderEndpoint.PendingRequest.IsResponseReady, "Setting authentication should be all that's necessary.");
     ProviderEndpoint.SendResponse();
 }
Ejemplo n.º 10
0
 protected void cancelButton_Click(object sender, EventArgs e)
 {
     this.RegisterAsyncTask(
         new PageAsyncTask(
             async ct => {
         var req = ProviderEndpoint.PendingAuthenticationRequest;
         if (req != null)
         {
             req.IsAuthenticated  = false;
             var providerEndpoint = new ProviderEndpoint();
             var response         = await providerEndpoint.PrepareResponseAsync(Response.ClientDisconnectedToken);
             await response.SendAsync(new HttpContextWrapper(this.Context), Response.ClientDisconnectedToken);
             this.Context.Response.End();
         }
     }));
 }
Ejemplo n.º 11
0
        public void AddEndpoint(int id, ProviderEndpointModel model, LoggedInUserDetails user)
        {
            // Check whether organisation is not active
            if (!user.Organization.IsActive)
            {
                throw new BaseException("Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator.");
            }

            // Check whether application does not belong to user
            _security.CheckAccessToApplication(user, id);

            // Get schema identifiers used by this application
            var usedSchemas = _endpoints.Where(i => i.ApplicationId == id).Select(i => i.DataSchemaID);

            // Get all published schemas
            var schemas = _schemas.Where(i => i.Status == (int)TemplateStatus.Active).Select(i => i.ID);

            // Get unused published schemas
            var availableSchemas = schemas.Except(usedSchemas).ToList();

            // Check whether no available schemas found
            if (!availableSchemas.Any() || !availableSchemas.Contains(model.SelectedSchemaID))
            {
                // Return error if all schemas in use
                throw new BaseException("Your application already uses all available schemas. DataLinker allows only one endpoint per schema.");
            }

            // Get selected schema
            var dataSchema = _schemas.FirstOrDefault(i => i.ID == model.SelectedSchemaID);

            // Setup endpoint details
            var endPoint = new ProviderEndpoint
            {
                DataSchemaID   = model.SelectedSchemaID,
                ApplicationId  = id,
                CreatedAt      = GetDate,
                CreatedBy      = user.ID.Value,
                Description    = model.Description,
                IsActive       = true,
                IsIndustryGood = dataSchema.IsIndustryGood,
                Name           = string.IsNullOrEmpty(model.Name) ? string.Empty : model.Name,
                ServiceUri     = model.Uri
            };

            // Save new endpoint
            _endpoints.Add(endPoint);
        }
Ejemplo n.º 12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.RegisterAsyncTask(
         new PageAsyncTask(
             async ct => {
         // The user may have just completed a login.  If they're logged in, see if we can complete the OpenID login.
         if (User.Identity.IsAuthenticated && ProviderEndpoint.PendingAuthenticationRequest != null)
         {
             await
             Util.ProcessAuthenticationChallengeAsync(
                 ProviderEndpoint.PendingAuthenticationRequest, Response.ClientDisconnectedToken);
             if (ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated.HasValue)
             {
                 var providerEndpoint = new ProviderEndpoint();
                 var responseMessage  = await providerEndpoint.PrepareResponseAsync(this.Response.ClientDisconnectedToken);
                 await responseMessage.SendAsync(new HttpContextWrapper(this.Context), this.Response.ClientDisconnectedToken);
                 this.Context.Response.End();
             }
         }
     }));
 }
Ejemplo n.º 13
0
        private List <schemaEndpoint> GetSchemaEndpoints(ProviderEndpoint endpoint,
                                                         IList <OrganizationLicense> licenses, DataSchema schema, string appName)
        {
            var result = new List <schemaEndpoint>();

            // provider should has a published license for endpoint
            if (licenses.Any(i => i.ProviderEndpointID == endpoint.ID))
            {
                // Setup model for endpoint model
                var schemaEndpoint = new schemaEndpoint
                {
                    Endpoint = new endpointDetails
                    {
                        ServiceUri  = endpoint.ServiceUri,
                        Description = endpoint.Description,
                        Name        = appName
                    },
                    Schema = schema.ToDetails()
                };
                // Add model to result
                result.Add(schemaEndpoint);
            }
            return(result);
        }
Ejemplo n.º 14
0
        public void Init()
        {
            sysAdmin = new User
            {
                Email          = "*****@*****.**",
                ID             = 1,
                IsActive       = true,
                IsSysAdmin     = true,
                OrganizationID = 2
            };

            otherOrganization = new Organization
            {
                ID       = 3,
                Name     = "OrgName3",
                IsActive = true
            };

            user = new User
            {
                Email          = "*****@*****.**",
                ID             = 2,
                IsSysAdmin     = false,
                OrganizationID = 2
            };

            otherUser = new User
            {
                Email          = "*****@*****.**",
                ID             = 3,
                IsSysAdmin     = false,
                OrganizationID = otherOrganization.ID
            };

            organization = new Organization
            {
                ID       = 2,
                Name     = "OrgName2",
                IsActive = true
            };


            activeService = new Application
            {
                OrganizationID             = organization.ID,
                IsActive                   = true,
                Name                       = "activeService",
                PublicID                   = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"),
                ID                         = 1,
                IsIntroducedAsIndustryGood = true,
                IsProvider                 = true
            };

            consumerApplication = new Application
            {
                OrganizationID = 2,
                IsActive       = true,
                Name           = "active applications",
                PublicID       = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"),
                ID             = 4,
                IsProvider     = false
            };

            notActiveService = new Application
            {
                OrganizationID = 2,
                IsActive       = false,
                Name           = "notActiveService",
                PublicID       = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"),
                ID             = 2,
                IsProvider     = false
            };

            otherService = new Application
            {
                OrganizationID = 3,
                IsActive       = true,
                Name           = "otherService",
                PublicID       = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"),
                ID             = 3,
                IsProvider     = false
            };

            dataSchema = new DataSchema
            {
                ID   = 1,
                Name = "Schema1"
            };

            providerEndpoint = new ProviderEndpoint
            {
                ApplicationId  = activeService.ID,
                ID             = 1,
                DataSchemaID   = dataSchema.ID,
                IsIndustryGood = true,
                Description    = "Description"
            };

            licenseTemplate = new LicenseTemplate
            {
                ID        = 1,
                LicenseID = 1,
                Status    = (int)TemplateStatus.Active
            };

            _organizationLicense = new OrganizationLicense
            {
                ID                 = 1,
                Status             = (int)PublishStatus.Published,
                ProviderEndpointID = providerEndpoint.ID,
                DataSchemaID       = providerEndpoint.DataSchemaID,
                LicenseTemplateID  = licenseTemplate.ID
            };
            applicationToken = new ApplicationToken
            {
                ID            = 1,
                ApplicationID = activeService.ID,
                Token         = "token"
            };

            appService                       = new Mock <IApplicationsService>();
            _userService                     = new Mock <IUserService>();
            orgService                       = new Mock <IOrganizationService>();
            schemaService                    = new Mock <IDataSchemaService>();
            endpointService                  = new Mock <IProviderEndpointService>();
            licenseTemplateService           = new Mock <ILicenseTemplatesService>();
            sectionService                   = new Mock <ILicenseSectionService>();
            clauseService                    = new Mock <ILicenseClauseService>();
            clauseTemplateService            = new Mock <ILicenseClauseTemplateService>();
            endpointLicClauseService         = new Mock <IOrganizationLicenseClauseService>();
            licenseService                   = new Mock <IOrganizationLicenseService>();
            notificationService              = new Mock <INotificationService>();
            applicationTokenService          = new Mock <IService <ApplicationToken> >();
            applicationAuthenticationService = new Mock <IService <ApplicationAuthentication> >();
            configService                    = new Mock <IConfigurationService>();
            licenseContentBuilder            = new Mock <ILicenseContentBuilder>();
            adminNotificationService         = new Mock <IAdminNotificationService>();
            // Notification service
            notificationService.Setup(i => i.Admin).Returns(adminNotificationService.Object);
            configService.SetupProperty(p => p.ManageApplicationsPageSize, 5);
            var mockUrl = new Mock <UrlHelper>();

            // Setup application token service
            applicationTokenService.Setup(i => i.Get(applicationToken.ID)).Returns(applicationToken);
            applicationTokenService.Setup(i => i.Add(It.IsAny <ApplicationToken>())).Returns(true);
            applicationTokenService.Setup(i => i.Update(It.IsAny <ApplicationToken>())).Returns(true);
            // Schema service
            schemaService.Setup(p => p.Get(dataSchema.ID)).Returns(dataSchema);
            schemaService.Setup(p => p.Get(10)).Returns(new DataSchema {
                ID = 10, IsIndustryGood = false
            });
            schemaService.Setup(p => p.GetPublishedSchemas()).Returns(new List <DataSchema> {
                dataSchema, new DataSchema {
                    ID = 10, IsIndustryGood = false
                }
            });

            // Endpoint service
            endpointService.Setup(p => p.Get(It.IsAny <Expression <Func <ProviderEndpoint, bool> > >()))
            .Returns(new List <ProviderEndpoint> {
                providerEndpoint
            });
            endpointService.Setup(p => p.Get(providerEndpoint.ID)).Returns(providerEndpoint);

            licenseService.Setup(p => p.Get(It.IsAny <Expression <Func <OrganizationLicense, bool> > >()))
            .Returns(new List <OrganizationLicense> {
                _organizationLicense
            });

            // License template service
            licenseTemplateService.Setup(p => p.GetAll(false)).Returns(new List <LicenseTemplate> {
                licenseTemplate
            });
            licenseTemplateService.Setup(p => p.GetPublishedGlobalLicense()).Returns(licenseTemplate);

            // Application service
            appService.Setup(p => p.GetApplicationsFor((int)user.OrganizationID))
            .Returns(new List <Application> {
                activeService, notActiveService
            });
            appService.Setup(p => p.GetAllApplications())
            .Returns(new List <Application> {
                activeService, otherService, notActiveService
            });
            appService.Setup(p => p.Get(activeService.ID)).Returns(activeService);
            appService.Setup(p => p.Get(notActiveService.ID)).Returns(notActiveService);
            appService.Setup(p => p.Get(otherService.ID)).Returns(otherService);
            appService.Setup(p => p.Get(consumerApplication.ID)).Returns(consumerApplication);
            appService.Setup(p => p.GetAuthenticationFor(activeService.ID)).Returns(new ApplicationAuthentication());

            // Organization service
            orgService.Setup(p => p.Get(organization.ID)).Returns(organization);
            orgService.Setup(p => p.Get(otherOrganization.ID)).Returns(otherOrganization);

            var context = new Mock <ControllerContext>();

            context.Setup(m => m.HttpContext.Request.Form).Returns(new FormCollection());
            context.Setup(m => m.HttpContext.Request.Url).Returns(new Uri("http://test.com"));
            context.Setup(m => m.HttpContext.Request.Browser).Returns(new Mock <HttpBrowserCapabilitiesBase>().Object);

            controller = new ApplicationsController(appService.Object, applicationTokenService.Object,
                                                    applicationAuthenticationService.Object, _userService.Object,
                                                    orgService.Object, schemaService.Object, endpointService.Object,
                                                    licenseService.Object, configService.Object,
                                                    notificationService.Object);
            controller.ControllerContext = context.Object;
            controller.Url = mockUrl.Object;
        }
        public void Init()
        {
            schemaModel = new SchemaModel
            {
                DataSchemaID = 1,
                Description  = "Blah blah",
                Name         = "Name",
                Status       = TemplateStatus.Draft,
                Version      = 1
            };

            dSchemaDraft = new DataSchema
            {
                ID        = 1,
                Name      = "Draft",
                CreatedBy = 1,
                CreatedAt = today,
                Status    = (int)TemplateStatus.Draft
            };

            dSchemaPublished = new DataSchema
            {
                ID          = 2,
                Name        = "Published",
                CreatedAt   = today,
                CreatedBy   = 1,
                PublishedAt = today
            };

            dSchemaRetracted = new DataSchema
            {
                ID        = 3,
                Name      = "Retracted",
                CreatedAt = today,
                Status    = (int)TemplateStatus.Retracted
            };

            schemaFile = new SchemaFile
            {
                DataSchemaID = dSchemaDraft.ID,
                CreatedBy    = 1,
                FileFormat   = ".xml",
                ID           = 1
            };
            consumerOrganization = new Organization
            {
                ID = 1
            };
            providerOrganization = new Organization
            {
                ID = 2
            };
            providerApplication = new Application
            {
                ID             = 1,
                OrganizationID = providerOrganization.ID
            };
            consumerApplication = new Application
            {
                ID             = 2,
                OrganizationID = consumerOrganization.ID
            };
            providerLicense = new OrganizationLicense
            {
                ID            = 1,
                ApplicationID = providerApplication.ID
            };
            consumerLicense = new OrganizationLicense
            {
                ID            = 2,
                ApplicationID = consumerApplication.ID
            };
            licenseMatch = new LicenseMatch
            {
                ID = 1,
                ConsumerLicenseID = consumerLicense.ID,
                ProviderLicenseID = providerLicense.ID
            };
            endpoint = new ProviderEndpoint
            {
                ApplicationId = providerApplication.ID,
                DataSchemaID  = dSchemaPublished.ID,
                IsActive      = true
            };

            var file = new Mock <HttpPostedFileBase>();

            file.Setup(i => i.InputStream).Returns(new MemoryStream());
            file.Setup(i => i.FileName).Returns("file.xml");
            schemaModel.UploadFile = file.Object;
            var mock = new Mock <UrlHelper>();
            // Setup file
            var fileMock = new Mock <HttpPostedFileBase>();

            fileMock.Setup(x => x.FileName).Returns("file1.xml");
            var context = new Mock <ControllerContext>();

            context.Setup(m => m.HttpContext.Request.Files.Count).Returns(1);
            context.Setup(m => m.HttpContext.Request.Files[0]).Returns(fileMock.Object);
            context.Setup(m => m.HttpContext.Request.Url).Returns(new Uri("http://test.com"));
            sysAdmin = new User
            {
                ID         = 1,
                IsActive   = true,
                Email      = "*****@*****.**",
                IsSysAdmin = true
            };

            // Setup Services
            metaDataService            = new Mock <IDataSchemaService>();
            fileService                = new Mock <ISchemaFileService>();
            organizationService        = new Mock <IOrganizationService>();
            userService                = new Mock <IUserService>();
            notificationService        = new Mock <INotificationService>();
            endpointService            = new Mock <IProviderEndpointService>();
            applicationService         = new Mock <IApplicationsService>();
            configurationService       = new Mock <IConfigurationService>();
            organizationLicenseService = new Mock <IOrganizationLicenseService>();

            userService.Setup(u => u.Get(sysAdmin.ID)).Returns(sysAdmin);
            configurationService.SetupProperty(p => p.ManageSchemasPageSize, 5);
            // Setup organization service
            organizationService.Setup(m => m.Get(consumerOrganization.ID)).Returns(consumerOrganization);
            organizationService.Setup(m => m.Get(providerOrganization.ID)).Returns(providerOrganization);
            // Setup application service
            applicationService.Setup(m => m.Get(providerApplication.ID)).Returns(providerApplication);
            applicationService.Setup(m => m.Get(consumerApplication.ID)).Returns(consumerApplication);
            // Setup endpoint service
            endpointService.Setup(m => m.Get(endpoint.ID)).Returns(endpoint);
            // Setup organization licenses
            organizationLicenseService.Setup(i => i.Get(It.IsAny <Expression <Func <OrganizationLicense, bool> > >()))
            .Returns(new List <OrganizationLicense>());
            organizationLicenseService.Setup(m => m.GetAllProviderLicensesForMonth(It.IsAny <DateTime>()))
            .Returns(new List <OrganizationLicense> {
                providerLicense
            });
            organizationLicenseService.Setup(m => m.Get(consumerLicense.ID)).Returns(consumerLicense);
            // Schema file service
            fileService.Setup(m => m.Add(It.IsAny <SchemaFile>())).Returns(true);
            fileService.Setup(m => m.Update(It.IsAny <SchemaFile>())).Returns(true);
            fileService.Setup(m => m.Get(schemaFile.ID)).Returns(schemaFile);
            fileService.Setup(m => m.Get(It.IsAny <Expression <Func <SchemaFile, bool> > >()))
            .Returns(new List <SchemaFile> {
                schemaFile
            });
            // Dataschema service
            metaDataService.Setup(m => m.GetAllSchemas(1, false)).Returns(new List <DataSchema> {
                dSchemaDraft
            });
            metaDataService.Setup(m => m.Add(It.IsAny <DataSchema>())).Returns(true);
            metaDataService.Setup(m => m.Update(It.IsAny <DataSchema>())).Returns(true);
            metaDataService.Setup(m => m.Get(dSchemaDraft.ID)).Returns(dSchemaDraft);
            metaDataService.Setup(m => m.Get(dSchemaPublished.ID)).Returns(dSchemaPublished);
            metaDataService.Setup(m => m.Get(dSchemaRetracted.ID)).Returns(dSchemaRetracted);

            // License matches
            var mService = new MockService <LicenseMatch>();

            matchesService = new LicenseMatchesService(mService);
            matchesService.Add(licenseMatch);

            // Setup controller
            controller = new SchemasController(metaDataService.Object, fileService.Object, userService.Object,
                                               organizationService.Object, endpointService.Object, applicationService.Object, notificationService.Object, organizationLicenseService.Object, matchesService, configurationService.Object)
            {
                ControllerContext = context.Object,
                LoggedInUser      = new LoggedInUserDetails(sysAdmin),
                Url = mock.Object
            };
        }
Ejemplo n.º 16
0
        internal static async Task ProcessAuthenticationChallengeAsync(IAuthenticationRequest idrequest, CancellationToken cancellationToken)
        {
            // Verify that RP discovery is successful.
            var providerEndpoint = new ProviderEndpoint();

            if (await idrequest.IsReturnUrlDiscoverableAsync(providerEndpoint.Provider.Channel.HostFactories, cancellationToken) != RelyingPartyDiscoveryResult.Success)
            {
                idrequest.IsAuthenticated = false;
                return;
            }

            // Verify that the RP is on the whitelist.  Realms are case sensitive.
            string[] whitelist = ConfigurationManager.AppSettings["whitelistedRealms"].Split(';');
            if (Array.IndexOf(whitelist, idrequest.Realm.ToString()) < 0)
            {
                idrequest.IsAuthenticated = false;
                return;
            }

            if (idrequest.IsDirectedIdentity)
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    idrequest.LocalIdentifier = Util.BuildIdentityUrl();
                    idrequest.IsAuthenticated = true;
                }
                else
                {
                    // If the RP demands an immediate answer, or if we're using implicit authentication
                    // and therefore have nothing further to ask the user, just reject the authentication.
                    if (idrequest.Immediate || ImplicitAuth)
                    {
                        idrequest.IsAuthenticated = false;
                    }
                    else
                    {
                        // Send the user to a page to actually log into the OP.
                        if (!HttpContext.Current.Request.Path.EndsWith("Login.aspx", StringComparison.OrdinalIgnoreCase))
                        {
                            HttpContext.Current.Response.Redirect("~/Login.aspx");
                        }
                    }
                }
            }
            else
            {
                string userOwningOpenIdUrl = Util.ExtractUserName(idrequest.LocalIdentifier);

                // NOTE: in a production provider site, you may want to only
                // respond affirmatively if the user has already authorized this consumer
                // to know the answer.
                idrequest.IsAuthenticated = userOwningOpenIdUrl == HttpContext.Current.User.Identity.Name;

                if (!idrequest.IsAuthenticated.Value && !ImplicitAuth && !idrequest.Immediate)
                {
                    // Send the user to a page to actually log into the OP.
                    if (!HttpContext.Current.Request.Path.EndsWith("Login.aspx", StringComparison.OrdinalIgnoreCase))
                    {
                        HttpContext.Current.Response.Redirect("~/Login.aspx");
                    }
                }
            }

            if (idrequest.IsAuthenticated.Value)
            {
                // add extension responses here.
                var fetchRequest = idrequest.GetExtension <FetchRequest>();
                if (fetchRequest != null)
                {
                    var fetchResponse = new FetchResponse();
                    if (fetchRequest.Attributes.Contains(RolesAttribute))
                    {
                        // Inform the RP what roles this user should fill
                        // These roles would normally come out of the user database
                        // or Windows security groups.
                        fetchResponse.Attributes.Add(RolesAttribute, "Member", "Admin");
                    }
                    idrequest.AddResponseExtension(fetchResponse);
                }
            }
        }
Ejemplo n.º 17
0
 public void Ctor()
 {
     ProviderEndpoint pe = new ProviderEndpoint();
 }