Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeReferenceEnricher fills attributes with unexisting subattribute "id", instead of "value"? #51

Closed
sviatoslav-vilkovych opened this issue Oct 2, 2020 · 4 comments
Labels
bug Something isn't working
Projects

Comments

@sviatoslav-vilkovych
Copy link

Hello,
Please look at the next code:

					refLst.Add(new SCIMRepresentationAttribute
					{
						SchemaAttribute = new SCIMSchemaAttribute("id")
						{
							Name = "id",
							MultiValued = false,
							Type = SCIMSchemaAttributeTypes.STRING
						},
						ValuesString = new List<string>
						{
							filteredRepresentation.Id
						}
					});

I noticed that this code inserts "id", while in your SCIMConstants.cs class description of complex attributes both Group and User contains "value":
c.AddStringAttribute("value");

As a result, when getting users you will receive SCIMRepresentation with "value", but when the user returned after the update or create, it will "id" in its complex attributes. Same for groups. Is this intended or an issue?

Thanks!

@simpleidserver
Copy link
Owner

Hi,

The "id" attribute is mandatory and must be present in all SCIM representations for example : Users or Groups.
The class "AttributeReferenceEnricher" is used to add mandatory fields like "id", "display" or "$ref" into SCIM representations.
Those mandatory attributes are "normally" not inserted into sub complex attributes like "user\emails".

When a user is added :


POST http://localhost:60002/Users HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:60002
Content-Length: 416

{
 "schemas": [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:ietf:params:scim:schemas:extension:eid:2.0:User"],
 "userName": "loki3",
 "externalId": "externalId2",
 "name": { "formatted" : "formatted", "familyName": "familyName", "givenName": "givenName" },
"phoneNumbers": [ { "type": "mobile", "value": "01" }, { "type": "home", "value": "02" } ],
"validity": "22",
"birthDate": "25-09-20 13:35:33"
}

The following result is received :

HTTP/1.1 201 Created
Date: Sun, 04 Oct 2020 16:53:21 GMT
Content-Type: application/scim+json
Server: Kestrel
Content-Length: 850
ETag: 76840920-7b48-4393-aaea-18b4678cc3bb
Location: http://localhost:60002/Users/53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70

{
  "id": "53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70",
  "schemas": [
    "urn:ietf:params:scim:schemas:core:2.0:User",
    "urn:ietf:params:scim:schemas:extension:eid:2.0:User"
  ],
  "meta": {
    "resourceType": "Users",
    "created": "2020-10-04T16:53:21.2108435Z",
    "lastModified": "2020-10-04T16:53:21.2108436Z",
    "version": "76840920-7b48-4393-aaea-18b4678cc3bb",
    "location": "http://localhost:60002/Users/53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70"
  },
  "externalId": "externalId2",
  "userName": "loki3",
  "name": {
    "formatted": "formatted",
    "familyName": "familyName",
    "givenName": "givenName"
  },
  "phoneNumbers": [
    {
      "type": "mobile",
      "value": "01"
    },
    {
      "type": "home",
      "value": "02"
    }
  ],
  "validity": 22.0,
  "birthDate": "2020-09-25T13:35:33"
}

When the new user is fetched :

GET http://localhost:60002/Users/53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json

The following result is returned :

HTTP/1.1 200 OK
Date: Sun, 04 Oct 2020 16:53:55 GMT
Content-Type: application/scim+json
Server: Kestrel
Content-Length: 849
ETag: 76840920-7b48-4393-aaea-18b4678cc3bb
Location: http://localhost:60002/Users/53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70

{
  "id": "53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70",
  "schemas": [
    "urn:ietf:params:scim:schemas:core:2.0:User",
    "urn:ietf:params:scim:schemas:extension:eid:2.0:User"
  ],
  "meta": {
    "resourceType": "Users",
    "created": "2020-10-04T16:53:21.2108435",
    "lastModified": "2020-10-04T16:53:21.2108436",
    "version": "76840920-7b48-4393-aaea-18b4678cc3bb",
    "location": "http://localhost:60002/Users/53d7ef94-99b9-4f6b-93f2-f1ff3fb9dc70"
  },
  "externalId": "externalId2",
  "userName": "loki3",
  "birthDate": "2020-09-25T13:35:33",
  "phoneNumbers": [
    {
      "type": "home",
      "value": "02"
    },
    {
      "value": "01",
      "type": "mobile"
    }
  ],
  "name": {
    "givenName": "givenName",
    "formatted": "formatted",
    "familyName": "familyName"
  },
  "validity": 22.00
}

The "id" is not inserted into sub complex attributes (user\phoneNumbers).
I couldn't reproduce the error.

@sviatoslav-vilkovych
Copy link
Author

sviatoslav-vilkovych commented Oct 4, 2020

I don't know about the user\phoneNumbers, but I know that for user\groups I am getting "id" instead of "value", while I am setting "value".

    private IEnumerable<SCIMRepresentationAttribute> FillComplexGroupsAttribute(SCIMSchemaAttribute groupsAttribute, IEnumerable<ScimGroup> scimGroups)
    {
        var valueSubAttributeOfGroups = groupsAttribute.SubAttributes.Single(attr => attr.Name == ValueAttributeName);
        var refSubAttributeOfGroups = groupsAttribute.SubAttributes.Single(attr => attr.Name == RefAttributeName);
        var displaySubAttributeOfGroups = groupsAttribute.SubAttributes.Single(attr => attr.Name == DisplayAttributeName);

        var groupsScimAttributes = new List<SCIMRepresentationAttribute>();
        foreach (var group in scimGroups)
        {
            groupsScimAttributes.Add(new SCIMRepresentationAttribute(groupsAttribute.Id, groupsAttribute)
            {
                Values = new List<SCIMRepresentationAttribute>()
                {
                    new SCIMRepresentationAttribute(valueSubAttributeOfGroups.Id,
                                                    valueSubAttributeOfGroups,
                                                    valuesString: new List<string> { group.ObjectGuid }),
                    new SCIMRepresentationAttribute(displaySubAttributeOfGroups.Id,
                                                    displaySubAttributeOfGroups,
                                                    valuesString: new List<string> { group.DisplayName }),
                    new SCIMRepresentationAttribute(refSubAttributeOfGroups.Id,
                                                    refSubAttributeOfGroups,
                                                    valuesString: new List<string> { $"{Url}/{SCIMEndpoints.Group}/{group.ObjectGuid}" }),
                },
            });
        }

        return groupsScimAttributes;
    }

Imagine having IEnumerable<SCIMRepresentation> of users with groups filled with something like this. Then, during obtaining concrete user you will get a model with "id" because it goes through your Enricher model and won't have a "value" attribute, while the model that will be returned after changing the user will return the model with "value" because it goes through CommandHandler and I am setting all the fields.
And it wouldn't be a problem, but I can't do something like this:

var valueSubAttributeOfGroups = groupsAttribute.SubAttributes.Single(attr => attr.Name == "id");

Groups attribute does not have an "id" subattribute.

@simpleidserver
Copy link
Owner

Indeed it seems to be an issue. We will take a closer look and fix this issue.
Thank you for you feedback !

@simpleidserver simpleidserver added this to InProgress in 1.1.8 Oct 5, 2020
@simpleidserver simpleidserver added the bug Something isn't working label Oct 5, 2020
thabart added a commit that referenced this issue Oct 6, 2020
@simpleidserver
Copy link
Owner

The issue is fixed : e7c5f61

@simpleidserver simpleidserver moved this from InProgress to Done in 1.1.8 Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
1.1.8
Done
Development

No branches or pull requests

2 participants