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 +4 -4
- data/app/models/scim_engine/complex_types/base.rb +18 -0
- data/app/models/scim_engine/complex_types/email.rb +3 -0
- data/app/models/scim_engine/complex_types/name.rb +2 -0
- data/app/models/scim_engine/complex_types/reference.rb +2 -0
- data/app/models/scim_engine/resource_type.rb +1 -0
- data/app/models/scim_engine/resources/base.rb +29 -0
- data/app/models/scim_engine/schema/attribute.rb +9 -0
- data/app/models/scim_engine/schema/base.rb +5 -0
- data/app/models/scim_engine/schema/email.rb +2 -0
- data/app/models/scim_engine/schema/group.rb +2 -0
- data/app/models/scim_engine/schema/name.rb +2 -0
- data/app/models/scim_engine/schema/reference.rb +2 -0
- data/app/models/scim_engine/schema/user.rb +2 -0
- data/app/models/scim_engine/service_provider_configuration.rb +1 -0
- data/lib/scim_engine/engine.rb +16 -0
- data/lib/scim_engine/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed9981951b0782ba7db0326ff758e4dd8c708d2
|
4
|
+
data.tar.gz: 5f0df404b9c2f6c8c0a57bfc852ef250062bc487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,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))
|
data/lib/scim_engine/engine.rb
CHANGED
@@ -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
|
data/lib/scim_engine/version.rb
CHANGED