scim_engine 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84aac5eb3121ba10036412a4c5d8ae959cf8fc99
4
- data.tar.gz: f9c50a53333b47f4e6961dfa2a9fe256d2f207c7
3
+ metadata.gz: 4ed9981951b0782ba7db0326ff758e4dd8c708d2
4
+ data.tar.gz: 5f0df404b9c2f6c8c0a57bfc852ef250062bc487
5
5
  SHA512:
6
- metadata.gz: 0bbf31701459d913599fdd83dd90b0120e19fc3c1cbff4133070293d93191044fb82fd2b2df79257544ee24618704d90946ebfea69ea632f243e30af0965584c
7
- data.tar.gz: a53d3895e691a9aaa7ae5b4adfd7755d430c129b36b820c91a48568b03548a84e1b4673ab207dfae95b78ea03fd15c731369dda4a2c9bcc95c181e881cde6bdd
6
+ metadata.gz: b04416ef679a70dcd8f7de73815c00b08ada6ad979c5a3437be430d682744e036a09af46ae61dd77ebbf1361a545b2f9e087a10cdbffca42810ac17ffec3a9cd
7
+ data.tar.gz: 9c8bceaad662bd5b1b720ac277a63e1935857d3243260435814d7510ba690de64e5c1a8cbf352191ca844e1bad6b7173afb34f87cfcbcc00890a54f61837cea5
@@ -1,5 +1,20 @@
1
1
  module ScimEngine
2
2
  module ComplexTypes
3
+ # This class represents complex types that could be used inside SCIM resources.
4
+ # Each complex type must inherit from this class. They also need to have their own schema defined.
5
+ # @example
6
+ # module ScimEngine
7
+ # module ComplexTypes
8
+ # class Email < Base
9
+ # set_schema ScimEngine::Schema::Email
10
+ #
11
+ # def as_json(options = {})
12
+ # {'type' => 'work', 'primary' => true}.merge(super(options))
13
+ # end
14
+ # end
15
+ # end
16
+ # end
17
+ #
3
18
  class Base
4
19
  include ActiveModel::Model
5
20
  include ScimEngine::Schema::DerivedAttributes
@@ -10,6 +25,9 @@ module ScimEngine
10
25
  @errors = ActiveModel::Errors.new(self)
11
26
  end
12
27
 
28
+ # Converts the object to its SCIM representation which is always a json representation
29
+ # @param options [Hash] a hash that could provide default values for some of the attributes of this complex type object
30
+ #
13
31
  def as_json(options={})
14
32
  options[:except] ||= ['errors']
15
33
  super.except(options)
@@ -1,8 +1,11 @@
1
1
  module ScimEngine
2
2
  module ComplexTypes
3
+ # Represents the complex email type.
4
+ # @see ScimEngine::Schema::Email
3
5
  class Email < Base
4
6
  set_schema ScimEngine::Schema::Email
5
7
 
8
+ # Returns the json representation of an email.
6
9
  def as_json(options = {})
7
10
  {'type' => 'work', 'primary' => true}.merge(super(options))
8
11
  end
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module ComplexTypes
3
+ # Represents the complex name type.
4
+ # @see ScimEngine::Schema::Name
3
5
  class Name < Base
4
6
  set_schema ScimEngine::Schema::Name
5
7
  end
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module ComplexTypes
3
+ # Represents the complex reference type.
4
+ # @see ScimEngine::Schema::Reference
3
5
  class Reference < Base
4
6
  set_schema ScimEngine::Schema::Reference
5
7
  end
@@ -1,4 +1,5 @@
1
1
  module ScimEngine
2
+ # Provides info about a resource type. Instances of this class are used to provide info through the /ResourceTypes endpoint of a SCIM service provider.
2
3
  class ResourceType
3
4
  include ActiveModel::Model
4
5
  attr_accessor :meta, :endpoint, :schema, :schemas, :id, :name, :schemaExtensions
@@ -1,5 +1,6 @@
1
1
  module ScimEngine
2
2
  module Resources
3
+ # The base class for all SCIM resources.
3
4
  class Base
4
5
  include ActiveModel::Model
5
6
  include ScimEngine::Schema::DerivedAttributes
@@ -27,6 +28,34 @@ module ScimEngine
27
28
  flattened
28
29
  end
29
30
 
31
+ # Can be used to extend an existing resource type's schema
32
+ # @example
33
+ # module Scim
34
+ # module Schema
35
+ # class MyExtension < ScimEngine::Schema::Base
36
+ #
37
+ # def initialize(options = {})
38
+ # super(name: 'ExtendedGroup',
39
+ # id: self.class.id,
40
+ # description: 'Represents extra info about a group',
41
+ # scim_attributes: self.class.scim_attributes)
42
+ # end
43
+ #
44
+ # def self.id
45
+ # 'urn:ietf:params:scim:schemas:extension:extendedgroup:2.0:Group'
46
+ # end
47
+ #
48
+ # def self.scim_attributes
49
+ # [ScimEngine::Schema::Attribute.new(name: 'someAddedAttribute',
50
+ # type: 'string',
51
+ # required: true,
52
+ # canonicalValues: ['FOO', 'BAR'])]
53
+ # end
54
+ # end
55
+ # end
56
+ # end
57
+ #
58
+ # ScimEngine::Resources::Group.extend_schema Scim::Schema::MyExtention
30
59
  def self.extend_schema(schema)
31
60
  derive_attributes_from_schema(schema)
