代码之家  ›  专栏  ›  技术社区  ›  Dokie

日内瓦框架中RP-STS的简单索赔转换

  •  3
  • Dokie  · 技术社区  · 17 年前

    在阅读了msdn文章之后( http://msdn.microsoft.com/en-us/magazine/2009.01.genevests.aspx )关于使用Microsoft Geneva框架实现自定义STS,我对其中一个场景有点困惑。这个场景如上述文章的图13所示。

    我的问题是,为了传递已经从IP-STS获得的索赔,RP如何发起对RP-STS的呼叫?如何将所需的方法deleteOrder()转换为RP-STS对操作声明的声明请求,RP-STS用值delete响应操作声明,值delete授权调用?我还认为这个数字有点不正确,因为RP-STS和策略引擎之间的交互应该有相反的声明和箭头。

    我可以看到这个结构,但不清楚Geneva/WCF提供了什么,以及在RP中必须在代码中做什么,这看起来有点奇怪,因为我们不能用删除“权限”的原则许可请求来保护DeleteOrder方法,但必须先要求角色,然后获得删除AC的细粒度声明。在那之后。

    如果我漏掉了这一点(因为我在网上找不到这件案子),那就道歉吧!

    事先谢谢。

    2 回复  |  直到 15 年前
        1
  •  1
  •   Dokie    17 年前

    我在日内瓦论坛上也问了同样的问题 http://social.msdn.microsoft.com/Forums/en/Geneva/thread/d10c556c-1ec5-409d-8c25-bee2933e85ea?prof=required 得到回复:

    嗨,多基,

    当我读到那篇文章时,我也在想同样的事情。在我思考如何实现这样一个场景时,我提出了两个想法:

    1. RP实际上被配置为需要来自RP-STS的声明;RP-STS需要来自IP-STS的安全令牌。因此,当受试者请求RP资源时,它会将他反弹到RP-STS,后者会将他反弹到IP-STS。在那里进行身份验证之后,他将被退回RP-STS,以身份为中心的声明将被转换为作出授权决策所必需的声明,并返回RP。

    2. RP被配置为有一个拦截器(例如,如果它是一个WCF服务,则有一个authorizationpolicy)来捕获调用,查看以身份为中心的声明,创建一个RST(使用wstrustclient),将其传递给RP-STS,该服务将声明扩展为返回到RP的新声明,并且RP做出授权决定。

    我从来没有实现过这一点,但是,如果我要实现这一点,我会进一步探讨这两个想法。

    嗯!


    当做,

    特拉维斯斯宾塞

    所以我将首先尝试选项2,看看是否可行,然后在这里制定一个答案。

        2
  •  0
  •   Max    15 年前

    我的第一种情况很好。 在我的例子中,ad fs是身份服务,而自定义sts是资源sts。

    所有webapp都使用相同的资源sts,但是在用户访问其他应用程序之后,与身份相关的声明不会被ad fs再次添加,因为用户已经过身份验证。我如何才能再次强制或请求AD FS的基本声明?

    我用actas创建了一个对ad fs的调用,现在它返回我的身份声明。 请记住,为用于调用AD FS的凭据启用允许委派的规则。

    string stsEndpoint = "https://<ADFS>/adfs/services/trust/2005/usernamemixed";
         var trustChannelFactory = new WSTrustChannelFactory(new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), stsEndpoint);
    
         trustChannelFactory.Credentials.UserName.UserName = @"DELEGATE";
         trustChannelFactory.Credentials.UserName.Password = @"PASSWORD";
    
         trustChannelFactory.TrustVersion = TrustVersion.WSTrustFeb2005;
    
         //// Prepare the RST.
         //var trustChannelFactory = new WSTrustChannelFactory(tokenParameters.IssuerBinding, tokenParameters.IssuerAddress);
         var trustChannel = (WSTrustChannel)trustChannelFactory.CreateChannel();
    
         var rst = new RequestSecurityToken(RequestTypes.Issue);
    
         rst.AppliesTo = new EndpointAddress(@"https:<RPADDRESS>");
    
         // If you're doing delegation, set the ActAs value.
         var principal = Thread.CurrentPrincipal as IClaimsPrincipal;
         var bootstrapToken = principal.Identities[0].BootstrapToken;
    
         // The bootstraptoken is the token received from the AD FS after succesfull authentication, this can be reused to call the AD FS the the users credentials
         if (bootstrapToken == null)
         {
            throw new Exception("Bootstraptoken is empty, make sure SaveBootstrapTokens = true at the RP");
         }
    
         rst.ActAs = new SecurityTokenElement(bootstrapToken);
    
         // Beware, this mode make's sure that there is no certficiate needed for the RP -> AD FS communication
         rst.KeyType = KeyTypes.Bearer;
    
         // Disable the need for AD FS to crypt the data to R-STS
         Scope.SymmetricKeyEncryptionRequired = false;
    
         // Here's where you can look up claims requirements dynamically.
         rst.Claims.Add(new RequestClaim(ClaimTypes.Name));
         rst.Claims.Add(new RequestClaim(ClaimTypes.PrimarySid));
    
         // Get the token and attach it to the channel before making a request.
         RequestSecurityTokenResponse rstr = null;
         var issuedToken = trustChannel.Issue(rst, out rstr);
         var claims = GetClaimsFromToken((GenericXmlSecurityToken)issuedToken);
    
     private static ClaimCollection GetClaimsFromToken(GenericXmlSecurityToken genericToken)
      {
         var handlers = FederatedAuthentication.ServiceConfiguration.SecurityTokenHandlers;
         var token = handlers.ReadToken(new XmlTextReader(new StringReader(genericToken.TokenXml.OuterXml)));
         return handlers.ValidateToken(token).First().Claims;
      }
    
    推荐文章