簡體   English   中英

使用shibboleth sso進行授權

[英]Authorization using shibboleth sso

我們已經將shibboleth web sso集成到我們的應用程序中以對用戶進行身份驗證,現在,我們想為我們的應用程序進行授權。 以下是我正在為authz考慮的過程。

  • 根據shibboleth idp,未經身份驗證的用戶將從idp重定向到login.jsp
  • 用戶輸入用戶名和密碼后,頁面將轉到我們的數據庫並驗證用戶是否有效。 如果用戶通過身份驗證,我想在這里獲得用戶的權限。
  • 現在,用戶再次將一些信息以及權限重定向到idp,因此idp會使用該權限重定向到我們的服務提供商,我們無法控制用戶的授權。 在這里,我知道我必須處理attribute-resolver.xml ,現在我們在此xml中使用Principle和transientId。 所以我知道我可以從shibboleth idp的saml響應中獲取所需的信息(權限)。

因此,請告訴我,如何處理attribute-resolver.xml以添加我們的授權權限。 小問題: 使用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響應)獲取已發布的必需屬性,並進行進一步處理(授權)。

您是否擁有並運營IdP? 否則,您將無權訪問attribute-resolver.xml並且必須在應用程序接收主體數據時在數據庫中查找屬性。

attribute-resolver.xml是IdP如何獲取可能與多個應用程序相關的屬性。 即使不允許您的應用程序接收特定屬性,也將解析所有屬性。 因此,如果您確實擁有IdP,並且認為此屬性將是相關的,則應將其加載到IdP中,並在您的應用程序收到IdP的SAML響應時將其讀出。

這完全是設計問題,針對不同的用例,不同的設計會更好。 另外,權限數據越復雜,您的應用程序處理它的可能性就越大。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM