Revendications et Web Services avec SharePoint 2010 - Claims and Web Services with SharePoint 2010 BCS

 
Français English
Ce billet montre l’appel d’un service Web utilisant une authentification à base de revendications via SharePoint 2010 BCS. Le web service est appelé par l’utilisation d’une liste externe. Le service web peut afficher dans ses traces les revendications qu’il reçoit. J’ai expliqué il y a un certain temps comment utiliser un service web en tant que source de données pour une liste externe. J’ai réutilisé le même principe avec quelques améliorations:
  • Le navigateur, SharePoint et le service Web sont sur différentes machines de façon à pouvoir vérifier le fonctionnement avec double hop (délégation vs impersonation).
  • On utilise la fédération d’identité (l’installation est faite sur la plateforme IDMGT du MTC Paris)

De façon à installer le service Web, je me suis inspiré d’un groupe de 4 pages de la librairie MSDN: WCF: Building WCF Web Services for SharePoint 2010 Business Connectivity Services

Le rôle des machines est le suivant pour ce scénario:

idmgt-sps Hôte SharePoint
idmgt-owa Hôte du service Web (IIS/WCF)
idmgt-win7 Machine cliente
idmgt-* Les autres machines gardent leur rôle habituel dans la plateforme IDMGT: ADFS, authentification Shibboleth, …
Sur le serveur de service Web (IDMGT-OWA), on a l’outil DebugView installé de façon à pouvoir voir les traces générées par l’exécution du service Web.

Le service Web a le code suivant, qui utilise Windows Identity Foundation (WIF), de façon à afficher les revendications contenues dans le jeton SAML qu’il a reçu:

This blog post is about calling a Web Service with claims based authentication thru SharePoint 2010 BCS. The web service is called by using an external list. The Web Service can show in its traces the claims it receives.

I explained a while ago how to have SharePoint using a Web Service as a datasource for an external list. I reused the same principle with a few enhancements:

  • The browser, SharePoint and the Web Service are on three different machines so that double hop issues can be checked (delegation vs impersonation).
  • federated identity is used (I installed it on the IDMGT platform in MTC Paris)

 

In order to install the Web Service, I leveraged a group of 4 MSDN library pages: WCF: Building WCF Web Services for SharePoint 2010 Business Connectivity Services

The role of the machines is the following for this scenario:

idmgt-sps SharePoint host
idmgt-owa Web service host (IIS/WCF)
idmgt-win7 Client machine
idmgt-* other machines are used for their usual roles in the IDMGT platform: ADFS, Shibboleth authentication, …
On the Web Service server (IDMGT-OWA), we have the DebugView tool installed in order to see the traces issued by Web Service execution. The web service has the following code, that uses Windows Identity Foundation (WIF), in order to display the claims included in the SAML token it received:
         public Customer[] GetAllCustomers()
        {
            Who();
            var customers = (from entry in _customers select entry.Value).ToArray();
            Trace.WriteLine(string.Format("GetAllCustomers will return {0} customers", customers.Length));
            return customers;
        }

         public Customer UpdateCustomer(Customer customer)
        {
            Who();
            Customer c;
            lock (_customers)
            {
                c = _customers[customer.Id];
                if (c == null) throw new ArgumentOutOfRangeException();

                c.FirstName = customer.FirstName;
                c.LastName = customer.LastName;
                c.FirstContractDate = customer.FirstContractDate;
                c.NbOfActiveContracts = customer.NbOfActiveContracts;
            }

            Trace.WriteLine(string.Format("UpdateCustomer updated customer {0}", c));
            return c;
        }
etc.
        private void Who()
        {
            IPrincipal user = Thread.CurrentPrincipal;
            if (user == null)
            {
                Trace.WriteLine(string.Format("current principal is null"));
            }
            else
            {
                Trace.WriteLine(string.Format("current user is of type {0}", user.GetType().Name));
                IIdentity userIdentity = user.Identity;
                if (userIdentity == null)
                {
                    Trace.WriteLine(string.Format("current user's identity is null"));
                }
                else
                {
                    Trace.WriteLine(string.Format("user's identity: {0} ({1}, {2})", userIdentity.Name, userIdentity.IsAuthenticated, userIdentity.AuthenticationType));
                }

                if (user is IClaimsPrincipal)
                {
                    Trace.WriteLine(string.Format("user is a Claims user"));
                    IClaimsPrincipal claimsUser = (IClaimsPrincipal)user;
                    IClaimsIdentity claimsUserIdentity = (IClaimsIdentity)user.Identity;

                    foreach (var c in claimsUserIdentity.Claims)
                    {
                        Trace.WriteLine(string.Format("claim {0}={1}", c.ClaimType, c.Value));
                    }
                }
            }
Voyons maintenant ce que cela donne. Authentifions-nous avec Shibboleth sur la plateforme Windows: Let’s check some test results now. Let’s authenticate thru Shibboleth on the Windows platform:
  

image

image

image

image

image

image

image

Le service Web pourrait donc changer son comportement en fonction des revendications qu’il reçoit (au lieu de simplement tracer les noms et valeurs des revendications). Cela montre aussi qu’il n’y a pas de problème de double hop: l’utilisateur a été authentifié depuis le navigateur sur idmgt-win7 auprès du serveur SharePoint et son identité a été passée via les revendications au serveur idmgt-owa. Voyons un autre exemple avec Yahoo! So the web service could change its behavior based on the claims it receives (instead of just tracing the claims names and values). This also shows that there is no double hop issue: the user was authenticated from idmgt-win7’s browser to idmgt-sps SharePoint server and his identity was then passed thru claims to the idmgt-owa server. Let’s see another example with Yahoo!

image

image

image

image

image

image

Smile

Benjamin