如何解决PATCH操作中的SCIM用户名
我已经使用SCIM实施了用户预配置/取消预配置:
users_controller.rb
class Scim::UsersController < Scim::ScimController
before_action :set_scim_provider
def index
startIndex = params[:startIndex].to_i
startIndex = 1 if startIndex < 1# if the user send a startIndex < 1,it is bad data,we don't take it.
itemsPerPage = params[:count].to_i
if itemsPerPage < 1 || itemsPerPage > @scim_provider.max_results
itemsPerPage = @scim_provider.default_number_of_results
end
scim_users = @scim_provider.identity_provider.communaute_accesses.from_scim
if params["filter"]
parser = Scim::QueryFilter::Parser.new
rpn_array = parser.parse(params["filter"])
tree = parser.tree
if tree.length == 3 and tree[0]== 'eq' and tree[1] == 'userName'
userName = tree[2]
scim_users = scim_users.where(provider_identifier: userName.delete('"'))
else
fail 'e'
end
end
paginated_users = scim_users.order(:created_at).offset(startIndex - 1).limit(itemsPerPage)
r = {
"schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],"totalResults": scim_users.size,"Resources": paginated_users.map { |ca| @scim_provider.representation_for_user(ca) },"startIndex": startIndex,"itemsPerPage": itemsPerPage
}
render_json_result(r,200)
end
def create
if @scim_provider.identity_provider.communaute_accesses.from_scim.find_by(provider_identifier: @body_params['userName'])
render_409_conflict("uniqueness")
else
ca = @scim_provider.identity_provider.communaute_accesses.find_by(provider_identifier: @body_params['userName'],communaute_id: @scim_provider.identity_provider.communaute.id)
if ca.nil?
ca = @scim_provider.identity_provider.communaute_accesses.create(provider_identifier: @body_params['userName'],communaute_id: @scim_provider.identity_provider.communaute.id)
end
ca.update_last_raw_value("scim",@body_string)
ca.extract_values_from_scim
ca.queue_send
end
render_json_result(@scim_provider.representation_for_user(ca),201)
end
def show
user = @scim_provider.identity_provider.communaute_accesses.from_scim.find_by(provider_identifier: @body_params['userName'])
if user
render_json_result(@scim_provider.representation_for_user(user),200)
else
render_404_not_found(params[:id])
end
end
def update
ca = @scim_provider.identity_provider.communaute_accesses.from_scim.find_by(provider_identifier: @body_params['userName'])
uc = UserCommunaute.find_by(provider_identifier: @body_params['userName'])
ca.update_last_raw_value("scim",@body_string)
ca.extract_values_from_scim
unless ca.nil?
if ca.pending?
ca.update_last_raw_value("scim",@body_string)
ca.update(active: false)
if ca.active == false
fail "Unable to delete this user because of activeness" if ca.active == true
ca.destroy!
end
render_json_result(@scim_provider.representation_for_communaute_access_patch(ca),200)
end
end
unless uc.nil?
uc.update(active: @body_params['active'])
if uc.active == false
uc.user.communaute_accesses.from_scim.destroy_all
uc.user.user_communautes.from_scim.destroy_all
render_json_result(@scim_provider.representation_for_user_communaute_patch(uc),200)
end
end
end
end
说明:
更新用户时,SCIM发送如下的PATCH请求:
{"schemas"=>["urn:ietf:params:scim:api:messages:2.0:PatchOp"],"Operations"=>[{"op"=>"Replace","path"=>"active","value"=>"False"}]}
(代码中的@body_params
)
这是我所期望的。但是有一段时间,我在PATCH操作期间的身体反应中也收到了userName
。
这是我在数据库中获取正确用户的方式。
实际结果:
当SCIM击中我的userName
操作时,我不再收到update
。
预期结果:
在PATCH操作期间能够接收有关用户的信息,以获取userName
并在我的数据库中找到合适的用户。
我几乎尝试了所有事情。当SCIM击中index
动作时,每次执行此动作之前,它都会返回userName
,一切以200 OK结束。
然后,通过update
时,它什么也没发送给我。
我最后尝试的是将userName
隔离为index
动作中的实例变量,以便在update
中获取它,如下所示:
# index
...
if params["filter"]
parser = Scim::QueryFilter::Parser.new
rpn_array = parser.parse(params["filter"])
tree = parser.tree
if tree.length == 3 and tree[0]== 'eq' and tree[1] == 'userName'
@user_name = tree[2]
scim_users = scim_users.where(provider_identifier: @user_name.delete('"'))
else
fail 'e'
end
end
...
# update
def update
ca = @scim_provider.identity_provider.communaute_accesses.from_scim.find_by(provider_identifier: @user_name)
uc = UserCommunaute.find_by(provider_identifier: @user_name)
ca.update_last_raw_value("scim",@body_string)
ca.extract_values_from_scim
...
但是,@user_name
中的update
似乎消失了,因为其值为nil
。
我正在生产环境中从Azure Active Directory和Okta取消配置。 在两个平台上都可以进行映射。 置备工作就像一种魅力。
解决方法
有关PATCH / Users / {userId},请参阅https://developer.okta.com/docs/reference/scim/scim-20/#update-a-specific-user-patch。您不能使用url中的userId来标识用户吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。