spec

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

This package implements the founding blocks for defining SCIM resource types, and basic error types.

Index

Constants

View Source
const ApplicationScimJson = "application/scim+json"

SCIM defined standard content type

View Source
const CoreSchemaId = "core"

Reserved Id for core schema

View Source
const ISO8601 = "2006-01-02T15:04:05"

SCIM defined date format used to parse dateTime values.

Variables

View Source
var (
	// The specified filter syntax was invalid, or the specified attribute and filter comparison combination is not supported.
	ErrInvalidFilter = &Error{Status: 400, Type: "invalidFilter"}

	// The specified filter yields many more results than the server is willing to calculate or process.
	ErrTooMany = &Error{Status: 400, Type: "tooMany"}

	// One or more of the attribute values are already in use or are reserved.
	ErrUniqueness = &Error{Status: 409, Type: "uniqueness"}

	// The attempted modification is not compatible with the target attribute's mutability or current state (e.g.,
	// modification of an "immutable" attribute with an existing value).
	ErrMutability = &Error{Status: 400, Type: "mutability"}

	// The request body message structure was invalid or did not conform to the request schema.
	ErrInvalidSyntax = &Error{Status: 400, Type: "invalidSyntax"}

	// The "path" attribute was invalid or malformed.
	ErrInvalidPath = &Error{Status: 400, Type: "invalidPath"}

	// The specified "path" did not yield an attribute or attribute value that could be operated on. This occurs when
	// the specified "path" value contains a filter that yields no match.
	ErrNoTarget = &Error{Status: 400, Type: "noTarget"}

	// A required value was missing, or the value specified was not compatible with the operation or attribute type.
	ErrInvalidValue = &Error{Status: 400, Type: "invalidValue"}

	// The resource was not found from persistence store.
	ErrNotFound = &Error{Status: 404, Type: "notFound"}

	// The specified request cannot be completed, due to the passing of sensitive information in a request URI.
	ErrSensitive = &Error{Status: 400, Type: "sensitive"}

	// The resource is in conflict with some pre conditions.
	ErrConflict = &Error{Status: 412, Type: "conflict"}

	// Server encountered internal error.
	ErrInternal = &Error{Status: 500, Type: "internal"}
)

Error prototypes

Functions

func MetaAttributes

func MetaAttributes() *metaAttr

MetaAttributes returns a structure to access individual attributes about fields in Schema, Attribute and ResourceType. These attributes are known as meta attributes, because they describe things that are used to describe other resources.

func Schemas

func Schemas() *schemaRegistry

Schemas return the schema registry that holds all registered schemas. Use Get and Register to operate the registry.

Types

type Attribute

type Attribute struct {
	// contains filtered or unexported fields
}

Attribute models a superset of defined SCIM attributes. It serves as the basic unit that describes data requirement this project.

In addition to attributes defined in SCIM, four additional attributes are defined: id, index, path and annotations. Id defines a unique identifier for this attribute, which by convention, should be the full URN name. Index defines a relative ascending sort index for the attribute among other attributes on the same level, which can be used to ensure proper ordering and nice presentation. Path is joined attribute names from the root, which is used to determine the full attribute name without further calculation. Annotations are of type map[string]map[string]interface{}, which is used as the major extension point to define additional behaviour. It is widely used by other processing mechanisms in this module. These four additional attributes have JSON names of "id", "_index", "_path" and "_annotations" respectively.

As an example, a typical attribute can be defined in JSON as:

{
	"id": "urn:ietf:params:scim:schemas:core:2.0:User:name.familyName",
	"name": "familyName",
	"type": "string",
	"multiValued": false,
	"required": false,
	"caseExact": false,
	"mutability": "readWrite",
	"returned": "default",
	"uniqueness": "none",
	"_index": 1,
	"_path": "name.familyName",
	"_annotations": {
		"@Identity": {}
	}
}

The above example defines a typical "name.familyName" attribute in the User resource type. It can be universally identified by "urn:ietf:params:scim:schemas:core:2.0:User:name.familyName"; can be placed at the second position (index 1) among sub attributes of "urn:ietf:params:scim:schemas:core:2.0:User:name"; has a path of "name.familyName" and has a single parameter-less annotation of "@Identity".

Because Attribute is at the core of the SCIM protocol, it is designed to be read only as much as possible. All data access, including iteration, search operations, need to be done via accessor methods. For simple fields, look for the methods corresponding to the field name. For example, field name can be accessed via method Name. For array fields, look for methods prefixed with ForEach, Exists and Count to perform iteration, search and get-length operations.

