コード例 #1
0
ファイル: AppController.cs プロジェクト: lulzzz/SAMLPortal
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SAMLPortalContext context = new SAMLPortalContext();
            var app = await context.App.FindAsync(id);

            if (app == null)
            {
                return(NotFound());
            }
            return(View("Edit", app));
        }
コード例 #2
0
ファイル: AuthController.cs プロジェクト: lulzzz/SAMLPortal
        public IActionResult StartRequest(int id)
        {
            SAMLPortalContext context = new SAMLPortalContext();
            App requestedApp          = context.App.Where(app => app.Id == id).Single();

            if (requestedApp != null)
            {
                if (AccessControl(requestedApp))
                {
                    return(LoginResponse(new Saml2Id(), Saml2StatusCodes.Success, "", requestedApp, null, this.User.Claims));
                }
                else
                {
                    return(LoginResponse(new Saml2Id(), Saml2StatusCodes.RequestDenied, "", requestedApp, null, this.User.Claims));
                }
            }
            else
            {
                return(Content("You are not authorized"));
            }
        }
コード例 #3
0
ファイル: AppController.cs プロジェクト: lulzzz/SAMLPortal
        public async Task <IActionResult> Delete(int?id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(NotFound());
            }
            SAMLPortalContext context = new SAMLPortalContext();
            var app = await context.App.AsNoTracking().FirstOrDefaultAsync(m => m.Id == id);

            if (app == null)
            {
                return(NotFound());
            }

            if (saveChangesError.GetValueOrDefault())
            {
                ViewData["ErrorMessage"] =
                    "Delete failed. Try again, and if the problem persists " +
                    "see your system administrator.";
            }
            return(View(app));
        }
コード例 #4
0
ファイル: AppController.cs プロジェクト: lulzzz/SAMLPortal
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            SAMLPortalContext context = new SAMLPortalContext();
            var app = await context.App.FindAsync(id);

            if (app == null)
            {
                return(Redirect("/"));
            }

            try
            {
                context.App.Remove(app);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction(nameof(Delete), new { id = id, saveChangesError = true }));
            }
        }
コード例 #5
0
ファイル: AppController.cs プロジェクト: lulzzz/SAMLPortal
        public async Task <IActionResult> EditPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            SAMLPortalContext context = new SAMLPortalContext();
            var appToUpdate           = await context.App.FirstOrDefaultAsync(s => s.Id == id);

            if (await TryUpdateModelAsync <App>(
                    appToUpdate,
                    "",
                    s => s.Name,
                    s => s.Description,
                    s => s.Role,
                    s => s.Enabled,
                    s => s.MetadataURL,
                    s => s.Issuer,
                    s => s.SingleSignOnDestination,
                    s => s.SingleLogoutResponseDestination))
            {
                try
                {
                    await context.SaveChangesAsync();

                    return(Redirect("/"));
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            return(View("Edit", appToUpdate));
        }
コード例 #6
0
ファイル: Startup.cs プロジェクト: lulzzz/SAMLPortal
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, SAMLPortalContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                if (GlobalSettings.GetInt("CONFIG_SETUPASSISTANT_STEP") > 5)
                {
                    context.Database.Migrate();
                }
            }

            app.UseStaticFiles();
            app.UseRouting();

            // Middlewares goes under this comment

            app.UseSetupAssistantMiddleware();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //SAMLPortalContext context = new SAMLPortalContext();
            //if (!context.Setup.Any())
            //{
            //    Setup initialSetup = new Setup();
            //    initialSetup.IsConfigured = false;
            //    context.Add(initialSetup);
            //    context.SaveChanges();
            //}

            //App test = new App();
            //test.Name = "Gitlab";
            //test.Description = "An awesome GitHub alternative";
            //test.Enabled = true;
            //using (var context = new SAMLPortalContext())
            //{
            //    //context.Add(test);
            //    //context.SaveChanges();
            //    //Console.WriteLine("CHANGED");

            //    var allApps = context.App.ToList();
            //}
        }
コード例 #7
0
ファイル: AuthController.cs プロジェクト: lulzzz/SAMLPortal
        /// <summary>
        /// Search in the database the App corresponding to the given issuer.
        /// </summary>
        /// <param name="issuer"></param>
        /// <returns></returns>
        private static App ValidateApp(string issuer)
        {
            SAMLPortalContext context = new SAMLPortalContext();

            return(context.App.Where(app => app.Issuer != null && app.Issuer.Equals(issuer, StringComparison.InvariantCultureIgnoreCase)).Single());
        }
コード例 #8
0
ファイル: AppController.cs プロジェクト: lulzzz/SAMLPortal
        // GET: App
        public ActionResult Index()
        {
            SAMLPortalContext context = new SAMLPortalContext();

            return(View(context.App.ToList()));
        }