/// <summary> /// Add a new user /// </summary> /// <param name="FirstName"></param> /// <param name="LastName"></param> /// <param name="VunetId"></param> /// <param name="RoleName"></param> /// <returns></returns> public JsonResult AddNewUser(string FirstName, string LastName, string VunetId, string RoleName) { string response = string.Empty; ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); UserDTO dto = new UserDTO() { ApplicationName = applicationName, CreatedBy = User.Identity.Name, CreatedOn = DateTime.Now, FirstName = FirstName, LastName = LastName, IsActive = true, Show = true, VunetId = VunetId }; using (securityClient) { response = securityClient.AddUserToApplication(dto); if (response.Contains("Success")) { response += Environment.NewLine + securityClient.AddUserToAppRole(VunetId, applicationName, RoleName); } } return(Json(response, JsonRequestBehavior.AllowGet)); }
public IEnumerable <SelectListItem> GetRoles() { List <SelectListItem> roles = new List <SelectListItem>(); ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); using (securityClient) { var rolesList = securityClient.GetAllRolesInApp("DTM").ToList(); foreach (var role in rolesList) { SelectListItem item = new SelectListItem() { Text = role, Value = role }; roles.Add(item); //model.Roles.Add(item); } //model.Roles = roles; } return(roles); }
//protected void Application_AuthenticateRequest(object sender, EventArgs e) //{ // if (HttpContext.Current.Request.IsAuthenticated) // { // List<string> roles = new List<string>(); // var identity = HttpContext.Current.User.Identity; // //set up domain context // PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "Vanderbilt"); // //find the user // UserPrincipal user = UserPrincipal.FindByIdentity(ctx, identity.Name); // //find the AD groups // GroupPrincipal adminGroup = GroupPrincipal.FindByIdentity(ctx, "DTM Admin Access"); // GroupPrincipal userGroup = GroupPrincipal.FindByIdentity(ctx, "DTM User Access"); // GroupPrincipal devGroup = GroupPrincipal.FindByIdentity(ctx, "TVPG Members"); // if (user != null) // { // //check if user is a member of AD group // if (user.IsMemberOf(adminGroup)) // { // roles.Add("admin"); // } // else if (user.IsMemberOf(userGroup)) // { // roles.Add("user"); // } // else if (user.IsMemberOf(devGroup)) // { // roles.Add("dev"); // } // } // HttpContext.Current.User = new GenericPrincipal(identity, roles.ToArray()); // } //} protected void Application_AuthenticateRequest(object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.AuthenticationType == "Forms" && HttpContext.Current.Request.IsAuthenticated) { var identity = HttpContext.Current.User.Identity; PrincipalContext context = new PrincipalContext(ContextType.Domain); UserPrincipal user = UserPrincipal.FindByIdentity(context, identity.Name); #region ApplicaionSecurityService Call ////Call the ApplicationSecurity Service for roles ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); string[] userRoles; using (securityClient) { try { userRoles = securityClient.GetUserRolesInApp("DTM", identity.Name); HttpContext.Current.User = new GenericPrincipal(identity, userRoles); } catch (Exception ex) { throw ex; } } #endregion } } }
/// <summary> /// Populates the AppUserRoleModel /// </summary> /// <returns></returns> private List <AppUserRoleModel> GetAllUsers() { List <AppUserRoleModel> models = new List <AppUserRoleModel>(); ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); List <AppUserRoleDTO> dto = new List <AppUserRoleDTO>(); using (securityClient) { dto = securityClient.GetAppUserWithRoles(applicationName).ToList(); models = ConvertToModel(dto); } return(models.OrderBy(x => x.FirstName).ThenBy(x => x.LastName).ToList()); }
/// <summary> /// Add a new role /// </summary> /// <param name="RoleName"></param> /// <param name="Description"></param> /// <returns></returns> public JsonResult AddNewRole(string RoleName, string Description) { string response = string.Empty; ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); RolesDTO dto = new RolesDTO() { ApplicationName = applicationName, RoleName = RoleName, RoleDescription = Description, CreatedBy = User.Identity.Name, CreatedOn = DateTime.Now, IsActive = true, Show = true }; using (securityClient) { response = securityClient.AddRoleToApplication(dto); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult LoginPage(FormCollection collection) { try { ActiveDirectoryClient client = new ActiveDirectoryClient(); string vunetId = collection["Username"]; string ePass = collection["Password"]; string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name; bool isValidUser = client.ValidateVUnetIDePassword(vunetId, ePass); if (isValidUser) { ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); List <UserDTO> users = new List <UserDTO>(); using (securityClient) { users = securityClient.GetAllUsersInApplication("DTM").ToList(); if (!string.IsNullOrEmpty(users.Where(x => x.IsActive == true && x.VunetId == vunetId).Select(x => x.VunetId).FirstOrDefault())) { System.Web.Security.FormsAuthentication.SetAuthCookie(vunetId, true); HttpContext.Session.Timeout = 90; return(RedirectToAction("ShowExistingRequests", "ExistingRequests")); } else { return(View("Unauthorized")); } } } else { return(View("Unauthorized")); } } catch (Exception) { return(RedirectToAction("ErrorLanding", "Login")); } }
public ActionResult ConfirmEditUser(AppUserRoleModel model) { ApplicationSecurityClient securityClient = new ApplicationSecurityClient(); AppUserRoleDTO dto = new AppUserRoleDTO() { ApplicationName = model.ApplicationName, FirstName = model.FirstName, LastName = model.LastName, IsUserActive = model.IsUserActive, RoleName = model.RoleName, ShowUser = true, VunetId = model.VunetId, UpdatedBy = User.Identity.Name, UpdatedOn = DateTime.Now }; using (securityClient) { securityClient.UpdateAppUserRole(dto); } return(RedirectToAction("DTMUsers")); }