Attribute also introduces the notion of an element attribute. An element attribute is a derived attribute from a multiValued attribute in order to represent the data requirements of its elements. Because elements of multiValued properties can be generated and deleted on the fly, these attributes also need to be so. DeriveElementAttribute can be used to generate a new element attribute. IsElementAttributeOf can be used to check if the current attribute is a derived element attribute.

As of now, Attribute is parsed to and from JSON using special adapter structures that exposes and hides certain fields. This design is subject to change when we move to treat Schema as just another resource. See also:

issue https://github.com/imulab/go-scim/issues/40

func (*Attribute) Annotation

func (attr *Attribute) Annotation(name string) (params map[string]interface{}, ok bool)

Annotation returns the annotation parameters by the given name (case sensitive) and a boolean indicating whether this annotations exists.

func (*Attribute) CaseExact

func (attr *Attribute) CaseExact() bool

CaseExact returns true if the attribute's value is case sensitive. Case sensitivity only applies to string attributes.

func (*Attribute) CountCanonicalValues

func (attr *Attribute) CountCanonicalValues() int

CountCanonicalValues returns the total number of canonical values defined.

func (*Attribute) CountReferenceTypes

func (attr *Attribute) CountReferenceTypes() int

CountReferenceTypes returns the total number of reference types.

func (*Attribute) CountSubAttributes

func (attr *Attribute) CountSubAttributes() int

Return the total number of sub attributes.

func (*Attribute) DFS

func (attr *Attribute) DFS(callback func(attr *Attribute))

DFS perform a depth-first-traversal on the given attribute and invokes callback

func (*Attribute) DeriveElementAttribute

func (attr *Attribute) DeriveElementAttribute() *Attribute

DeriveElementAttribute create an element attribute of this attribute. This method is only meaningful when invoked on a multiValued attribute.

The derived element attribute will inherit most properties from this attribute except for id, multiValued and annotations. Id will be suffixed with "$elem". MultiValued will be set to false. Annotations will be derived from the parameters of "@ElementAnnotations" from this attribute.

For example, a multiValued attribute (certain fields omitted for brevity) like

{
	"id": "urn:ietf:params:scim:schemas:core:2.0:User:emails",
	"name": "emails",
	"type": "complex",
	"multiValued": true,
	"_annotations": {
		"@ElementAnnotations": {
			"@StateSummary": {}
		}
	},
	...
}

will derive an element attribute of:

{
	"id": "urn:ietf:params:scim:schemas:core:2.0:User:emails$elem",
	"name": "emails",
	"type": "complex",
	"multiValued": false,
	"_annotations": {
		"@StateSummary": {}
	},
	...
}

See also:

annotation.ElementAnnotations

func (*Attribute) Description

func (attr *Attribute) Description() string

Description returns human-readable text to describe the attribute.

func (*Attribute) Equals

func (attr *Attribute) Equals(other *Attribute) bool

Equals returns true if the two attributes are considered equal.

func (*Attribute) ExistsCanonicalValue

func (attr *Attribute) ExistsCanonicalValue(criteria func(canonicalValue string) bool) bool

ExistsCanonicalValue returns true if the canonical value that meets the criteria exists; false otherwise.

func (*Attribute) ExistsReferenceType

func (attr *Attribute) ExistsReferenceType(criteria func(referenceType string) bool) bool

ExistsReferenceType returns true if the reference type that meets the criteria exists; false otherwise.

func (*Attribute) FindSubAttribute

func (attr *Attribute) FindSubAttribute(criteria func(subAttr *Attribute) bool) *Attribute

FindSubAttribute returns the sub attribute that matches the criteria, or returns nil if no sub attribute meets criteria.

func (*Attribute) ForEachAnnotation

func (attr *Attribute) ForEachAnnotation(callback func(annotation string, params map[string]interface{}))

ForEachAnnotation iterates through annotations and invoke callback.

func (*Attribute) ForEachCanonicalValues

func (attr *Attribute) ForEachCanonicalValues(callback func(canonicalValue string))

ForEachCanonicalValues invokes callback function on each defined canonical values

func (*Attribute) ForEachReferenceTypes

func (attr *Attribute) ForEachReferenceTypes(callback func(referenceType string))

ForEachReferenceTypes invokes callback function on each defined reference types

func (*Attribute) ForEachSubAttribute

func (attr *Attribute) ForEachSubAttribute(callback func(subAttribute *Attribute) error) error

ForEachSubAttribute invokes callback function on each sub attribute.

func (*Attribute) GoesBy

func (attr *Attribute) GoesBy(name string) bool

GoesBy returns true if this attribute can be addressed by the given name.

func (*Attribute) ID

func (attr *Attribute) ID() string

