首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >补丁操作中的SCIM userName

补丁操作中的SCIM userName
EN

Stack Overflow用户
提问于 2020-10-09 09:15:03
回答 1查看 139关注 0票数 1

我已经使用SCIM实现了用户配置/取消配置,如下所示:

users_controller.rb

代码语言:javascript
复制
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发送一个补丁请求,如下所示:{"schemas"=>["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations"=>[{"op"=>"Replace", "path"=>"active", "value"=>"False"}]} (代码中的@body_params)

这正是我所期待的。但是,有一段时间,在补丁操作期间,我也在身体响应中接收到了userName

--这就是我如何在DB.中获取正确用户的方法。

的实际结果:当按下update操作时,不再接收userName

预期的结果:能够在修补程序操作期间接收有关用户的信息,以获取userName并在我的数据库中找到正确的用户。

我几乎什么都试过了。当SCIM执行index操作时,它每次都会这样做,然后再去其他地方,它确实会给我返回一个userName,一切都是200 OK。然后,当通过update时,它什么也不发送给我。我最后一次尝试的是将userName隔离为index操作中的实例变量,以便在update中获取它,如下所示:

代码语言:javascript
复制
# 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 in update似乎消失了,因为它的价值是nil

在生产环境中,我将从Azure Active和Okta中删除。在这两个平台上,映射都是可以的。准备工作就像一种魅力。

EN

回答 1

Stack Overflow用户

发布于 2020-11-05 19:28:03

有关修补程序/用户/{userId},请参阅https://developer.okta.com/docs/reference/scim/scim-20/#update-a-specific-user-patch。您能不能不使用url中的userId来识别用户?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64277101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档