public MasterDataClient(string serviceName, BootstrapContext token = null) { Tracer = TracerFactory.StartTracer(this, "ctor"); var runtime = RuntimeFactory.CreateRuntime(); Container = runtime.CreateServiceProxy<IMasterDataManagementService>(serviceName); if (token.IsInstance()) Container.Initialize(token); }
public void Ctor_StringToken_Works () { BootstrapContext bootstrapContext = new BootstrapContext ("token"); Assert.AreEqual ("token", bootstrapContext.Token, "#1"); Assert.IsNull (bootstrapContext.TokenBytes, "#2"); Assert.IsNull (bootstrapContext.SecurityToken, "#3"); Assert.IsNull (bootstrapContext.SecurityTokenHandler, "#4"); }
private static string GetTokenAsXml(BootstrapContext bootstrapContext) { var builder = new StringBuilder(); using (var writer = XmlWriter.Create(builder)) { new Saml2SecurityTokenHandler(new SamlSecurityTokenRequirement()).WriteToken(writer, bootstrapContext.SecurityToken); } return builder.ToString(); }
public void Ctor_ByteArrayToken_Works () { BootstrapContext bootstrapContext = new BootstrapContext (new byte [] { 0x01 }); Assert.IsNotNull (bootstrapContext.TokenBytes, "#1"); Assert.AreEqual (1, bootstrapContext.TokenBytes.Length, "#2"); Assert.AreEqual (1, bootstrapContext.TokenBytes [0], "#3"); Assert.IsNull (bootstrapContext.Token, "#4"); Assert.IsNull (bootstrapContext.SecurityToken, "#5"); Assert.IsNull (bootstrapContext.SecurityTokenHandler, "#6"); }
public void Serialize_StringToken_Works () { BootstrapContext bootstrapContext = new BootstrapContext ("token"); BinaryFormatter binaryFormatter = new BinaryFormatter (); using (var s = new MemoryStream ()) { binaryFormatter.Serialize (s, bootstrapContext); s.Position = 0; BootstrapContext bootstrapContext2 = binaryFormatter.Deserialize (s) as BootstrapContext; Assert.IsNotNull (bootstrapContext2, "#1"); Assert.AreEqual (bootstrapContext.Token, bootstrapContext2.Token, "#2"); Assert.AreEqual (bootstrapContext.TokenBytes, bootstrapContext2.TokenBytes, "#3"); Assert.AreEqual (bootstrapContext.SecurityToken, bootstrapContext2.SecurityToken, "#4"); Assert.AreEqual (bootstrapContext.SecurityTokenHandler, bootstrapContext2.SecurityTokenHandler, "#5"); } }
public static void SetBootstrapToken(BootstrapContext bootstrapToken) { if (bootstrapToken.IsNull()) return; ContainerFactory.Current.Bind(typeof(BootstrapContext), bootstrapToken, Scope.Context); }
private SecurityToken GetActAsToken(BootstrapContext context) { string stsAddress = "https://identity.thinktecture.com/idsrvsample/issue/wstrust/mixed/username"; string realm = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration.Realm; var factory = new WSTrustChannelFactory( new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), new EndpointAddress(stsAddress)); factory.TrustVersion = TrustVersion.WSTrust13; factory.Credentials.UserName.UserName = "******"; factory.Credentials.UserName.Password = "******"; var rst = new RequestSecurityToken { AppliesTo = new EndpointReference(realm), RequestType = RequestTypes.Issue, KeyType = KeyTypes.Bearer, ActAs = new SecurityTokenElement(context.SecurityToken) }; var channel = factory.CreateChannel(); var delegationToken = channel.Issue(rst); return delegationToken; }
public void Ctor_ByteArrayToken_NullToken_Throws () { BootstrapContext bootstrapContext = new BootstrapContext ((byte [])null); Assert.Fail ("Should have thrown"); }
public void Ctor_StringToken_NullToken_Throws () { BootstrapContext bootstrapContext = new BootstrapContext ((string)null); Assert.Fail ("Should have thrown"); }
public void Serialize_SecurityTokenAndHandler_Works () { var securityToken = new UserNameSecurityToken (user, password, "uuid-927c0b98-ba18-49d2-a653-306d60f85751-3"); var securityTokenHandler = new SimpleSecurityTokenHandler (); BootstrapContext bootstrapContext = new BootstrapContext (securityToken, securityTokenHandler); BinaryFormatter binaryFormatter = new BinaryFormatter (); using (var s = new MemoryStream ()) { binaryFormatter.Serialize (s, bootstrapContext); s.Position = 0; BootstrapContext bootstrapContext2 = binaryFormatter.Deserialize (s) as BootstrapContext; Assert.IsNotNull (bootstrapContext2, "#1"); // Deserialize does not restore the SecurityToken, but restores into the Token. Assert.IsNotNull (bootstrapContext2.Token, "#3"); // We replace ' /' by '/' to accomodate the xml writer differences between mono and .net Assert.AreEqual (SerializedBootstrapContextSecurityTokenString.Replace (" /", "/"), bootstrapContext2.Token.Replace (" /", "/"), "#2"); Assert.AreEqual (bootstrapContext.TokenBytes, bootstrapContext2.TokenBytes, "#3"); Assert.IsNull (bootstrapContext2.SecurityToken, "#4"); Assert.IsNull (bootstrapContext2.SecurityTokenHandler, "#5"); } }
public void Ctor_SecurityToken_NullHandler_Throws () { BootstrapContext bootstrapContext = new BootstrapContext (new UserNameSecurityToken ("user", "password"), null); Assert.Fail ("Should have thrown"); }
public void Ctor_SecurityToken_NullToken_Throws () { BootstrapContext bootstrapContext = new BootstrapContext (null, new SimpleSecurityTokenHandler ()); Assert.Fail ("Should have thrown"); }
public void Ctor_SecurityToken_Works () { var securityToken = new UserNameSecurityToken (user, password); var securityTokenHandler = new SimpleSecurityTokenHandler (); BootstrapContext bootstrapContext = new BootstrapContext (securityToken, securityTokenHandler); Assert.IsNotNull (bootstrapContext.SecurityToken, "#1"); Assert.AreEqual (user, securityToken.UserName, "#2"); Assert.AreEqual (password, securityToken.Password, "#3"); Assert.AreEqual (securityTokenHandler, bootstrapContext.SecurityTokenHandler, "#4"); Assert.IsNull (bootstrapContext.Token, "#5"); Assert.IsNull (bootstrapContext.TokenBytes, "#6"); }
/// <summary> /// Persists the WIF <see cref="BootstrapContext" /> to the store /// </summary> /// <param name="Runtime"> /// the current <see cref="IRuntime"/> instance /// </param> /// <param name="context"> /// the <see cref="BootstrapContext"/> to persist /// </param> public static void SetBootstrapContext(this IRuntime runtime, BootstrapContext context) { runtime.GetStateStorageContainer().TryAddStorageItem(context); }
/// <summary> /// Validates the token using the wrapped token handler and generates IAuthorizationPolicy /// wrapping the returned ClaimsIdentities. /// </summary> /// <param name="token">Token to be validated.</param> /// <returns>Read-only collection of IAuthorizationPolicy</returns> protected override ReadOnlyCollection<IAuthorizationPolicy> ValidateTokenCore( SecurityToken token ) { ReadOnlyCollection<ClaimsIdentity> identities = null; try { identities = _wrappedX509SecurityTokenHandler.ValidateToken(token); } catch ( Exception ex ) { if ( !_exceptionMapper.HandleSecurityTokenProcessingException( ex ) ) { throw; } } // tlsnego will dispose of the x509, when we write out the bootstrap we will get a dispose error. bool shouldSaveBootstrapContext = SecurityTokenHandlerConfiguration.DefaultSaveBootstrapContext; if ( _wrappedX509SecurityTokenHandler.Configuration != null ) { shouldSaveBootstrapContext = _wrappedX509SecurityTokenHandler.Configuration.SaveBootstrapContext; } if ( shouldSaveBootstrapContext ) { X509SecurityToken x509Token = token as X509SecurityToken; SecurityToken tokenToCache; if ( x509Token != null ) { tokenToCache = new X509SecurityToken( x509Token.Certificate ); } else { tokenToCache = token; } BootstrapContext bootstrapContext = new BootstrapContext(tokenToCache, _wrappedX509SecurityTokenHandler); foreach (ClaimsIdentity identity in identities) { identity.BootstrapContext = bootstrapContext; } } List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy>(1); policies.Add(new AuthorizationPolicy(identities)); return policies.AsReadOnly(); }