public ActiveDirectoryService(GNEntityModelContainer db, IdentityModelContainer identityDB)
        {
            base.db = db;

            this.aspNetRoleService      = new AspNetRoleService(identityDB);
            this.aspNetUserRolesService = new AspNetUserRoleService(identityDB);
        }
Exemplo n.º 2
0
        public TeamService(GNEntityModelContainer db, IdentityModelContainer identityDB)
        {
            base.db = db;

            this.aspNetRoleService     = new AspNetRoleService(identityDB);
            this.aspNetUserRoleService = new AspNetUserRoleService(identityDB);
        }
 public CloudFileService(GNEntityModelContainer db, IdentityModelContainer identityDB)
     : base(db)
 {
     base.db = db;
     this.aspNetRoleService  = new AspNetRoleService(identityDB);
     this.transactionService = new TransactionService(db);
 }
Exemplo n.º 4
0
 public ProjectService(GNEntityModelContainer db, IdentityModelContainer identityDB)
     : base(db)
 {
     base.db = db;
     this.aspNetRoleService = new AspNetRoleService(identityDB);
     this.teamService       = new TeamService(db, identityDB);
 }
 public SampleService(GNEntityModelContainer db, IdentityModelContainer identityDB)
     : base(db)
 {
     base.db = db;
     this.aspNetRoleService = new AspNetRoleService(identityDB);
     this.teamService       = new TeamService(db, identityDB);
     this.cloudFileService  = new CloudFileService(db, identityDB);
 }
