Wednesday, March 30, 2016

WCF Impersonation from SP 2013 Claims

From my colleague Steve Stefanovich:

It looks like the issue is that the WCF services expect a Windows Identity but all SharePoint has is a Claims Identity so when it attempts to impersonate while calling WCF, it passes the default Windows Identity which is IUsr. The solution is not pretty but you can request a Windows Identity and then impersonate it while calling the service like this:

System.Security.Principal.WindowsIdentity ctx = null;

              Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
              {
                ctx = Microsoft.SharePoint.SPSecurityContext.GetWindowsIdentity();
              });

              using (ctx.Impersonate())
              {
                     //Call WCF Service here
              }

I’m going to try and clean this up some but at least this gives you the general idea. You do need to have the Claims to Windows Token Service setup properly for this to work.





Final follow-up, I promise. It looks like you can fix this using am End Point Behavior and Message Inspector which means less code to touch. Here’s the code for anyone interested. Just apply it to your endpoints either in the config file or in code like this: client.Endpoint.EndpointBehaviors.Add(new ClaimsContextIdentityBehavior());

I’m sure there are some fringe combinations of impersonation options I haven’t hit but it seems to solve the immediate issue we had of not being able to impersonate the logged in user in a call to the WCF service from a SP 2013 claims based web app. Also need to add error handling around the call to the C2WTS.

public class ClaimsContextIdentityBehavior : IClientMessageInspector, IEndpointBehavior
    {
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            WindowsImpersonationContext wic = correlationState as WindowsImpersonationContext;
            if (wic != null)
            {
                wic.Undo();
                wic.Dispose();
            }
        }

        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            System.Security.Principal.WindowsIdentity ctx = null;
            Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                ctx = Microsoft.SharePoint.SPSecurityContext.GetWindowsIdentity();
            });

            if (ctx != null)
            {
                return ctx.Impersonate();
            }
            else
            {
                return null;
            }
        }

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {

        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
          
            clientRuntime.MessageInspectors.Add(this);

        }


        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {


        }


        public void Validate(ServiceEndpoint endpoint)
        {

        }

    }

Tuesday, March 15, 2016

Define a workflow lookup

https://support.office.com/en-us/article/Define-a-workflow-lookup-D7FCC0DD-6E2D-4E10-BD07-F22627F5C2F3

Thursday, March 10, 2016

Tuesday, March 8, 2016

Monday, March 7, 2016

Understanding how to package and deploy workflow in SharePoint 2013

https://msdn.microsoft.com/en-us/library/office/jj819316.aspx

You cannot save a SharePoint 2010 list or site workflow as a template.

Sunday, March 6, 2016

Manage Office Data with SharePoint 2013

https://app.pluralsight.com/player?course=manage-office-data-sharepoint-2013&author=bill-kulterman&name=manage-office-data-sharepoint-2013-m1&clip=0&mode=live

Friday, March 4, 2016

Migrate SharePoint Designer Workflow from 2007 to 2013

http://blogs.technet.com/b/vinitt/archive/2013/04/21/migrate-workflow-from-sharepoint-2007-to-sharepoint-2013.aspx

Set up and manage access requests

https://support.office.com/en-us/article/Set-up-and-manage-access-requests-94b26e0b-2822-49d4-929a-8455698654b3

Thursday, March 3, 2016

Using InfoPath and the Web service GetUserProfileByName

http://thinketg.com/using-infopath-and-the-web-service-getuserprofilebyname/

User Profiles and User Information List Synchronization

http://www.sharepointchick.com/archive/2009/06/17/user-profiles-and-the-user-information-list-or-userinfo-table.aspx

Hidden users list in SharePoint

http://sharepointviews.com/hidden-users-list-in-sharepoint/

SharePoint's hidden user-list - User Information List

https://zimmergren.net/sharepoints-hidden-user-list-user-information-list/

Introduction: Control user access with permissions

https://support.office.com/en-US/article/Introduction-Control-user-access-with-permissions-ab2d1ab1-07cf-4c69-bdd9-390bfd787b26

Edit permissions for a list, library, or individual item

https://support.office.com/en-US/article/Edit-permissions-for-a-list-library-or-individual-item-02d770f3-59eb-4910-a608-5f84cc297782

Overview of site permissions in SharePoint 2013

https://technet.microsoft.com/en-us/library/jj219771.aspx

Permissions planning for sites and content in SharePoint 2013

https://technet.microsoft.com/en-us/library/cc262939.aspx