Commit 7a53298
Changed files (6)
app
controllers
scim
models
scim
spec
requests
scim
app/controllers/scim/v2/schemas_controller.rb
@@ -6,7 +6,7 @@ module Scim
skip_before_action :authenticate!
def index
- render json: [user_schema, group_schema].to_json
+ render json: [schema.user, schema.group].to_json
end
def show
@@ -16,87 +16,12 @@ module Scim
private
def current_schema(url = request.original_url)
- return group_schema if url.include?(Scim::Kit::V2::Schemas::GROUP)
- return user_schema if url.include?(Scim::Kit::V2::Schemas::USER)
+ return schema.group if url.include?(Scim::Kit::V2::Schemas::GROUP)
+ return schema.user if url.include?(Scim::Kit::V2::Schemas::USER)
end
- def user_schema
- Scim::Kit::V2::Schema.build(
- id: Scim::Kit::V2::Schemas::USER,
- name: "User",
- location: scim_v2_schema_url(id: Scim::Kit::V2::Schemas::USER)
- ) do |schema|
- schema.description = "User Account"
- schema.add_attribute(name: 'userName') do |x|
- x.description = "Unique identifier for the User"
- x.required = true
- x.uniqueness = :server
- end
- schema.add_attribute(name: 'password') do |x|
- x.description = "The User's cleartext password."
- x.mutability = :write_only
- x.required = false
- x.returned = :never
- end
- schema.add_attribute(name: 'emails') do |x|
- x.multi_valued = true
- x.description = "Email addresses for the user."
- x.add_attribute(name: 'value') do |y|
- y.description = "Email addresses for the user."
- end
- x.add_attribute(name: 'primary', type: :boolean) do |y|
- y.description = "A Boolean value indicating the preferred email"
- end
- end
- schema.add_attribute(name: 'groups') do |x|
- x.multi_valued = true
- x.description = "A list of groups to which the user belongs."
- x.mutability = :read_only
- x.add_attribute(name: 'value') do |y|
- y.description = "The identifier of the User's group."
- y.mutability = :read_only
- end
- x.add_attribute(name: '$ref', type: :reference) do |y|
- y.reference_types = %w[User Group]
- y.description = "The URI of the corresponding 'Group' resource."
- y.mutability = :read_only
- end
- x.add_attribute(name: 'display') do |y|
- y.description = "A human-readable name."
- y.mutability = :read_only
- end
- end
- end
- end
-
- def group_schema
- Scim::Kit::V2::Schema.new(
- id: Scim::Kit::V2::Schemas::GROUP,
- name: "Group",
- location: scim_v2_schema_url(id: Scim::Kit::V2::Schemas::GROUP)
- ) do |schema|
- schema.description = "Group"
- schema.add_attribute(name: 'displayName') do |x|
- x.description = "A human-readable name for the Group."
- end
- schema.add_attribute(name: 'members') do |x|
- x.description = "A list of members of the Group."
- x.add_attribute(name: 'value') do |y|
- y.description = "Identifier of the member of this Group."
- y.mutability = :immutable
- end
- x.add_attribute(name: '$ref') do |y|
- y.description = "The URI corresponding to a SCIM resource."
- y.reference_types = %w[User Group]
- y.mutability = :immutable
- end
- x.add_attribute(name: 'type') do |y|
- y.description = "A label indicating the type of resource"
- y.canonical_values = %w[User Group]
- y.mutability = :immutable
- end
- end
- end
+ def schema
+ SCIM::Schema
end
end
end
app/models/scim/schema.rb
@@ -6,5 +6,69 @@ module SCIM
GROUP = 'urn:ietf:params:scim:schemas:core:2.0:Group'
RESOURCE_TYPE = 'urn:ietf:params:scim:schemas:core:2.0:ResourceType'
USER = 'urn:ietf:params:scim:schemas:core:2.0:User'
+
+ def self.group
+ url = Spank::IOC.resolve(:url_helpers)
+
+ Scim::Kit::V2::Schema.new(
+ id: Scim::Kit::V2::Schemas::GROUP,
+ name: "Group",
+ location: url.scim_v2_schema_url(id: Scim::Kit::V2::Schemas::GROUP)
+ ) do |schema|
+ schema.add_attribute(name: 'displayName')
+ schema.add_attribute(name: 'members') do |x|
+ x.add_attribute(name: 'value') do |y|
+ y.mutability = :immutable
+ end
+ x.add_attribute(name: '$ref') do |y|
+ y.reference_types = %w[User Group]
+ y.mutability = :immutable
+ end
+ x.add_attribute(name: 'type') do |y|
+ y.canonical_values = %w[User Group]
+ y.mutability = :immutable
+ end
+ end
+ end
+ end
+
+ def self.user
+ url = Spank::IOC.resolve(:url_helpers)
+
+ Scim::Kit::V2::Schema.build(
+ id: Scim::Kit::V2::Schemas::USER,
+ name: "User",
+ location: url.scim_v2_schema_url(id: Scim::Kit::V2::Schemas::USER)
+ ) do |schema|
+ schema.add_attribute(name: 'userName') do |x|
+ x.required = true
+ x.uniqueness = :server
+ end
+ schema.add_attribute(name: 'password') do |x|
+ x.mutability = :write_only
+ x.required = false
+ x.returned = :never
+ end
+ schema.add_attribute(name: 'emails') do |x|
+ x.multi_valued = true
+ x.add_attribute(name: 'value')
+ x.add_attribute(name: 'primary', type: :boolean)
+ end
+ schema.add_attribute(name: 'groups') do |x|
+ x.multi_valued = true
+ x.mutability = :read_only
+ x.add_attribute(name: 'value') do |y|
+ y.mutability = :read_only
+ end
+ x.add_attribute(name: '$ref', type: :reference) do |y|
+ y.reference_types = %w[User Group]
+ y.mutability = :read_only
+ end
+ x.add_attribute(name: 'display') { |y| y.mutability = :read_only }
+ end
+ schema.add_attribute(name: 'timezone')
+ schema.add_attribute(name: 'locale')
+ end
+ end
end
end
app/models/scim/user_mapper.rb
@@ -7,19 +7,17 @@ module SCIM
end
def map_from(user)
- Scim::Shady::User.build do |x|
- x.id = user.id
- x.username = user.email
- x.created_at = user.created_at
- x.updated_at = user.updated_at
- x.location = @url_helpers.scim_v2_user_url(user)
- x.locale = user.locale
- x.timezone = user.timezone
- x.version = user.lock_version
- x.emails do |y|
- y.add(user.email, primary: true)
- end
- end
+ schema = SCIM::Schema.user
+ x = Scim::Kit::V2::Resource.new(schemas: [schema], location: @url_helpers.scim_v2_user_url(user))
+ x.meta.version = user.lock_version
+ x.meta.created = user.created_at
+ x.meta.last_modified = user.updated_at
+ x.id = user.id
+ x.user_name = user.email
+ x.locale = user.locale
+ x.timezone = user.timezone
+ x.emails = [{ value: user.email, primary: true }]
+ x
end
end
end
spec/requests/scim/v2/users_spec.rb
@@ -142,7 +142,7 @@ describe '/scim/v2/users' do
specify { expect(json[:meta][:lastModified]).to be_present }
specify { expect(json[:meta][:version]).to be_present }
specify { expect(json[:meta][:location]).to be_present }
- specify { expect(json[:emails]).to match_array([value: new_email, type: 'work', primary: true]) }
+ specify { expect(json[:emails]).to match_array([value: new_email, primary: true]) }
specify { expect(json[:locale]).to eql(locale) }
specify { expect(json[:timezone]).to eql(timezone) }
end
Gemfile
@@ -23,7 +23,6 @@ gem 'rails', '~> 5.2.0'
gem 'rotp', '~> 3.3'
gem 'saml-kit', '~> 1.0'
gem 'scim-kit', '~> 0.2'
-gem 'scim-shady', '~> 0.2'
gem 'spank', '~> 1.0'
gem 'turbolinks', '~> 5'
gem 'webpacker', '~> 3.5'
Gemfile.lock
@@ -113,7 +113,7 @@ GEM
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
ffaker (2.10.0)
- ffi (1.9.25)
+ ffi (1.10.0)
flipper (0.16.0)
flipper-active_record (0.16.0)
activerecord (>= 3.2, < 6)
@@ -290,11 +290,9 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
- scim-kit (0.2.1)
+ scim-kit (0.2.2)
tilt (~> 2.0)
tilt-jbuilder (~> 0.7)
- scim-shady (0.2.1)
- activesupport (>= 4.2.0)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
@@ -388,7 +386,6 @@ DEPENDENCIES
rubocop-rspec (~> 1.30)
saml-kit (~> 1.0)
scim-kit (~> 0.2)
- scim-shady (~> 0.2)
selenium-webdriver (~> 3.14)
spank (~> 1.0)
turbolinks (~> 5)