Exemple #1
0
        public async Task <ValidationResult> ValidateEdit(string arId, string policyJson, ClaimsPrincipal currentUser)
        {
            var policyJsonParsed = new DelegationPolicyJsonParser(policyJson);
            var newPolicyIssuer  = policyJsonParsed.PolicyIssuer;
            var newAccessSubject = policyJsonParsed.AccessSubject;

            if (string.IsNullOrEmpty(newPolicyIssuer) || string.IsNullOrEmpty(newAccessSubject))
            {
                return(ValidationResult.Invalid("Policy issuer and access subject are required."));
            }

            var existingEntity = await _delegationService.GetByPolicyId(arId, currentUser.GetPartyId());

            if (existingEntity.PolicyIssuer != newPolicyIssuer || existingEntity.AccessSubject != newAccessSubject)
            {
                return(ValidationResult.Invalid("The combination policyIssuer - accessSubject must remain unmodified."));
            }

            return(ValidationResult.Valid());
        }
Exemple #2
0
        public async Task <ValidationResult> ValidateCreate(string policyJson, ClaimsPrincipal currentUser)
        {
            var policyJsonParsed = new DelegationPolicyJsonParser(policyJson);
            var newPolicyIssuer  = policyJsonParsed.PolicyIssuer;
            var newAccessSubject = policyJsonParsed.AccessSubject;

            var validationResult = ValidateIssuer(currentUser.GetPartyId(), newPolicyIssuer, newAccessSubject);

            if (!validationResult.Success)
            {
                return(validationResult);
            }

            if (await _delegationService.DelegationExists(newPolicyIssuer, newAccessSubject))
            {
                return(ValidationResult.Invalid("The combination policyIssuer - accessSubject already exists."));
            }

            return(ValidationResult.Valid());
        }
Exemple #3
0
        public void PolicyIssuer_ForPolicyIssuerMissing_ReturnsNull()
        {
            //Arrange
            var policyString = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000001""
                    }     
                }
            }";

            //Act
            var policyJson = new DelegationPolicyJsonParser(policyString);

            //Assert
            policyJson.PolicyIssuer.ShouldBe(null);
        }
Exemple #4
0
        public void AccessSubject_ForAccessSubjectMissing_ReturnsNull()
        {
            //Arrange
            var policyString = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972715"",
                    ""target"":
                    {
            
                    }     
                }
            }";

            //Act
            var policyJson = new DelegationPolicyJsonParser(policyString);

            //Assert
            policyJson.AccessSubject.ShouldBe(null);
        }
Exemple #5
0
        public void PolicyIssuer_WithValidPolicyIssuer_ReturnsPolicyIssuer()
        {
            //Arrange
            var policyString = @"
            {
                ""delegationEvidence"":
                {
                    ""notBefore"": 1509633681,
                    ""notOnOrAfter"": 1509633741,
                    ""policyIssuer"": ""EU.EORI.NL812972715"",
                    ""target"":
                    {
                        ""accessSubject"": ""EU.EORI.NL000000001""
                    }
                }
            }";

            //Act
            var policyJson   = new DelegationPolicyJsonParser(policyString);
            var policyIssuer = policyJson.PolicyIssuer;

            //Assert
            policyIssuer.ShouldBe("EU.EORI.NL812972715");
        }