Example #1
0
 public SessionManager(string secretKey)
 {
     _signatureService = new SignatureService(secretKey);
     _userService      = new UserService();
     _jwtService       = new JWTService();
     _userClaimService = new UserClaimsService();
 }
Example #2
0
 public SessionManager()
 {
     _signatureService = new SignatureService(Environment.GetEnvironmentVariable("AppLaunchSecretKey", EnvironmentVariableTarget.Machine));
     _userService      = new UserService();
     _jwtService       = new JWTService();
     _userClaimService = new UserClaimsService();
 }
        public void And_Claim_Not_Found_Then_Returns_False(
            string employerAccountId,
            UserClaimsService userClaimsService)
        {
            var claims = new List <Claim>();

            userClaimsService.UserIsInRole(employerAccountId, EmployerUserRole.Owner, claims)
            .Should().BeFalse();
        }
        public void And_User_Is_In_Role_Then_Returns_True(
            string employerAccountId,
            UserClaimsService userClaimsService)
        {
            var claims = BuildClaims(employerAccountId, EmployerUserRole.Owner);

            userClaimsService.UserIsInRole(employerAccountId, EmployerUserRole.Owner, claims)
            .Should().BeTrue();
        }
Example #5
0
        public override async Task SetUserClaims(string email, UserRolesEnum userRole, string propCode, string unitNumber)
        {
            await Task.CompletedTask;

            if (!_claims.ContainsKey(email))
            {
                throw new Exception("User not logged in");
            }
            _claims[email] = new UserClaimsService(email, userRole, propCode, unitNumber);
        }
        public void And_User_Not_Found_Then_Returns_False(
            string employerAccountId,
            string differentAccountId,
            UserClaimsService userClaimsService)
        {
            var claims = BuildClaims(differentAccountId, EmployerUserRole.Owner);

            userClaimsService.UserIsInRole(employerAccountId, EmployerUserRole.Owner, claims)
            .Should().BeFalse();
        }
        public override async Task <UserClaimsService> GetUserClaims(string emailLogin)
        {
            if (string.IsNullOrEmpty(emailLogin))
            {
                //throw new NullReferenceException(nameof(emailClaim));
                IntLoggedUser = new UserClaimsService("",
                                                      UserRolesEnum.Anonymous,
                                                      "",
                                                      "");
                return(IntLoggedUser);
            }

            var user = await _userManager.FindByEmailAsync(emailLogin);

            var claims = await _userManager.GetClaimsAsync(user);

            var roles = await _userManager.GetRolesAsync(user);

            if (!(roles.Any() && Enum.TryParse(roles.FirstOrDefault(), out UserRolesEnum userRole)))
            {
                throw new Exception();
            }

            UserClaimsService loggedUser = new UserClaimsService(user.Email,
                                                                 userRole,
                                                                 "",
                                                                 "");


            switch (userRole)
            {
            case UserRolesEnum.Anonymous:
                break;

            case UserRolesEnum.Tenant:
                loggedUser = new UserClaimsService(user.Email,
                                                   userRole,
                                                   claims.FirstOrDefault(x => x.Type == SecurityClaims.PropertyCode.ToString())?.Value,
                                                   claims.FirstOrDefault(x => x.Type == SecurityClaims.UnitNumber.ToString())?.Value);

                break;

            case UserRolesEnum.Superintendent:
                loggedUser = new UserClaimsService(user.Email,
                                                   userRole,
                                                   claims.FirstOrDefault(x => x.Type == SecurityClaims.PropertyCode.ToString())?.Value,
                                                   "");

                break;

            case UserRolesEnum.Administrator:
                break;

            case UserRolesEnum.Worker:

                break;
            }

            IntLoggedUser = loggedUser;
            return(loggedUser);
        }
        public override async Task <UserClaimsService> GetUserClaims(string emailLogin)
        {
            await Task.CompletedTask;


            if (string.IsNullOrEmpty(emailLogin))
            {
                //throw new NullReferenceException(nameof(emailClaim));
                IntLoggedUser = new UserClaimsService("",
                                                      UserRolesEnum.Anonymous,
                                                      "",
                                                      "");
                return(IntLoggedUser);
            }

            var           userRoleClaim = _claims.FirstOrDefault(x => x.Type == "extension_userrole");
            UserRolesEnum userRole      = UserRolesEnum.Anonymous;

            if (userRoleClaim != null)
            {
                Enum.TryParse(userRoleClaim.Value, out userRole);
            }


            IntLoggedUser = new UserClaimsService(emailLogin,
                                                  userRole,
                                                  "",
                                                  "");

            switch (userRole)
            {
            case UserRolesEnum.Anonymous:
                break;

            case UserRolesEnum.Tenant:
                IntLoggedUser = new UserClaimsService(emailLogin,
                                                      userRole,
                                                      _claims.FirstOrDefault(x => x.Type == "extension_PropertyCode")?.Value,
                                                      _claims.FirstOrDefault(x => x.Type == "extension_UnitNumber")?.Value);

                break;

            case UserRolesEnum.Superintendent:
                IntLoggedUser = new UserClaimsService(emailLogin,
                                                      userRole,
                                                      _claims.FirstOrDefault(x => x.Type == "extension_PropertyCode")?.Value,
                                                      "");

                break;

            case UserRolesEnum.Administrator:
                break;

            case UserRolesEnum.Worker:

                break;
            }



            return(IntLoggedUser);
        }