Exemplo n.º 1
0
        private ValidationResponse CheckAccessTokenMatch(AccessToken accessToken, AccessEnity accessEntity)
        {
            if (string.IsNullOrEmpty(accessToken.Organisation))
            {
                return(GetValidationResult(false, "The organisation name is empty.",
                                           StatusDictionary.PROPERTY_EMPTY));
            }

            string decryptedTokenOrganisation = SymmetricEncryption.Decrypt(accessToken.Organisation);
            //string decryptedEntityOrganisation = SymmetricEncryption.Decrypt(accessEntity.Organisation);
            bool   propertyMatchFailed = false;
            string propertyName        = string.Empty;

            if (decryptedTokenOrganisation != accessEntity.Organisation)             // decryptedEntityOrganisation
            {
                propertyMatchFailed = true;
                propertyName        = "Organisation";
            }

            if (!Enumerable.SequenceEqual(accessToken.Scope, accessEntity.Scope))
            {
                propertyMatchFailed = true;
                propertyName        = "Scope";
            }

            if (!CompareDates(accessToken.StartTime, accessEntity.StartTime))
            {
                propertyMatchFailed = true;
                propertyName        = "StartTime";
            }

            if (!CompareDates(accessToken.EndTime, accessEntity.EndTime))
            {
                propertyMatchFailed = true;
                propertyName        = "EndTime";
            }

            bool   validationSuccessful = true;
            string message = "Validation was successful.";
            int    status  = StatusDictionary.SUCCESS;

            if (propertyMatchFailed)
            {
                validationSuccessful = false;
                message = string.Format("The property: {0} from Access-Token and DB Access do not match.", propertyName);
                status  = StatusDictionary.TOKEN_VALUE_DOES_NOT_MATCH;
            }
            ValidationResponse response = GetValidationResult(validationSuccessful, message, status);

            return(response);
        }
Exemplo n.º 2
0
        public ValidationResponse AccessTokenValidation(string encryptedToken)
        {
            AccessToken accessToken = null;

            try
            {
                accessToken = GetAccessToken(encryptedToken);
            }
            catch (ValidationException exception)
            {
                return(GetValidationResult(false, exception.Message,
                                           exception.Status));
            }

            DateTime currentTime = DateTime.Now;

            if (currentTime > accessToken.EndTime)
            {
                return(GetValidationResult(false, "Access-Token passed expiry date.",
                                           StatusDictionary.ACCESS_TOKEN_EXPIRED));
            }

            if (string.IsNullOrEmpty(accessToken.Token))
            {
                return(GetValidationResult(false, "Token value from Access-Token is empty.",
                                           StatusDictionary.ACCESS_TOKEN_EMPTY));
            }

            AccessEnity access = GetAccessEntity(accessToken.Token);

            if (access == null)
            {
                return(GetValidationResult(false, "Could not find key matching token in the database.",
                                           StatusDictionary.TOKEN_NOT_FOUND));
            }
            ValidationResponse response = CheckAccessTokenMatch(accessToken, access);

            return(response);
        }