Esempio n. 1
0
        public JsonResult UpdateUserLocation(int locationId)
        {
            PopulateSecurityExtended();

            var TANK_usp_upd_SecurityDefaultLocation_spParams = new TANK_usp_upd_SecurityDefaultLocation_spParams()
            {
                UserAn     = SecurityExtended.UserName,
                LocationID = locationId
            };

            _utilityService.ExecStoredProcedureWithoutResults("TANK_usp_upd_SecurityDefaultLocation", TANK_usp_upd_SecurityDefaultLocation_spParams);

            #region  location

            var locationResults = _sharedFunctions.GetLocation(SecurityExtended.UserName);
            if (locationResults != null && locationResults.Any())
            {
                var identity = User.Identity as ClaimsIdentity;
                identity.RemoveClaim(identity.FindFirst("LocationId"));
                identity.AddClaim(new Claim("LocationId", locationResults[0].LocationID.HasValue ? locationResults[0].LocationID.ToString() : null));
                identity.RemoveClaim(identity.FindFirst("LocationName"));
                identity.AddClaim(new Claim("LocationName", locationResults[0].LocationDS));
                identity.RemoveClaim(identity.FindFirst("SecurityProfileId"));
                identity.AddClaim(new Claim("SecurityProfileId", locationResults[0].SecurityProfileID.ToString()));
            }

            #endregion location


            return(Json(1));
        }
Esempio n. 2
0
        public ClaimsIdentity CreateIdentity(DOWTank.Core.Domain.TANK_usp_sel.TANK_usp_sel_Security_spResults userDetails)
        {
            //todo: remove it later
            var identity = new ClaimsIdentity("ApplicationCookie");

            identity.AddClaim(new Claim("UserName", userDetails.UserAN));
            identity.AddClaim(new Claim("DisplayName", userDetails.FullName));

            #region  location

            var locationResults = _sharedFunctions.GetLocation(userDetails.UserAN);
            if (locationResults != null && locationResults.Any())
            {
                identity.AddClaim(new Claim("LocationId", locationResults[0].LocationID.HasValue ? locationResults[0].LocationID.ToString() : null));
                identity.AddClaim(new Claim("LocationName", locationResults[0].LocationDS));
                identity.AddClaim(new Claim("SecurityProfileId", locationResults[0].SecurityProfileID.ToString()));
            }

            #endregion location

            #region SetSecurityGroups

            var securityGroups = GetSecurityGroups(userDetails);

            string roleList = string.Empty;
            if (securityGroups != null && securityGroups.Any())
            {
                roleList = string.Join <string>(",", securityGroups.ToList());
                identity.AddClaim(new Claim("Roles", roleList));
            }

            #endregion SetSecurityGroups

            return(identity);
        }