ID returns the id of the attribute that globally identifies the attribute. Attribute ids are in the format of <schema_urn>:<full_path>. Core attributes has no need to prefix the schema URN. For instance, "schemas", "meta.version", "urn:ietf:params:scim:schemas:core:2.0:Group:displayName"

func (*Attribute) IsElementAttributeOf

func (attr *Attribute) IsElementAttributeOf(other *Attribute) bool

IsElementAttributeOf returns true if this attribute is the derived element attribute of the other attribute.

func (*Attribute) Len

func (attr *Attribute) Len() int

func (*Attribute) Less

func (attr *Attribute) Less(i, j int) bool

func (*Attribute) MarshalJSON

func (attr *Attribute) MarshalJSON() ([]byte, error)

func (*Attribute) MultiValued

func (attr *Attribute) MultiValued() bool

MultiValued return whether the attribute allows several instance of properties to be defined.

func (*Attribute) Mutability

func (attr *Attribute) Mutability() Mutability

Mutability return the mutability definition of the attribute.

func (*Attribute) Name

func (attr *Attribute) Name() string

Name returns the name of the attribute.

func (*Attribute) Path

func (attr *Attribute) Path() string

Path returns the full path of this attribute. The full path are the name of all attributes from the root to this attribute, delimited by period ("."). For instance, "id", "meta.version", "emails.value".

func (*Attribute) PublicValues

func (attr *Attribute) PublicValues() interface{}

PublicValues returns a representation of this attribute's public values (non-extension) in a data structure that conforms to the definition of prop.Property#Raw. However, this method does not implement it.

func (*Attribute) Required

func (attr *Attribute) Required() bool

Required return true when the attribute is required.

func (*Attribute) Returned

func (attr *Attribute) Returned() Returned

Returned returns the returned definition of the attribute.

func (*Attribute) SubAttributeForName

func (attr *Attribute) SubAttributeForName(name string) *Attribute

Return the sub attribute that goes by the name, or nil

func (*Attribute) Swap

func (attr *Attribute) Swap(i, j int)

func (*Attribute) Type

func (attr *Attribute) Type() Type

Type return the data type of the attribute.

func (*Attribute) Uniqueness

func (attr *Attribute) Uniqueness() Uniqueness

Uniqueness return the uniqueness definition of the attribute.

func (*Attribute) UnmarshalJSON

func (attr *Attribute) UnmarshalJSON(raw []byte) error

type Error

type Error struct {
	Status int
	Type   string
}

A SCIM error message. The structure is left completely open for convenience, but it is not recommended to create Error directly. To create an error, use the error prototypes (i.e. ErrInvalidFilter). If needed, wrap the error prototype by fmt.Errorf("additional detail: %w", err).

func (Error) Error

func (s Error) Error() string

type Mutability

type Mutability int

SCIM mutability definition

const (
	MutabilityReadWrite Mutability = iota
	MutabilityReadOnly
	MutabilityWriteOnly
	MutabilityImmutable
)

SCIM mutability attribute defined in RFC7643

func (Mutability) String

func (m Mutability) String() string

type ResourceType

type ResourceType struct {
	// contains filtered or unexported fields
}

Resource type models the SCIM resource type. It is a collection of one main schema and zero or more schema extensions to describe a single type of SCIM resource.

To access the main schema of the resource type, call Schema method; to access the schema extensions, use ForEachExtension method.

A resource type can be used to generate a super attribute. A super attribute is a single valued complex typed attribute that encapsulates all attributes from its main schema and schema extensions as sub attributes. Among these, the top-level attributes from the main schema will be added to the super attribute as top level sub attributes. The top-level attributes from each schema extension will be first added to a container complex attribute as top level sub attributes, and then that single container complex attribute is added to the super attribute as a top level sub attribute.

For example, suppose we have a main schema containing attribute A1 and A2, a schema extension B containing attribute B1, and another schema extension C containing attribute C1 and C2. The super attribute will be in the structure of:

{
	A1,
	A2,
	B {
		B1
	},
	C {
		C1,
		C2
	}
}

ResourceType is currently being parsed to and from JSON using special adapters. This design is subject to change when we move to treat ResourceType as just another resource. See also:

issue https://github.com/imulab/go-scim/issues/40

func (*ResourceType) CountExtensions

func (t *ResourceType) CountExtensions() int

CountExtensions returns the total number of extensions

func (*ResourceType) Description

func (t *ResourceType) Description() string

Return the description of the resource type

func (*ResourceType) Endpoint

func (t *ResourceType) Endpoint() string

func (*ResourceType) ForEachExtension

