Skip to content

Commit 4f89d52

Browse files
committed
[#SST-15979] add the ServiceProviderConfig(s) endpoints
1 parent e590c5c commit 4f89d52

File tree

7 files changed

+159
-12
lines changed

7 files changed

+159
-12
lines changed

app/controllers/concerns/scim_rails/response.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def json_scim_response(object:, status: :ok, counts: nil)
2020
when "delete"
2121
head status
2222
return
23+
when "configuration"
24+
response = ScimRails.config.config_schema
2325
end
2426

2527
render \
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module ScimRails
2+
class ScimServiceController < ScimRails::ApplicationController
3+
def configuration
4+
ScimRails.config.before_scim_response.call(request.params) unless ScimRails.config.before_scim_response.nil?
5+
6+
ScimRails.config.after_scim_response.call(users, "RETRIEVED") unless ScimRails.config.after_scim_response.nil?
7+
8+
json_scim_response(object: nil)
9+
end
10+
end
11+
end

config/routes.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
ScimRails::Engine.routes.draw do
2-
get 'scim/v2/Users', action: :index, controller: 'scim_users'
3-
post 'scim/v2/Users', action: :create, controller: 'scim_users'
4-
get 'scim/v2/Users/:id', action: :show, controller: 'scim_users'
5-
put 'scim/v2/Users/:id', action: :put_update, controller: 'scim_users'
6-
patch 'scim/v2/Users/:id', action: :patch_update, controller: 'scim_users'
7-
delete 'scim/v2/Users/:id', action: :delete, controller: 'scim_users'
2+
get 'scim/v2/Users', action: :index, controller: 'scim_users'
3+
post 'scim/v2/Users', action: :create, controller: 'scim_users'
4+
get 'scim/v2/Users/:id', action: :show, controller: 'scim_users'
5+
put 'scim/v2/Users/:id', action: :put_update, controller: 'scim_users'
6+
patch 'scim/v2/Users/:id', action: :patch_update, controller: 'scim_users'
7+
delete 'scim/v2/Users/:id', action: :delete, controller: 'scim_users'
88

9-
get 'scim/v2/Groups', action: :index, controller: 'scim_groups'
10-
post 'scim/v2/Groups', action: :create, controller: 'scim_groups'
11-
get 'scim/v2/Groups/:id', action: :show, controller: 'scim_groups'
12-
put 'scim/v2/Groups/:id', action: :put_update, controller: 'scim_groups'
13-
patch 'scim/v2/Groups/:id', action: :patch_update, controller: 'scim_groups'
14-
delete 'scim/v2/Groups/:id', action: :delete, controller: 'scim_groups'
9+
get 'scim/v2/Groups', action: :index, controller: 'scim_groups'
10+
post 'scim/v2/Groups', action: :create, controller: 'scim_groups'
11+
get 'scim/v2/Groups/:id', action: :show, controller: 'scim_groups'
12+
put 'scim/v2/Groups/:id', action: :put_update, controller: 'scim_groups'
13+
patch 'scim/v2/Groups/:id', action: :patch_update, controller: 'scim_groups'
14+
delete 'scim/v2/Groups/:id', action: :delete, controller: 'scim_groups'
15+
16+
get 'scim/v2/ServiceProviderConfig', action: :configuration, controller: 'scim_service'
17+
get 'scim/v2/ServiceProviderConfigs', action: :configuration, controller: 'scim_service'
1518
end

lib/generators/scim_rails/templates/initializer.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,40 @@
150150
config.after_scim_response = lambda do |object, status|
151151
print "#{object} #{status}"
152152
end
153+
154+
config.config_schema = {
155+
schemas: ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
156+
patch: {
157+
supported: true
158+
},
159+
bulk: {
160+
supported: false,
161+
maxOperations: 0,
162+
maxPayloadSize: 0
163+
},
164+
filter: {
165+
supported: true,
166+
},
167+
changePassword: {
168+
supported: false
169+
},
170+
sort: {
171+
supported: true
172+
},
173+
etag: {
174+
supported: false
175+
},
176+
authenticationSchemes: [
177+
{
178+
type: "oauthbearertoken",
179+
name: "Oauth Bearer Token",
180+
description: "Authentication scheme using the OAuth Bearer Token Standard"
181+
},
182+
{
183+
type: "httpbasic",
184+
name: "HTTP Basic",
185+
description: "Authentication scheme using the HTTP Basic Standard"
186+
}
187+
]
188+
}
153189
end

lib/scim_rails/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Config
4747
:before_scim_response,
4848
:after_scim_response,
4949
:scim_attribute_type_mappings,
50+
:config_schema
5051

5152
def initialize
5253
@basic_auth_model = "Company"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require "spec_helper"
2+
3+
RSpec.describe ScimRails::ScimServiceController, type: :controller do
4+
include AuthHelper
5+
6+
routes { ScimRails::Engine.routes }
7+
8+
describe "configuration" do
9+
let(:company) { create(:company) }
10+
11+
context "when unauthorized" do
12+
it "returns scim+json content type" do
13+
get :configuration
14+
15+
expect(response.content_type).to eq("application/scim+json")
16+
end
17+
18+
it "fails with no credentials" do
19+
get :configuration
20+
21+
expect(response.status).to eq(401)
22+
end
23+
24+
it "fails with invalid credentials" do
25+
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials("unauthorized","123456")
26+
27+
get :configuration
28+
29+
expect(response.status).to eq(401)
30+
end
31+
end
32+
33+
context "when authorized" do
34+
let(:body) { JSON.parse(response.body) }
35+
36+
before :each do
37+
http_login(company)
38+
end
39+
40+
it "returns scim+json content type" do
41+
get :configuration
42+
43+
expect(response.content_type).to eq("application/scim+json")
44+
end
45+
46+
it "is successful with valid credentials" do
47+
get :configuration
48+
49+
expect(response.status).to eq(200)
50+
end
51+
52+
it "successfully returns the configuration of the app" do
53+
get :configuration
54+
55+
expect(body.deep_symbolize_keys).to eq(ScimRails.config.config_schema)
56+
end
57+
end
58+
end
59+
end

spec/support/scim_rails_config.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,39 @@
117117
},
118118
}
119119

120+
config.config_schema = {
121+
schemas: ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
122+
patch: {
123+
supported: true
124+
},
125+
bulk: {
126+
supported: false,
127+
maxOperations: 0,
128+
maxPayloadSize: 0
129+
},
130+
filter: {
131+
supported: true,
132+
},
133+
changePassword: {
134+
supported: false
135+
},
136+
sort: {
137+
supported: true
138+
},
139+
etag: {
140+
supported: false
141+
},
142+
authenticationSchemes: [
143+
{
144+
type: "oauthbearertoken",
145+
name: "Oauth Bearer Token",
146+
description: "Authentication scheme using the OAuth Bearer Token Standard"
147+
},
148+
{
149+
type: "httpbasic",
150+
name: "HTTP Basic",
151+
description: "Authentication scheme using the HTTP Basic Standard"
152+
}
153+
]
154+
}
120155
end

0 commit comments

Comments
 (0)