class Ddr::Auth::GrouperGateway
Constants
- DEFAULT_TIMEOUT
- SUBJECT_ID_RE
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/ddr/auth/grouper_gateway.rb, line 19 def initialize super Grouper::Rest::Client::Resource.new(ENV["GROUPER_URL"], user: ENV["GROUPER_USER"], password: ENV["GROUPER_PASSWORD"], timeout: ENV.fetch("GROUPER_TIMEOUT", DEFAULT_TIMEOUT).to_i) end
repository_groups(*args)
click to toggle source
# File lib/ddr/auth/grouper_gateway.rb, line 11 def self.repository_groups(*args) new.repository_groups(*args) end
user_groups(*args)
click to toggle source
# File lib/ddr/auth/grouper_gateway.rb, line 15 def self.user_groups(*args) new.user_groups(*args) end
Public Instance Methods
repository_groups(raw = false)
click to toggle source
List of all grouper groups for the repository
# File lib/ddr/auth/grouper_gateway.rb, line 27 def repository_groups(raw = false) repo_groups = groups(Ddr::Auth.repository_group_filter) if ok? return repo_groups if raw repo_groups.map do |g| Group.new(g["name"], label: g["displayExtension"]) end else [] end end
user_groups(user, raw = false)
click to toggle source
# File lib/ddr/auth/grouper_gateway.rb, line 39 def user_groups(user, raw = false) groups = [] subject_id = user.principal_name.scan(SUBJECT_ID_RE).first return groups unless subject_id begin request_body = { "WsRestGetGroupsRequest" => { "subjectLookups" => [{"subjectIdentifier" => subject_id}] } } # Have to use :call b/c grouper-rest-client :subjects method doesn't support POST response = call("subjects", :post, request_body) if ok? result = response["WsGetGroupsResults"]["results"].first # Have to manually filter results b/c Grouper WS version 1.5 does not support filter parameter if result && result["wsGroups"] groups = result["wsGroups"].select { |g| g["name"] =~ /^#{Ddr::Auth.repository_group_filter}/ } end end rescue StandardError => e # XXX Should we raise a custom exception? Rails.logger.error e end return groups if raw groups.map do |g| Group.new(g["name"], label: g["displayExtension"]) end end