Exemplo n.º 6
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context and user manager to use a single instance per request
            app.CreatePerOwinContext(GNIdentityDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);

            // JLS: Ensure that, by default, the system will authenticate requests with our configured CookieAuthentication.
            app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ApplicationCookie);


            //JLS: ***********************************************

            app.UseWsFederationAuthentication(
                new WsFederationAuthenticationOptions
            {
                AuthenticationType = "Sanford",
                Wtrealm            = ConfigurationManager.AppSettings["Sanford:Wtrealm"],
                MetadataAddress    = ConfigurationManager.AppSettings["Sanford:Metadata"],
                Notifications      = new WsFederationAuthenticationNotifications
                {
                    AuthenticationFailed = context =>
                    {
                        context.HandleResponse();
                        //JLS: ToDo: Replace this target of this redirect with the appropriate URL for the GenomeNext application.
                        context.Response.Redirect("Home/Error?message=" + context.Exception.Message);
                        return(Task.FromResult(-1));
                    },
                    //SecurityTokenReceived
                    SecurityTokenValidated = context =>
                    {
                        var userEmail = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Email).Value;

                        var identityDB = new IdentityModelContainer();
                        var db         = new GNEntityModelContainer();
                        GNContact contact;

                        AspNetUser user = identityDB.AspNetUsers.Where(a => a.Email.ToLower().Equals(userEmail.ToLower())).FirstOrDefault();
                        if (user != null)
                        {
                            //exists
                            contact = db.GNContacts.Where(a => a.User.Id.Equals(user.Id) && a.IsInviteAccepted == true).FirstOrDefault();
                        }
                        else
                        {
                            //create new
                            String ssoEmail             = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Email).Value;
                            GNOrganization organization = db.GNOrganizations.Where(a => a.Name.Contains("Sanford")).FirstOrDefault();
                            AspNetUser newUser          = new AspNetUser
                            {
                                Id             = Guid.NewGuid().ToString(),
                                Email          = ssoEmail,
                                IsAdmin        = false,
                                Password       = "******",
                                UserName       = ssoEmail,
                                EmailConfirmed = true
                            };
                            identityDB.AspNetUsers.Add(newUser);

                            contact = new GNContact
                            {
                                Id             = Guid.NewGuid(),
                                AspNetUserId   = newUser.Id,
                                CreateDateTime = DateTime.Now,
                                Email          = ssoEmail,
                                FirstName      = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.GivenName).Value
                            };

                            db.GNContacts.Add(contact);
                            identityDB.SaveChanges();
                            db.SaveChanges();
                        }


                        var applicationUserIdentity = new ClaimsIdentity();
                        applicationUserIdentity.AddClaim(new Claim(ClaimTypes.Name, contact.FullName, ""));
                        applicationUserIdentity.AddClaim(new Claim(ClaimTypes.Email, user.Email, ""));
                        context.OwinContext.Authentication.User.AddIdentity(applicationUserIdentity);

                        context.Response.Redirect("Home");
                        return(Task.FromResult(0));
                    }
                }
            }
                );
            //JLS: ***********************************************


            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                ExpireTimeSpan     = TimeSpan.FromMinutes(30),
                Provider           = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
        }
 public IdentityEntityService(IdentityModelContainer db)
     : base(db)
 {
     base.db = db;
 }
        private void GetContactForUser(ActionExecutingContext filterContext)
        {
            try
            {
                if (filterContext != null && filterContext.Controller != null &&
                    filterContext.Controller.GetType().GetProperties().Count(p => p.Name == "identityDB") != 0 &&
                    filterContext.Controller.GetType().GetProperties().Count(p => p.Name == "db") != 0)
                {
                    IdentityModelContainer identityDB = (IdentityModelContainer)filterContext.Controller.GetType().GetProperty("identityDB").GetValue(filterContext.Controller);
                    GNEntityModelContainer db         = (GNEntityModelContainer)filterContext.Controller.GetType().GetProperty("db").GetValue(filterContext.Controller);

                    var       requestUser = filterContext.HttpContext.User;
                    GNContact contact     = null;

                    if (requestUser != null && requestUser.Identity != null && requestUser.Identity.IsAuthenticated)
                    {
                        var user = identityDB.AspNetUsers.Where(u => u.UserName == requestUser.Identity.Name).FirstOrDefault();

                        if (user != null)
                        {
                            Guid defaultOrganizationIdGuid = Guid.Empty;
                            if (!string.IsNullOrEmpty(user.DefaultOrganizationId))
                            {
                                defaultOrganizationIdGuid = Guid.Parse(user.DefaultOrganizationId);

                                contact = db.GNContacts
                                          .Where(c => (c.AspNetUserId == user.Id && c.GNOrganizationId == defaultOrganizationIdGuid))
                                          .FirstOrDefault();
                            }
                            else
                            {
                                contact = db.GNContacts
                                          .Where(c => (c.AspNetUserId == user.Id))
                                          .FirstOrDefault();

                                if (contact != null)
                                {
                                    user.DefaultOrganizationId   = contact.GNOrganizationId.ToString();
                                    identityDB.Entry(user).State = System.Data.Entity.EntityState.Modified;
                                    user.Password        = "******";
                                    user.PasswordConfirm = ".";
                                    identityDB.SaveChanges();
                                }
                            }

                            if (contact != null && user != null)
                            {
                                contact.User = user;
                            }

                            if (contact != null && contact.GNContactRoles != null)
                            {
                                foreach (var contactRole in contact.GNContactRoles)
                                {
                                    contactRole.AspNetRole = identityDB.AspNetRoles.Find(contactRole.AspNetRoleId);
                                }
                            }
                        }
                    }

                    if (contact != null)
                    {
                        //set contact
                        filterContext.Controller.ViewBag.ContactForUser = contact;

                        //set organizations for user contact
                        filterContext.Controller.ViewBag.OrganizationsForUser =
                            db.GNContacts
                            .Where(c => c.AspNetUserId == contact.AspNetUserId)
                            .Select(c => c.GNOrganization)
                            .Where(o => o.Id != contact.GNOrganizationId)
                            .ToList();

                        //get org settings template for user
                        var orgConfigSettingsTemplate =
                            db.GNSettingsTemplates
                            .Include(t => t.GNSettingsTemplateConfigs)
                            .Where(t => t.GNOrganizations.Any(o => o.Id == contact.GNOrganizationId))
                            .FirstOrDefault();

                        if (orgConfigSettingsTemplate != null &&
                            orgConfigSettingsTemplate.GNSettingsTemplateConfigs != null &&
                            orgConfigSettingsTemplate.GNSettingsTemplateConfigs.Count != 0)
                        {
                            filterContext.Controller.ViewBag.OrgConfigSettings =
                                orgConfigSettingsTemplate.GNSettingsTemplateConfigs.ToList();
                        }
                    }
                    else
                    {
                        filterContext.Controller.ViewBag.ContactForUser = null;
                    }
                }
            }
            catch (Exception e)
            {
                LogUtil.Error(logger, "Unable to Get Contact User!!", e);
            }
        }
 public AspNetUserService(IdentityModelContainer db)
     : base(db)
 {
     base.db = db;
 }