func (t *ResourceType) ForEachExtension(callback func(extension *Schema, required bool) error) error

ForEachExtension iterates through all schema extensions and invoke the callback.

func (*ResourceType) ID

func (t *ResourceType) ID() string

Return the id of the resource type

func (*ResourceType) MarshalJSON

func (t *ResourceType) MarshalJSON() ([]byte, error)

func (*ResourceType) Name

func (t *ResourceType) Name() string

Return the name of the resource type

func (*ResourceType) ResourceLocation

func (t *ResourceType) ResourceLocation() string

ResourceLocation returns the relative URI at which this ResourceType resource can be accessed. This value is formally defined in the specification and hence fixed.

func (*ResourceType) ResourceTypeName

func (t *ResourceType) ResourceTypeName() string

ResourceTypeName returns the resource type of the ResourceType resource. This value is formally defined and hence fixed.

func (*ResourceType) Schema

func (t *ResourceType) Schema() *Schema

Return the main schema of the resource type

func (*ResourceType) SuperAttribute

func (t *ResourceType) SuperAttribute(includeCore bool) *Attribute

SuperAttribute return a virtual complex attribute that contains all schema attributes as its sub attributes.

func (*ResourceType) UnmarshalJSON

func (t *ResourceType) UnmarshalJSON(raw []byte) error

type Returned

type Returned int

SCIM returned definition

const (
	ReturnedDefault Returned = iota
	ReturnedAlways
	ReturnedRequest
	ReturnedNever
)

SCIM returned attribute defined in RFC7643

func (Returned) String

func (r Returned) String() string

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema models a SCIM schema. It is the collection of one or more attributes. Schema structure is read only after construction. Schema can be identified by its id, and can be cached in a schema registry.

See also:

Schemas()

Schema is currently being parsed to and from JSON via special adapters. This design is subject to change when we move to treat Schema as just another resource. See also:

issue https://github.com/imulab/go-scim/issues/40

func (*Schema) Description

func (s *Schema) Description() string

Description returns the human-readable text that describes the schema.

func (*Schema) ForEachAttribute

func (s *Schema) ForEachAttribute(callback func(attr *Attribute) error) error

ForEachAttribute iterate all attributes in this schema and invoke callback function.

func (*Schema) ID

func (s *Schema) ID() string

ID returns the id of the schema.

func (*Schema) MarshalJSON

func (s *Schema) MarshalJSON() ([]byte, error)

func (*Schema) Name

func (s *Schema) Name() string

Name returns the name of the schema.

func (*Schema) ResourceLocation

func (s *Schema) ResourceLocation() string

ResourceLocation returns the relative URI at which this Schema resource can be accessed. This value is formally defined in the specification and hence fixed.

func (*Schema) ResourceTypeName

func (s *Schema) ResourceTypeName() string

ResourceTypeName returns the resource type of the Schema resource. This value is formally defined and hence fixed.

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(raw []byte) error

type ServiceProviderConfig

type ServiceProviderConfig struct {
	Schemas []string `json:"schemas"`
	DocURI  string   `json:"documentationUri"`
	Patch   struct {
		Supported bool `json:"supported"`
	} `json:"patch"`
	Bulk struct {
		Supported  bool `json:"supported"`
		MaxOp      int  `json:"maxOperations"`
		MaxPayload int  `json:"maxPayloadSize"`
	} `json:"bulk"`
	Filter struct {
		Supported  bool `json:"supported"`
		MaxResults int  `json:"maxResults"`
	} `json:"filter"`
	ChangePassword struct {
		Supported bool `json:"supported"`
	} `json:"changePassword"`
	Sort struct {
		Supported bool `json:"supported"`
	} `json:"sort"`
	ETag struct {
		Supported bool `json:"supported"`
	} `json:"etag"`
	AuthSchemes []struct {
		Type        string `json:"type"`
		Name        string `json:"name"`
		Description string `json:"description"`
		SpecURI     string `json:"specUri"`
		DocURI      string `json:"documentationUri"`
	} `json:"authenticationSchemes"`
}

Service provider config

type Type

type Type int

A SCIM data type

const (
	TypeString Type = iota
	TypeInteger
	TypeDecimal
	TypeBoolean
	TypeDateTime
	TypeReference
	TypeBinary
	TypeComplex
)

SCIM data types defined in RFC7643

func (Type) String

func (t Type) String() string

type Uniqueness

type Uniqueness int

SCIM uniqueness definition

const (
	UniquenessNone Uniqueness = iota
	UniquenessServer
	UniquenessGlobal
)

SCIM uniqueness attribute defined in RFC7643

func (Uniqueness) String

func (u Uniqueness) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL