View Source SmeeView.Attributes (SmeeView v0.2.0)

This module can extracts the <saml:Attribute> elements in entity metadata as "aspect" structs, and then process and filter the results.

Aspects can be extracted with three functions:

  • Views, via view/3 are lists of aspects
  • Prisms, via prism/3 are maps of entity IDs to views
  • There is also view_one/3 which returns the first aspect found

Aspects can be extracted from Smee.Metadata structs, Smee.Entity structs, or lists of aspects, Metadata and Entity structs.

The other functions in this module are intended to be applied to collections of aspect structs - for working with individual aspects, please look at the appropriate Aspect module.

Summary

Functions

Returns true if the aspects contain the specified attribute name

Returns true if the aspects contain the specified attribute friendly name

Returns a list of all attribute names (full, technical, URI names).

Removes any non-IdP aspects from a list (view) or map (prism)

Returns a list of all attribute names (full, technical, URI names).

Returns a map of Elixir.SmeeView.Aspects.Attribute aspect structs extracted from the input data, with entity IDs as keys.

Returns only SAML1 attributes

Returns only SAML2 attributes

Removes any non-SP aspects from a list (view) or map (prism)

Returns a list of Elixir.SmeeView.Aspects.Attribute aspect structs extracted from the input data.

Returns a single Elixir.SmeeView.Aspects.Attribute aspect struct extracted from one record in the input data.

Functions

@spec contain?(aspects :: list() | map(), name :: binary()) :: boolean() | map()

Returns true if the aspects contain the specified attribute name

  Attributes.contain?(attrs, "urn:oid:1.3.6.1.4.1.5923.1.1.1.6")
# => true

Link to this function

contain_friendly?(aspects, friendly_name)

View Source
@spec contain_friendly?(aspects :: list() | map(), name :: binary()) ::
  boolean() | map()

Returns true if the aspects contain the specified attribute friendly name

  Attributes.contain?(attrs, "sn")
# => true

@spec friendly_names(aspects :: list() | map()) :: list() | map()

Returns a list of all attribute names (full, technical, URI names).

The results are sorted and each value is unique.

  Attributes.friendly_names(attrs)
# => ["eduPersonPrincipalName", "email", "organizationName"]
@spec idp_filter(aspects :: map() | list()) :: map() | list()

Removes any non-IdP aspects from a list (view) or map (prism)

Attributes.idp_filter(view)
# => []
@spec names(aspects :: list() | map()) :: list() | map()

Returns a list of all attribute names (full, technical, URI names).

The results are sorted and each value is unique.

  Attributes.names(attrs)
# => ["urn:oid:1.3.6.1.4.1.5923.1.1.1.6", "urn:oid:0.9.2342.19200300.100.1.3", "urn:oid:2.5.4.10"]
Link to this function

prism(various, role \\ :all, options \\ [])

View Source
@spec prism(
  various :: Smee.Entity.t() | Smee.Metadata.t() | list(),
  role :: atom(),
  options :: keyword()
) :: map()

Returns a map of Elixir.SmeeView.Aspects.Attribute aspect structs extracted from the input data, with entity IDs as keys.

Input data can be a Smee.Entity or Smee.Metadata struct, or a list containing Smee.Entity and/or Smee.Metadata structs. Only appropriate aspect records will be returned.

prism/3 is useful for extracting specific types of aspects from lists of entity records, or metadata. If you are only interested in one aspect from a single Smee.Entity struct then you should probably use view/3 instead.

The optional role parameter will optimize the results to only search for either :idp or :sp aspects. The default is :all.

Attributes.prism(entity)
# => %{"https://example.com/shibboleth" =>  [%Elixir.SmeeView.Aspects.Attribute{}, %Elixir.SmeeView.Aspects.Attribute{},]}
@spec saml1_filter(aspects :: list() | map()) :: list()

Returns only SAML1 attributes

Filters the view (list) or prism (map) to only include SAML1 attributes

Attributes.saml1_filter(aspects)
# =>  [%Elixir.SmeeView.Aspects.Attribute{}]
@spec saml2_filter(aspects :: list() | map()) :: list()

Returns only SAML2 attributes

Filters the view (list) or prism (map) to only include SAML2 attributes

Attributes.saml2_filter(aspects)
# => [%Elixir.SmeeView.Aspects.Attribute{}]
@spec sp_filter(aspects :: map() | list()) :: map() | list()

Removes any non-SP aspects from a list (view) or map (prism)

Attributes.sp_filter(view)
# => []
Link to this function

view(list, role \\ :all, options \\ [])

View Source
@spec view(
  list :: Smee.Entity.t() | Smee.Metadata.t() | list(),
  role :: atom(),
  options :: keyword()
) ::
  list()

Returns a list of Elixir.SmeeView.Aspects.Attribute aspect structs extracted from the input data.

Input data can be a Smee.Entity or Smee.Metadata struct, or a list containing Smee.Entity, Smee.Metadata or any aspects. Only appropriate aspect records will be returned.

view/3 is useful for extracting specific types of aspects from one Entity, but because it has no entity ID information it's often not the best choice for handling Metadata. When extracting information from entire metadata it's often better to use prism/3 which returns the same data in a map, associated with each entity's ID.

The optional role parameter will optimize the results to only search for either :idp or :sp aspects. The default is :all.

Attributes.view(entity)
# => [%Elixir.SmeeView.Aspects.Attribute{}, %Elixir.SmeeView.Aspects.Attribute{}]
Link to this function

view_one(smee_data, role \\ :all, options \\ [])

View Source
@spec view_one(
  list :: Smee.Entity.t() | Smee.Metadata.t() | list(),
  role :: atom(),
  options :: keyword()
) :: SmeeView.Aspects.Attribute.t() | nil

Returns a single Elixir.SmeeView.Aspects.Attribute aspect struct extracted from one record in the input data.

Input data can be a Smee.Entity or Smee.Metadata struct, or a list containing Smee.Entity, Smee.Metadata or any aspects.

Only one entity will be processed and then only one aspect will be returned. If you pass one Entity struct as the input, it will be that entity (obviously). If you pass metadata structs or lists one entity will be chosen at random. The first suitable entity will be returned.

view_one/3 is intended for use with a single entity record and aspects like SmeeView.Aspect.Entity, SmeeView.Aspect.SP' orSmeeView.Aspect.Organization' but will work with any aspect.

The optional role parameter will optimize the results to only search for either :idp or :sp aspects. The default is :all.

Attributes.view_one(entity)
# => %Elixir.SmeeView.Aspects.Attribute{}