/// <summary> /// Creates the user information dto. /// </summary> /// <returns>A <see cref="UserInformationDto"/></returns> public UserInformationDto CreateUserInformationDto() { var claimsPrincipal = _currentClaimsPrincipalService.GetCurrentPrincipal(); var permissions = claimsPrincipal.CurrentPermissions(); var accountKey = claimsPrincipal.CurrentAccountKey(); var staffKey = claimsPrincipal.CurrentStaffKey(); UserInformationDto userInformationDto = null; var session = _sessionProvider.GetSession(); var account = session.Get <SystemAccount> (accountKey); var staff = account.StaffMembers.First(x => x.Key == staffKey); var agency = staff.Agency; var location = staff.PrimaryLocation; userInformationDto = new UserInformationDto { AccountKey = account.Key, AccountIdentifier = account.Identifier, AgencyKey = agency.Key, AgencyDisplayName = agency.AgencyProfile.AgencyName.DisplayName, LocationKey = location == null ? 0 : location.Key, LocationDisplayName = location == null ? string.Empty : location.LocationProfile.LocationName.DisplayName, StaffKey = staff.Key, StaffFirstName = staff.StaffProfile.StaffName.First, StaffMiddleName = staff.StaffProfile.StaffName.Middle, StaffLastName = staff.StaffProfile.StaffName.Last, DirectEmailAddress = staff.DirectAddressCredential == null ? null : (staff.DirectAddressCredential.DirectAddress == null? null : staff.DirectAddressCredential.DirectAddress.Address), GrantedPermissions = permissions }; return(userInformationDto); }
/// <summary> /// Login to a session as given staff. /// </summary> /// <param name="staff">The staff.</param> public void LoginAs(Staff staff) { Check.IsNotNull(staff, "Staff is required."); var claimsPrincipal = _currentClaimsPrincipalService.GetCurrentPrincipal(); _permissionClaimsManager.IssueSystemPermissionClaimsForStaff(claimsPrincipal, staff); _permissionClaimsManager.IssueStaffKeyClaims(claimsPrincipal, staff); }
/// <summary> /// Determines whether the current user has the specified <see cref="Permission" />. /// </summary> /// <param name="permission">The permission.</param> /// <returns> /// <c>true</c> if the user has been granted the specified <see cref="ProCenter.Mvc.Infrastructure.Permission" />; /// otherwise, <c>false</c>. /// </returns> public bool DoesUserHavePermission(Permission permission) { var claimsPrincipal = _currentClaimsPrincipalService.GetCurrentPrincipal(); var claimsIdentity = (ClaimsIdentity)claimsPrincipal.Identity; var hasClaim = claimsIdentity.Claims.Any( c => c.Type == ProCenterClaimType.PermissionClaimType && c.Value == permission.Name); return(hasClaim); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(ExerciseEmergencyAccessRequest request) { var principal = _currentClaimsPrincipalService.GetCurrentPrincipal(); var systemAccount = _accountRepository.GetByKey(principal.CurrentAccountKey()); _permissionClaimsManager.ExerciseEmergencyAccess(principal, systemAccount); var response = CreateTypedResponse(); response.UserInformationDto = _userInformationDtoFactory.CreateUserInformationDto(); return(response); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(RollbackEmergencyAccessRequest request) { var principal = _currentClaimsPrincipalService.GetCurrentPrincipal(); var staff = _staffRepository.GetByKey(principal.CurrentStaffKey()); _permissionClaimsManager.RollbackEmergencyAccess(principal, staff); var response = CreateTypedResponse(); response.UserInformationDto = _userInformationDtoFactory.CreateUserInformationDto(); return(response); }
public void ProcessRequest(HttpContext context) { // var identity = _currentClaimsPrincipalService.GetCurrentPrincipal ().Identity; var identity = _currentClaimsPrincipalService.GetCurrentPrincipal().Identity as IClaimsIdentity; var nameIdentifier = identity.Claims.First(c => c.ClaimType == ClaimTypes.NameIdentifier).Value; // check this for security reason if (identity.IsAuthenticated) { var staffKeyString = context.Request["staffKey"]; var staffKey = string.IsNullOrEmpty(staffKeyString) ? 0 : long.Parse(staffKeyString); var account = _accountRepository.GetByIdentifier(nameIdentifier); // check this for security reason if (account.StaffMembers.Any(x => x.Key == staffKey)) { var staff = _staffRepository.GetByKey(staffKey); _signOnService.LoginAs(staff); context.Response.Redirect("~/Client.aspx"); } } }