示例#1
0
        public async Task <IActionResult> University(AuthConfig config)
        {
            if (!ModelState.IsValid)
            {
                config.University = await GetClaimedUniversity(await GetCurrentUserAsync(), config.UniversityId);

                return(View("ManageUniversity", config));
            }

            var authConfigService = new AuthConfigService(new SqlAuthConfigRepository(_dbContext), _samlConfigurations);
            await authConfigService.SaveAsync(config);

            var universityService = new UniversityService(new SqlUniversityRepository(_dbContext));
            var claimedUniversity = await universityService.FindByIdAsync(config.UniversityId);

            var serverService = new ServerService(new SqlServerRepository(_dbContext));
            await serverService.EnableAuthAsync(claimedUniversity.Server);

            var membershipService = new MembershipService(new SqlMembershipRepository(_dbContext));

            foreach (var channel in claimedUniversity.Server.Channels)
            {
                await membershipService.DropMembershipsAsync(channel);
            }

            return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.ManageUniversitySuccess }));
        }
示例#2
0
        public async Task <IActionResult> AssertionConsumerService()
        {
            // Receive and process the SAML assertion contained in the SAML response.
            // The SAML response is received either as part of IdP-initiated or SP-initiated SSO.
            var ssoResult = await _samlServiceProvider.ReceiveSsoAsync();

            if (string.IsNullOrEmpty(ssoResult.RelayState))
            {
                // This was a test initiated from the manage page
                return(RedirectToAction("Index", "Manage", new { Message = ManageController.ManageMessageId.TestSamlSuccess }));
            }

            // This is a mess, but there's no other way to find the current user because
            // this controller hides the current identity for some reason
            var user = await _userManager.FindByIdAsync(ssoResult.RelayState.Split(',')[0]);

            var universityService = new UniversityService(new SqlUniversityRepository(_dbContext));
            var university        = await universityService.FindByIdAsync(int.Parse(ssoResult.RelayState.Split(',')[1]));

            var authConfigService = new AuthConfigService(new SqlAuthConfigRepository(_dbContext), null);
            var authConfig        = await authConfigService.GetConfigAsync(university);

            await universityService.JoinAsync(user, university, authConfig.OverrideUsernames?ssoResult.UserID : null);

            return(RedirectToAction("Index", "Chat"));
        }
示例#3
0
 public ChatController(WarblerDbContext context)
 {
     UserService            = new UserService(new SqlUserRepository(context));
     UniversityService      = new UniversityService(new SqlUniversityRepository(context));
     AuthConfigService      = new AuthConfigService(new SqlAuthConfigRepository(context), null);
     ChannelTemplateService = new ChannelTemplateService(new SqlChannelTemplateRepository(context));
 }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement      = true,
                    ReactHotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            var dbContext = serviceProvider.GetService <WarblerDbContext>();

            if (dbContext.Database.EnsureCreated())
            {
                new ChannelTemplateService(new SqlChannelTemplateRepository(dbContext))
                .CreateDefaultTemplatesAsync()
                .Wait();
            }

            var samlConfigs       = serviceProvider.GetService <SamlConfigurations>();
            var authConfigService = new AuthConfigService(new SqlAuthConfigRepository(dbContext), samlConfigs);

            authConfigService.RefreshConfigsAsync().Wait();

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseWebSockets();
            app.UseSignalR(routes =>
            {
                routes.MapHub <ProximityHub>(nameof(ProximityHub));
                routes.MapHub <ChatHub>(nameof(ChatHub));
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areaRoute",
                    template: "{area:exists}/{controller=Home}/{action=Index}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#5
0
        public async Task <string> Join([FromBody] NearByResult userChoice)
        {
            var user = await UserService.FindByNameAsync(User.Identity.Name);

            var university = await UniversityService.GetOrCreateAsync(userChoice, await ChannelTemplateService.GetAsync());

            var isAlreadyMember = university.Server.Channels
                                  .Any(ch => ch.Memberships.Any(m => m.User.Equals(user)));

            if (isAlreadyMember)
            {
                return("/Chat");
            }
            if (university.Server.IsAuthEnabled)
            {
                var partner = await AuthConfigService.GetConfigAsync(university);

                return($"/Account/SingleSignOn?partnerName={partner.Name}&relayState={user.Id},{university.Id}");
            }
            await UniversityService.JoinAsync(user, university);

            return("/Chat");
        }