Silverlight Claim-Based-Security Part-2
In part 1 I talked about a simple approach to combine WCF Routing service and claims-based security and I got some questions about the sample code and routing service configuration. In this post, I’ll explain some additional scenarios and would provide link to the source code. In my original post I used following very simple routing configuration where the RST (Request Security Token) message goes to the STS and everything else goes to the UserService (a business service)
Simple Routing Configuration
- <routing>
- <filterTables>
- <filterTable name="SLRouting">
- <add endpointName="stsEndpoint" filterName="matchRST" priority="5"/>
- <add endpointName="serviceEndpoint" filterName="allMessages" priority="1"/>
- </filterTable>
- </filterTables>
- <filters>
- <filter filterType="Action" filterData="https://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue" name="matchRST"/>
- <filter filterType="MatchAll" name="allMessages"/>
- </filters>
- </routing>
The STS endpoint uses an action filter (line 4) which looks for a WS-Trust RST message and forwards it to the STS. If RST filter doesn’t match, then the routing engine goes and tries the second filter (line 5) which is a match all. So in my simple configuration all non-RST messages are simply sent to the second endpoint. Real world scenarios obviously would require more granular routing but it can easily be enabled using the same pattern. WCF routing configuration is quite powerful and supports composite (AND, OR etc) and custom filters using which you can model any routing logic as you per your needs.
Another interesting scenarios is to support multiple authentication schemes on the STS – windows authentication for the intranet while userName password for the internet.
To enables this I have exposed the STS functionality using two different endpoints supporting both username/password based authentication as well as windows authentication.
/ActiveSTS/issue.svc/IWSTrust13/ActiveSTS/windowsintegrated/issue.svc/IWSTrust13
Because windows authentication is point-point so I relied on impersonation to flow the end-user identity to the STS via the Router. The windows authentication flow looks like this:
For the windows-integrated endpoint, router is configured to impersonate the client and the outgoing messages is sent under this impersonated context which enables the STS to authenticate the original user using windows authentication.
<serviceBehaviors> <behavior> <serviceAuthorization impersonateCallerForAllOperations="true"/> </behavior> </serviceBehaviors>
When deploying in IIS, both the router endpoint and the STS endpoint needs to be configured for windows-authentication and I have accomplished it by creating a sub-folder (windowsintegrated) under both virtual directories and configuring this for windows-authentication. The main/parent virtual directories still has anonymous access enabled for the userName authentication to work. Note with userName authentication, the credentials goes inside the SOAP message. My VS setup look like this:
The web.config(s) under the ‘windowsintegrated’ folder overrides the settings to enable windows-authentication. For example, in the STS project the root web.config defines both service endpoints along with a default binding which is configured for UserName authentication over HTTP.
Root web.config: STS
- <system.serviceModel>
- <serviceHostingEnvironment>
- <serviceActivations>
- <add relativeAddress="~/issue.svc" service="CustomSecurityTokenServiceConfiguration"
- factory="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory"/>
- <add relativeAddress="~/windowsintegrated/issue.svc" service="CustomSecurityTokenServiceConfiguration"
- factory="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceHostFactory"/>
- </serviceActivations>
- </serviceHostingEnvironment>
- <services>
- <service name="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract">
- <endpoint address="IWSTrust13"
- binding="customBinding"
- contract="Microsoft.IdentityModel.Protocols.WSTrust.IWSTrust13SyncContract"/>
- </service>
- </services>
- <bindings>
- <customBinding>
- <binding>
- <security authenticationMode="UserNameOverTransport" allowInsecureTransport="true"/>
- <httpTransport/>
- </binding>
- </customBinding>
- </bindings>
- </system.serviceModel>
The web.config in the ‘windowsintegrated’ changes the default binding to enable windows authentication. I’m using the ‘Simplified WCF Configuration’ here so the final config is very clean as a result.
Overriden default CustomBindin
- <system.serviceModel>
- <services/>
- <bindings>
- <customBinding>
- <binding>
- <httpTransport authenticationScheme="Negotiate"/>
- </binding>
- </customBinding>
- </bindings>
- </system.serviceModel>
Similar technique is used on the WebSite/Router where I pick different STS endpoint/binding depending on the chosen router endpoint. The root web.config goes to the anonymous STS endpoint (line 2 & 3) and authentication is done using the message credentials (userName).
Root web.config WebSite
- <client>
- <endpoint name="stsEndpoint" address="https://localhost/ActiveSTS/issue.svc/IWSTrust13"
- binding="customBinding" bindingConfiguration="outBinding" contract="*">
- </endpoint>
- <endpoint name="serviceEndpoint" address="https://localhost/UserService/Service1.svc"
- binding="customBinding" bindingConfiguration="outBinding" contract="*">
- </endpoint>
- </client>
Web.config in the ‘windowsintegrated’ changes the default STS endpoint/binding to match the windows authentication requirements and also enables impersonation to flow windows identity to the STS.
Router config for windows auth
<system.serviceModel>
<services/>
<client>
<remove name="stsEndpoint"/>
<endpoint name="stsEndpoint" address="https://localhost/ActiveSTS/windowsintegrated/issue.svc/IWSTrust13"
binding="customBinding" bindingConfiguration="outBinding" contract="*"/>
</client>
<bindings>
<customBinding>
<binding name="inBinding">
<httpsTransport authenticationScheme="Negotiate"/>
</binding>
<binding name="outBinding">
<httpTransport authenticationScheme="Negotiate"/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceAuthorization impersonateCallerForAllOperations="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Finally make sure to enable integrated windows authentication on the ‘windowsintegrated’ directory in IIS before you run the samples.
enjoy…
Download: Sample solution
Original post by Zulfiqar Ahmed on 23/03/11 here: https://zamd.net/2011/03/23/silverlight-claim-based-security-part-2/