【发布时间】: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