Exemplo n.º 1
0
        /// <summary>
        /// Creates a new token by contacting the STS
        /// </summary>
        /// <param name="channelFactory">
        ///   The channel factory.
        /// </param>
        /// <param name="identity">
        ///   The identity of the calling user
        /// </param>
        /// <typeparam name="T">
        /// The service contract
        /// </typeparam>
        /// <returns>
        /// A new security token
        /// </returns>
        protected virtual SecurityToken CreateNewSecurityToken <T>(ChannelFactory <T> channelFactory, IIdentity identity)
        {
            var serviceAddress = channelFactory.Endpoint.Address.Uri.AbsoluteUri;
            var serviceBinding = channelFactory.Endpoint.Binding as WS2007FederationHttpBinding;
            var claimsIdentity = identity as IClaimsIdentity;
            var bootstrapToken = claimsIdentity != null ? claimsIdentity.BootstrapToken : null;

            return(_securityTokenProvider.IssueToken(serviceBinding, serviceAddress, bootstrapToken));
        }
Exemplo n.º 2
0
        public void IssueToken_WS2007HttpBindingIsNotSet_Throws()
        {
            // Arrange
            var securityTokenProvider = new SecurityTokenProvider();
            var binding    = MockRepository.GenerateStub <WS2007FederationHttpBinding>();
            var actAsToken = MockRepository.GenerateStub <SecurityToken>();

            // Act
            // Assert
            var ex = Assert.Throws <ApplicationException>(() => securityTokenProvider.IssueToken(binding, "http://localhost/service", actAsToken));

            Assert.AreEqual("Unable to get WS2007HttpBinding", ex.Message);
        }
Exemplo n.º 3
0
        public void IssueToken_CalledOnContract_CallsChannelIssue()
        {
            // Arrange
            var securityTokenProvider = new SecurityTokenProvider();
            var channelContract       = MockRepository.GenerateMock <IWSTrustChannelContract>();
            var actAsToken            = MockRepository.GenerateStub <SecurityToken>();

            // Act
            securityTokenProvider.IssueToken(channelContract, "http://localhost/service", actAsToken);

            // Assert
            channelContract.AssertWasCalled(x => x.Issue(Arg <RequestSecurityToken> .Is.Anything, out Arg <RequestSecurityTokenResponse> .Out(null).Dummy));
        }