private async Task EnrichSubjectAttributes(XacmlContextRequest request, string resourceParty) { // If there is no resource party then it is impossible to enrich roles if (string.IsNullOrEmpty(resourceParty)) { return; } XacmlContextAttributes subjectContextAttributes = request.GetSubjectAttributes(); int subjectUserId = 0; int resourcePartyId = Convert.ToInt32(resourceParty); foreach (XacmlAttribute xacmlAttribute in subjectContextAttributes.Attributes) { if (xacmlAttribute.AttributeId.OriginalString.Equals(_userAttributeId)) { subjectUserId = Convert.ToInt32(xacmlAttribute.AttributeValues.First().Value); } } if (subjectUserId == 0) { return; } List <Role> roleList = await GetDecisionPointRolesForUser(subjectUserId, resourcePartyId) ?? new List <Role>(); subjectContextAttributes.Attributes.Add(GetRoleAttribute(roleList)); }
/// <summary> /// Assert that two <see cref="XacmlContextRequest"/> have the same property values. /// </summary> /// <param name="expected">An instance with the expected values.</param> /// <param name="actual">The instance to verify.</param> public static void AssertEqual(XacmlContextRequest expected, XacmlContextRequest actual) { Assert.Equal(expected.Attributes.Count, actual.Attributes.Count); Assert.Equal(expected.GetResourceAttributes().Attributes.Count, actual.GetResourceAttributes().Attributes.Count); Assert.Equal(expected.GetSubjectAttributes().Attributes.Count, actual.GetSubjectAttributes().Attributes.Count); AssertEqual(expected.Attributes, actual.Attributes); }
/// <summary> /// Gets the user id from the XacmlContextRequest subject attribute /// </summary> /// <param name="request">The Xacml Context Request</param> /// <returns>The user id of the subject</returns> public int GetSubjectUserId(XacmlContextRequest request) { XacmlContextAttributes subjectContextAttributes = request.GetSubjectAttributes(); XacmlAttribute subjectAttribute = subjectContextAttributes.Attributes.FirstOrDefault(a => a.AttributeId.OriginalString.Equals(XacmlRequestAttribute.UserAttribute)); return(Convert.ToInt32(subjectAttribute?.AttributeValues.FirstOrDefault()?.Value)); }
/// <summary> /// Updates needed subject information for the Context Request for a specific delegation /// </summary> /// <param name="request">The original Xacml Context Request</param> /// <param name="subjects">The list of PartyIds to be added as subject attributes</param> public void Enrich(XacmlContextRequest request, List <int> subjects) { if (subjects?.Count == 0) { return; } XacmlContextAttributes subjectContextAttributes = request.GetSubjectAttributes(); subjectContextAttributes.Attributes.Add(GetPartyIdsAttribute(subjects)); }
private async Task EnrichSubjectAttributes(XacmlContextRequest request, string resourceParty) { XacmlContextAttributes subjectContextAttributes = request.GetSubjectAttributes(); int subjectUserId = 0; int resourcePartyId = Convert.ToInt32(resourceParty); foreach (XacmlAttribute xacmlAttribute in subjectContextAttributes.Attributes) { if (xacmlAttribute.AttributeId.OriginalString.Equals(_userAttributeId)) { subjectUserId = Convert.ToInt32(xacmlAttribute.AttributeValues.First().Value); } } if (subjectUserId == 0) { return; } List <Role> roleList = await _rolesWrapper.GetDecisionPointRolesForUser(subjectUserId, resourcePartyId) ?? new List <Role>(); subjectContextAttributes.Attributes.Add(GetRoleAttribute(roleList)); }