发布于2023-06-07 20:02 阅读(508) 评论(0) 点赞(18) 收藏(4)
我们已经将 shibboleth web sso 集成到我们的应用程序中以对用户进行身份验证,现在我们要为我们的应用程序进行授权。以下是我正在为 authz 考虑的过程。
所以请告诉我,如何处理 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黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!