32
61
  extended_schemas << schema
@@ -1,10 +1,16 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # Represents an attribute of a SCIM resource that is declared in its schema.
4
+ # Attributes can be simple or complex. A complex attribute needs to have its own schema that is passed to the initilize method when the attribute is instantiated.
5
+ # @example
6
+ # Attribute.new(name: 'userName', type: 'string', uniqueness: 'server')
7
+ # Attribute.new(name: 'name', complexType: ScimEngine::ComplexTypes::Name)
3
8
  class Attribute
4
9
  include ActiveModel::Model
5
10
  include ScimEngine::Errors
6
11
  attr_accessor :name, :type, :multiValued, :required, :caseExact, :mutability, :returned, :uniqueness, :subAttributes, :complexType, :canonicalValues
7
12
 
13
+ # @param options [Hash] a hash of values to be used for instantiating the attribute object. Some of the instance variables of the objects will have default values if this hash does not contain anything for them.
8
14
  def initialize(options = {})
9
15
  defaults = {
10
16
  multiValued: false,
@@ -23,6 +29,9 @@ module ScimEngine
23
29
  super(defaults.merge(options || {}))
24
30
  end
25
31
 
32
+ # Validates a value against this attribute object. For simple attributes, it checks if blank is valid or not and if the type matches. For complex attributes, it delegates it to the valid? method of the complex type schema.
33
+ # If the value is not valid, validation message(s) are added to the errors attribute of this object.
34
+ # @return [Boolean] whether or not the value is valid for this attribute
26
35
  def valid?(value)
27
36
  return valid_blank? if value.blank? && !value.is_a?(FalseClass)
28
37
 
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # The base class that each schema class must inherit from.
4
+ # These classes represent the schema of a SCIM resource or a complex type that could be used in a resource.
3
5
  class Base
4
6
  include ActiveModel::Model
5
7
  attr_accessor :id, :name, :description, :scim_attributes, :meta
@@ -9,12 +11,15 @@ module ScimEngine
9
11
  @meta = Meta.new(resourceType: "Schema")
10
12
  end
11
13
 
14
+ # Converts the schema to its json representation that will be returned by /SCHEMAS end-point of a SCIM service provider.
12
15
  def as_json(options = {})
13
16
  @meta.location = ScimEngine::Engine.routes.url_helpers.scim_schemas_path(name: id)
14
17
  original = super
15
18
  original.merge('attributes' => original.delete('scim_attributes'))
16
19
  end
17
20
 
21
+ # Validates the resource against specific validations of each attribute,for example if the type of the attribute matches the one defined in the schema.
22
+ # @param resource [Object] a resource object that uses this schema
18
23
  def self.valid?(resource)
19
24
  cloned_scim_attributes.each do |scim_attribute|
20
25
  resource.add_errors_from_hash(scim_attribute.errors.to_hash) unless scim_attribute.valid?(resource.send(scim_attribute.name))
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # Represnts the schema for the Email complex type
4
+ # @see ScimEngine::ComplexTypes::Email
3
5
  class Email < Base
4
6
  def self.scim_attributes
5
7
  @scim_attributes ||= [
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # Represnts the schema for the Group resource
4
+ # @see ScimEngine::Resources::Group
3
5
  class Group < Base
4
6
 
5
7
  def initialize(options = {})
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # Represnts the schema for the Name complex type
4
+ # @see ScimEngine::ComplexTypes::Name
3
5
  class Name < Base
4
6
 
5
7
  def self.scim_attributes
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # Represnts the schema for the Reference complex type
4
+ # @see ScimEngine::ComplexTypes::Reference
3
5
  class Reference < Base
4
6
  def self.scim_attributes
5
7
  @scim_attributes ||= [
@@ -1,5 +1,7 @@
1
1
  module ScimEngine
2
2
  module Schema
3
+ # Represnts the schema for the User resource
4
+ # @see ScimEngine::Resources::User
3
5
  class User < Base
4
6
 
5
7
  def initialize(options = {})
@@ -1,4 +1,5 @@
1
1
  module ScimEngine
2
+ # Represnts the service provider info. Used by the /ServiceProviderConfig endpoint to privide specification compliance, authentication schemes, data models.
2
3
  class ServiceProviderConfiguration
3
4
  include ActiveModel::Model
4
5
 
@@ -15,14 +15,30 @@ module ScimEngine
15
15
  default_resources + custom_resources
16
16
  end
17
17
 
18
+ # Can be used to add a new resource type which is not provided by the gem.
19
+ # @example
20
+ # module Scim
21
+ # module Resources
22
+ # class ShinyResource < ScimEngine::Resources::Base
23
+ # set_schema Scim::Schema::Shiny
24
+ #
25
+ # def self.endpoint
26
+ # "/Shinies"
27
+ # end
28
+ # end
29
+ # end
30
+ # end
31
+ # ScimEngine::Engine.add_custom_resource Scim::Resources::ShinyResource
18
32
  def self.add_custom_resource(resource)
19
33
  custom_resources << resource
20
34
  end
21
35
 
36
+ # Returns the list of custom resources, if any.
22
37
  def self.custom_resources
23
38
  @custom_resources ||= []
24
39
  end
25
40
 
41
+ # Returns the default resources added in this gem: User and Group.
26
42
  def self.default_resources
27
43
  [ Resources::User, Resources::Group ]
28
44
  end
@@ -1,3 +1,3 @@
1
1
  module ScimEngine
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scim_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''