【问题标题】:SSO:How to get array of groups in redmine ominiauth SAML plugin from the SAML respone?SSO:如何从 SAML 响应中获取 redmine ominiauth SAML 插件中的组数组?
【发布时间】:2016-06-17 12:37:06
【问题描述】:

为 redmine 实施 SSO:Idp-OpenAM、SP-redmine(Ominiauth SAML 插件)

我想在 redmine_ominiauth_saml 插件中获取分配给用户的组列表,但我只能获得单个组,该组首先在组断言中的 SAML 响应中。

那么数组属性有什么不同的配置:

OpenAM 上 SP 的属性映射:

  • groups=isMemberOf
  • 姓氏=sn
  • 用户名=邮件
  • first_name=givenName
  • 电子邮件=邮件

Redmine 上的属性映射: "/opt/redmine/config/initializers/saml_3.0.rb"

:attribute_mapping              => {
    # How will we map attributes from SSO to redmine attribute
      :login      => 'extra.raw_info.username',
      :firstname  => 'extra.raw_info.first_name',
      :lastname   => 'extra.raw_info.last_name',
      :mail       => 'extra.raw_info.email',
      :isMemberOf => 'extra.raw_info.groups'
    }

SAML 响应包含数组中的属性组,如下所示:

<saml:AttributeStatement>
                        <saml:Attribute Name="first_name">
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >umesh</saml:AttributeValue>
                        </saml:Attribute>
                        <saml:Attribute Name="username">
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >ubr@abc.com</saml:AttributeValue>
                        </saml:Attribute>
                        <saml:Attribute Name="email">
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >ubr@abc.com</saml:AttributeValue>
                        </saml:Attribute>
                        <saml:Attribute Name="last_name">
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >rajani</saml:AttributeValue>
                        </saml:Attribute>
                        <saml:Attribute Name="groups">
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >cn=ABC,ou=groups,dc=abc,dc=opendj,dc=com</saml:AttributeValue>
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >cn=XYZ,ou=groups,dc=abc,dc=opendj,dc=com</saml:AttributeValue>
                                <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                     xsi:type="xs:string"
                                                     >cn=YZQ,ou=groups,dc=abc,dc=opendj,dc=com</saml:AttributeValue>
                        </saml:Attribute>
                </saml:AttributeStatement>

我知道 SAML 插件中的这段代码给了我一个组(ruby 中的代码): /opt/redmine/plugins/redmine_omniauth_saml/lib/redmine_omniauth_saml.rb

def user_attributes_from_saml(omniauth)

         HashWithIndifferentAccess.new.tap do |h|
          required_attribute_mapping.each do |symbol|
            key = configured_saml[:attribute_mapping][symbol]
              h[symbol] = key.split('.')                # Get an array with nested keys: name.first will return [name, first]
              .map {|x| [:[], x]}                     # Create pair elements being :[] symbol and the key
              .inject(omniauth) do |hash, params|     # For each key, apply method :[] with key as parameter
                hash.send(*params)
              end
             **print "key:value "+key+":" +h[symbol]**  # gives key value pair, first_name, group 'ABC' only leaves other group
          end
        end
      end

【问题讨论】:

    标签: single-sign-on saml openam redmine-plugins


    【解决方案1】:

    其实 ruby​​-saml 插件默认是作为单个值返回的属性。

    我们需要在 ruby​​-saml 插件中设置多值。

    ruby-saml 插件有 attributes.rb 文件。

    更新@@single_value_compatibility 的值并设置为“false”

    现在您将获得完整的价值。

    希望您的问题得到解决。

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2017-07-27
      • 2018-07-17
      • 2021-02-15
      相关资源
      最近更新 更多