Exemplo n.º 1
0
        public string AcquireToken(string userLogin, string userPassword, Guid projectGuid)
        {
            var guidCheckResult = GuidUniquenessCheck(projectGuid);

            if (guidCheckResult != null)
            {
                return(guidCheckResult);
            }

            // policies check
            try
            {
                var projectId    = _projectRepository.GetByGuid(projectGuid).Id;
                var policyTuples = _getPoliciesFromProjectFactory.Create().Invoke(projectId).WithTypes(PolicyType.LogIn);

                var user = _userRepository.FindBy(u => u.Login == userLogin).FirstOrDefault();
                if (user != null)
                {
                    var userId = user.Id;
                    var userLastPasswordChange = user.LastPasswordChange;

                    foreach (var policyTuple in policyTuples)
                    {
                        switch (policyTuple.Item1)
                        {
                        case Policy.AccountExpirationDate:
                            var userConfiguration =
                                (UserAccountExpirationDateConfiguration)
                                userConfigurationOrDefaultFromProjectFactory.Create()
                                .Invoke(userId, Policy.AccountExpirationDate, projectId);
                            if (
                                !Check.AccountExpirationDate(
                                    (AccountExpirationDateConfiguration)policyTuple.Item2, userConfiguration))
                            {
                                return new JsonObject
                                       {
                                           Result = JsonValues.AccountExpired
                                       }
                            }
                            .ToJson();
                            break;

                        case Policy.PasswordExpirationDate:
                            if (
                                !Check.PasswordExpirationDate(
                                    (PasswordExpirationDateConfiguration)policyTuple.Item2,
                                    userLastPasswordChange))
                            {
                                return new JsonObject
                                       {
                                           Result = JsonValues.PasswordExpired
                                       }
                            }
Exemplo n.º 2
0
        public string CreateNewUserInProject(UserModel user, Guid projectGuid)
        {
            int projectId;

            try
            {
                projectId = _getAllProjectFactory.Create().Invoke().FirstOrDefault(p => p.ProjectGuid == projectGuid).Id;
            }
            catch (Exception)
            {
                return(new JsonObject
                {
                    Result = JsonValues.Error,
                    ErrorDetails = $"Could not find id of project with guid: {projectGuid}"
                }.ToJson());
            }

            List <Tuple <Policy, PolicyConfiguration> > list;

            try
            {
                list =
                    _getPoliciesFromProjectFactory.Create()
                    .Invoke(projectId)
                    .WithTypes(PolicyType.AccountCreation)
                    .ToList();
            }
            catch (Exception)
            {
                return(new JsonObject
                {
                    Result = JsonValues.Error,
                    ErrorDetails = $"Could not find policies of project with id: {projectId}"
                }.ToJson());
            }

            try
            {
                foreach (var policyTuple in list)
                {
                    switch (policyTuple.Item1)
                    {
                    case Policy.MinimumPasswordLength:
                        if (
                            !Check.MinimumPasswordLength((MinimumPasswordLengthConfiguration)policyTuple.Item2,
                                                         user.Password))
                        {
                            return new JsonObject {
                                       Result = JsonValues.PasswordLengthIncorrect
                            }
                        }
                        .ToJson();
                        break;

                    case Policy.RequiredPasswordCharacters:
                        if (
                            !Check.RequiredPasswordCharacters(
                                (RequiredPasswordCharactersConfiguration)policyTuple.Item2, user.Password))
                        {
                            return new JsonObject {
                                       Result = JsonValues.RequiredCharactersViolation
                            }
                        }