WrappedSamlSecurityTokenAuthenticator.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. using System;
  5. using System.Collections.ObjectModel;
  6. using System.IdentityModel.Policy;
  7. using System.IdentityModel.Selectors;
  8. using System.IdentityModel.Tokens;
  9. using System.Security.Claims;
  10. namespace System.ServiceModel.Security
  11. {
  12. /// <summary>
  13. /// Authenticator that wraps both SAML 1.1 and SAML 2.0 WrapperSecurityTokenAuthenticators.
  14. /// </summary>
  15. internal class WrappedSamlSecurityTokenAuthenticator : SecurityTokenAuthenticator
  16. {
  17. WrappedSaml11SecurityTokenAuthenticator _wrappedSaml11SecurityTokenAuthenticator;
  18. WrappedSaml2SecurityTokenAuthenticator _wrappedSaml2SecurityTokenAuthenticator;
  19. public WrappedSamlSecurityTokenAuthenticator( WrappedSaml11SecurityTokenAuthenticator wrappedSaml11SecurityTokenAuthenticator, WrappedSaml2SecurityTokenAuthenticator wrappedSaml2SecurityTokenAuthenticator )
  20. {
  21. if ( wrappedSaml11SecurityTokenAuthenticator == null )
  22. {
  23. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "wrappedSaml11SecurityTokenAuthenticator" );
  24. }
  25. if ( wrappedSaml2SecurityTokenAuthenticator == null )
  26. {
  27. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "wrappedSaml2SecurityTokenAuthenticator" );
  28. }
  29. _wrappedSaml11SecurityTokenAuthenticator = wrappedSaml11SecurityTokenAuthenticator;
  30. _wrappedSaml2SecurityTokenAuthenticator = wrappedSaml2SecurityTokenAuthenticator;
  31. }
  32. protected override bool CanValidateTokenCore( SecurityToken token )
  33. {
  34. return ( _wrappedSaml11SecurityTokenAuthenticator.CanValidateToken( token ) || _wrappedSaml2SecurityTokenAuthenticator.CanValidateToken( token ) );
  35. }
  36. protected override ReadOnlyCollection<IAuthorizationPolicy> ValidateTokenCore( SecurityToken token )
  37. {
  38. if ( _wrappedSaml11SecurityTokenAuthenticator.CanValidateToken( token ) )
  39. {
  40. return _wrappedSaml11SecurityTokenAuthenticator.ValidateToken( token );
  41. }
  42. else if ( _wrappedSaml2SecurityTokenAuthenticator.CanValidateToken( token ) )
  43. {
  44. return _wrappedSaml2SecurityTokenAuthenticator.ValidateToken( token );
  45. }
  46. else
  47. {
  48. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ArgumentException( SR.GetString( SR.ID4101, token.GetType().ToString() ) ) );
  49. }
  50. }
  51. }
  52. }