程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

使用 shibboleth sso 授权

发布于2023-06-07 20:02     阅读(558)     评论(0)     点赞(18)     收藏(4)


我们已经将 shibboleth web sso 集成到我们的应用程序中以对用户进行身份验证,现在我们要为我们的应用程序进行授权。以下是我正在为 authz 考虑的过程。

  • 根据 shibboleth idp,未经身份验证的用户从 idp 重定向到 login.jsp
  • 用户输入用户名和密码后,该页面将转到我们的数据库并验证用户是否有效。如果他通过身份验证,我想在这里获得用户的权限。
  • 现在用户再次重定向到带有一些信息和权限的 idp,所以 idp 重定向到我们的服务提供商,我们无法控制用户的授权。在这里我开始知道我必须处理attribute-resolver.xml,现在我们在这个 xml 中使用 principle 和 transientId 。所以我知道我可以从 shibboleth idp 的 saml 响应中获取所需的信息(权限)。

所以请告诉我,如何处理 attribute-resolver.xml 以添加我们的授权权限。Imp 问题:使用 shibboleth 进行授权的更好流程是什么?

请查看我正在关注的以下流程......使用 idp 的身份验证流程,我们正在编写自己的 SP。1) 下面的 encodeSaml 请求将发送给 Idp,如下所示:

 public Pair<String,String>  getSAMLRequest(String spUrl, String consumerUrl) {
        AuthnRequest authnRequest = null;
        //String encodedSAMLRequest = null;
        Pair<String,String> encodedSAMLRequest = null;
        try {

            authnRequest = this.buildAuthnRequestObject(spUrl, consumerUrl);
            Encoder encoder = Encoder.getEncoder();
            encodedSAMLRequest = encoder.encodeAuthnRequest(authnRequest);
        } catch (MarshallingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return encodedSAMLRequest;
    }

private AuthnRequest buildAuthnRequestObject(String spUrl,
            String consumerUrl) {
        Issuer issuer = getIssuer();
        issuer.setValue(spUrl);

        DateTime issueInstant = new org.joda.time.DateTime();
        RequestedAuthnContext requestedAuthnContext = getRequestedAuthnContext();
        AuthnRequest authRequest = getAuthnRequest(issueInstant, issuer,
                consumerUrl, spUrl);

        authRequest.setRequestedAuthnContext(requestedAuthnContext);
        String systemTime = System.currentTimeMillis() + "";
        authRequest.setID("SSOIDSAMLREQ" +systemTime);              
        authRequest.setVersion(SAMLVersion.VERSION_20);
        authRequest.setAssertionConsumerServiceIndex(1);
        return authRequest;
    }

2)  First time idp redirects the user to login.jsp by using configuration which is in the handler.xml using externalAuth

 <ph:LoginHandler xsi:type="ph:ExternalAuthn"
                 externalAuthnPath="/external/login"
                 supportsForcedAuthentication="true" >
    <ph:AuthenticationMethod>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</ph:AuthenticationMethod>
</ph:LoginHandler>

--> 一旦进入上述路径,用户就可以看到 login.jsp,用户将输入凭据并提交给我们的服务器以验证用户。因此,我们将获得用户是否有效的布尔变量。

-> 一旦我们从服务器获得状态,我们就准备请求和响应,如下所示,将再次将其发送到 idp (AuthenticationEngine.returnToAuthenticationEngine(req,resp))。

request.setAttribute(globalStrings.getForceAuthn(), false);
                Principal principal = new UsernamePrincipal(login.getAttributes());
                Subject subj = new Subject();
                subj.getPrincipals().add(principal);
                request.setAttribute(LoginHandler.PRINCIPAL_KEY, principal);
                request.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY, personId);
                request.setAttribute(LoginHandler.SUBJECT_KEY, subj);
                request.setAttribute(globalStrings.getAuthnMethod(), this.authenticationMethod);
                AuthenticationEngine.returnToAuthenticationEngine(request, response);

3) We mention in the attribute-resolver and attribute-filter for the attributes to be released to the SP like below

<resolver:AttributeDefinition id="principal" xsi:type="PrincipalName" xmlns="urn:mace:shibboleth:2.0:resolver:ad">

   <resolver:AttributeEncoder xsi:type="enc:SAML2StringNameID" />

        <resolver:AttributeEncoder xsi:type="SAML2Base64" xmlns="urn:mace:shibboleth:2.0:attribute:encoder"
                                name="ORG_ATTRIBUTE_64" />
  <resolver:AttributeEncoder xsi:type="SAML2String" xmlns="urn:mace:shibboleth:2.0:attribute:encoder"
                                name="ORG_ATTRIBUTE" />
</resolver:AttributeDefinition> 

4) 所以会从SP(SAML response)中获取发布的所需属性并做进一步的处理(授权)。


解决方案


您是否拥有并运营 IdP?attribute-resolver.xml否则,当您的应用程序接收主体数据时,您无权访问并且必须在数据库中查找属性。

attribute-resolver.xml是 IdP 如何获取可能与多个应用程序相关的属性。即使不允许您的应用程序接收特定属性,也会解析所有属性。因此,如果您确实拥有 IdP,并且认为此属性相关,请务必将其加载到 IdP 中,并在您的应用程序收到来自 IdP 的 SAML 响应时将其读出。

这都是设计的问题,不同的设计对于不同的用例会更好。此外,权限数据越复杂,您的应用处理它的可能性就越大。



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/674314/76df5c7997d65baeba8f/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

18 0
收藏该文
已收藏

评论内容:(最多支持255个字符)