public static ScimAttributeSchema ToScimAttributeSchema(this IScimTypeAttributeDefinition definition) { var subAttributes = new List <ScimAttributeSchema>(); var definitionType = definition.GetType(); Type[] genericTypeArguments; if (definitionType.IsGenericType && definitionType.GetGenericTypeDefinition() == typeof(ScimTypeComplexAttributeDefinitionBuilder <,>) && (genericTypeArguments = definitionType.GetGenericArguments())[0] != genericTypeArguments[1]) // circular reference check e.g <ScimAttributeSchema, ScimAttributeSchema> { foreach (var subAttDefinition in definition.DeclaringTypeDefinition.AttributeDefinitions.Values) { subAttributes.Add(subAttDefinition.ToScimAttributeSchema()); } } return(new ScimAttributeSchema( definition.Name, GetScimDataType(definition.AttributeDescriptor), definition.Description, definition.MultiValued, definition.Mutability.ToString().LowercaseFirstCharacter(), definition.Required, definition.Returned.ToString().LowercaseFirstCharacter(), definition.Uniqueness.ToString().LowercaseFirstCharacter(), definition.CaseExact, subAttributes, definition.CanonicalValues, definition.ReferenceTypes)); }
public StatefulAttributeCanonicalizationRule( PropertyDescriptor propertyDescriptor, IScimTypeAttributeDefinition definition, StatefulAttributeCanonicalizationFunc <TAttribute> canonicalizationRule) { _PropertyDescriptor = propertyDescriptor; _Definition = definition; _CanonicalizationRule = canonicalizationRule; }
public AttributeCanonicalizationRule( PropertyDescriptor propertyDescriptor, IScimTypeAttributeDefinition definition, AttributeCanonicalizationAction <TAttribute> canonicalizationRule) { _PropertyDescriptor = propertyDescriptor; _Definition = definition; _CanonicalizationRule = (TAttribute value, IScimTypeAttributeDefinition attributeDefinition) => { canonicalizationRule.Invoke(value, attributeDefinition); return(value); }; }
public static Uri EnforceScimUri(Uri uri, IScimTypeAttributeDefinition attributeDefinition, ScimServerConfiguration serverConfiguration) { /* * SCIM 2.0 Specification * referenceTypes A multi-valued array of JSON strings that indicate * the SCIM resource types that may be referenced. Valid values * are as follows: * + A SCIM resource type (e.g., "User" or "Group"), + + "external" - indicating that the resource is an external + resource (e.g., a photo), or + + "uri" - indicating that the reference is to a service + endpoint or an identifier (e.g., a schema URN). */ if (attributeDefinition.ReferenceTypes != null && attributeDefinition.ReferenceTypes.Any()) { IScimResourceTypeDefinition resourceDefinition = null; foreach (var referenceType in attributeDefinition.ReferenceTypes) { if (referenceType.Equals(ScimConstants.ReferenceTypes.External, StringComparison.OrdinalIgnoreCase)) { // do not accept relative URIs for an attribute which is defined as an external reference type if (!uri.IsAbsoluteUri) { continue; } return(uri); } if (referenceType.Equals(ScimConstants.ReferenceTypes.Uri, StringComparison.OrdinalIgnoreCase)) { if (uri.ToString().StartsWith(ScimConstants.Defaults.URNPrefix, StringComparison.OrdinalIgnoreCase)) { return(uri); // uri is an identifier, possibly schema } // uri MUST be a valid SCIM resource resourceDefinition = serverConfiguration .GetResourceTypeDefinitions(AmbientRequestService.ProtocolVersion) .SingleOrDefault(rtd => uri.AbsolutePath.IndexOf(rtd.Endpoint, StringComparison.OrdinalIgnoreCase) >= 0); if (resourceDefinition != null) { break; } continue; } // uri MUST be a valid SCIM resource that's within the allowed referenceTypes resourceDefinition = serverConfiguration .GetResourceTypeDefinitions(AmbientRequestService.ProtocolVersion) .SingleOrDefault( rtd => rtd.Name.Equals(referenceType, StringComparison.OrdinalIgnoreCase) && uri.AbsolutePath.IndexOf(rtd.Endpoint, StringComparison.OrdinalIgnoreCase) >= 0); if (resourceDefinition != null) { break; } } // invalid URI for the associated reference types if (resourceDefinition == null) { return(uri); // allow validation to handle invalid uri's } return(BuildScimUri(uri)); } /* * Relative URIs should be resolved as specified in * Section 5.2 of [RFC3986]. However, the base URI for relative URI * resolution MUST include all URI components and path segments up to, * but not including, the Endpoint URI (the SCIM service provider root * endpoint) */ return(BuildScimUri(uri)); }