简体   繁体   English

如何使用 keycloak-saml 适配器将第三方 IdP SAML 属性映射到我的本地应用程序角色

[英]How to map third party IdP SAML attributes to my local application roles using keycloak-saml adapter

My setup is:我的设置是:

  • EAP 6.4.18 EAP 6.4.18
  • keycloak-saml adapter keycloak-saml 适配器
  • Third party IdP server (not a keycloak server)第三方 IdP 服务器(不是 keycloak 服务器)

I'm trying to secure one of the web applications inside an EAR.我正在尝试保护 EAR 中的 Web 应用程序之一。 Currently my standalone.xml looks like this:目前我的 standalone.xml 看起来像这样:

<subsystem xmlns="urn:jboss:domain:keycloak-saml:1.3">
    <secure-deployment name="myapp.war">
        <SP entityID="https://mydomain/myapp/" sslPolicy="EXTERNAL" nameIDPolicyFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" logoutPage="/logout.jsp" forceAuthentication="false" isPassive="false" turnOffChangeSessionIdOnLogin="false">
            <Keys>
                <Key signing="true" encryption="false">
                    <KeyStore password="pass" file="/path-to/keyStore.jks">
                        <PrivateKey alias="sp" password="pass"/>
                        <Certificate alias="sp"/>
                    </KeyStore>
                </Key>
            </Keys>
            <IDP entityID="...entityID...">
                <SingleSignOnService signRequest="true" validateResponseSignature="true" requestBinding="POST" bindingUrl="...sso dinding..." assertionConsumerServiceUrl="https://mydomain/myapp/saml"/>
                <SingleLogoutService validateRequestSignature="true" validateResponseSignature="true" signRequest="true" signResponse="true" requestBinding="POST" responseBinding="POST" postBindingUrl="...slo binding..." redirectBindingUrl="...redirect..."/>
                <Keys>
                    <Key signing="true" encryption="false">
                        <KeyStore password="pass" file="/path-to/keyStore.jks">
                            <Certificate alias="idp"/>
                        </KeyStore>
                    </Key>
                </Keys>
            </IDP>
        </SP>
    </secure-deployment>
</subsystem>

This part works just fine.这部分工作得很好。 I'm getting redirected to the IdP and I can login.我被重定向到 IdP,我可以登录。 The problem is that my application roles and the ones returned by the IdP do not match.问题是我的应用程序角色和 IdP 返回的角色不匹配。

How can I configure a role mapping between those 2 so that the user has the correct roles in the session?如何在这两个角色之间配置角色映射,以便用户在会话中拥有正确的角色?

Ty.泰。

Note:笔记:

I've done something like this with the picketlink subsystem.我已经用 picketlink 子系统做过类似的事情。 Below I used a properties file to do such mapping.下面我使用一个属性文件来做这样的映射。 I thought something similar could be done with the keycloak adapter, but the "keycloak-saml:1.1" schema doesn't seem to have a way to select a security-domain.我认为可以使用 keycloak 适配器完成类似的操作,但是“keycloak-saml:1.1”模式似乎没有办法选择安全域。

<security-domain name="my-realm">
<authentication>
    <login-module code="org.picketlink.identity.federation.bindings.jboss.auth.SAML2LoginModule" flag="optional">
        <module-option name="password-stacking" value="useFirstPass"/>
    </login-module>
    <login-module code="org.jboss.security.auth.spi.RoleMappingLoginModule" flag="optional">
        <module-option name="password-stacking" value="useFirstPass"/>
        <module-option name="rolesProperties" value="${jboss.server.config.dir}/rolesMapping-roles.properties"/>
        <module-option name="replaceRole" value="true"/>
    </login-module>
</authentication>

With the picketlink subsystem I could select my security domain and the roles mapping would happen.使用 picketlink 子系统,我可以选择我的安全域,然后角色映射就会发生。

<service-provider name="myapp.war" security-domain="my-realm"...

This is the configuration I was missing:这是我缺少的配置:

​<RoleMappingsProvider id="properties-based-role-mapper">
       ​<Property name="properties.file.location" value="/opt/mappers/roles.properties"/>
​</RoleMappingsProvider>

The implementation class of "properties-based-role-mapper" is: org.keycloak.adapters.saml.PropertiesBasedRoleMapper “properties-based-role-mapper”的实现类为:org.keycloak.adapters.saml.PropertiesBasedRoleMapper

More information here: https://www.keycloak.org/docs/latest/securing_apps/#_saml-general-config更多信息在这里: https : //www.keycloak.org/docs/latest/securing_apps/#_saml-general-config

The problem was that I was looking at schema version 1.1 which doesn't provide that option.问题是我正在查看不提供该选项的架构版本 1.1。 The version 1.3 does, works perfectly. 1.3 版可以,完美运行。

I hope this question/answer helps someone out there.我希望这个问题/答案可以帮助那里的人。

Cheers.干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM