public static void AddIdentity(this ManagementService svc, Credentials serviceIdentity, DateTime startDate, DateTime endDate) { Contract.Requires(svc != null); Contract.Requires(serviceIdentity != null); Contract.Requires(startDate != default(DateTime)); Contract.Requires(endDate > startDate); var sid = new ServiceIdentity() { Name = serviceIdentity.UserName }; var key = new ServiceIdentityKey() { StartDate = startDate, EndDate = endDate, Type = "Password", Usage = "Password", Value = Encoding.UTF8.GetBytes(serviceIdentity.Password), DisplayName = string.Format(CultureInfo.InvariantCulture, "{0} key for {1}", "Password", serviceIdentity.UserName) }; svc.AddToServiceIdentities(sid); svc.AddRelatedObject(sid, "ServiceIdentityKeys", key); svc.SaveChanges(SaveChangesOptions.Batch); }
public static RelyingParty AddRelyingParty(this ManagementService svc, Uri realm, string relyingPartyName, DateTime startDate, DateTime endDate, byte[] tokenSigningKey, int tokenLifetime) { Contract.Requires(svc != null); Contract.Requires(realm != null); Contract.Requires(realm.IsAbsoluteUri); Contract.Requires(realm.AbsolutePath == "/"); Contract.Requires(!string.IsNullOrWhiteSpace(relyingPartyName)); Contract.Requires(startDate != default(DateTime)); Contract.Requires(endDate > startDate); Contract.Requires(tokenSigningKey != null); Contract.Requires(tokenLifetime >= 1); var relyingParty = new RelyingParty() { Name = relyingPartyName, AsymmetricTokenEncryptionRequired = false, TokenType = "SWT", TokenLifetime = tokenLifetime }; svc.AddToRelyingParties(relyingParty); var relyingPartyAddress = new RelyingPartyAddress() { Address = realm.AbsoluteUri, EndpointType = "Realm" }; svc.AddRelatedObject(relyingParty, "RelyingPartyAddresses", relyingPartyAddress); var relyingPartyKey = new RelyingPartyKey() { StartDate = startDate, EndDate = endDate, Type = "Symmetric", Usage = "Signing", IsPrimary = true, Value = tokenSigningKey }; svc.AddRelatedObject(relyingParty, "RelyingPartyKeys", relyingPartyKey); svc.SaveChanges(SaveChangesOptions.Batch); return relyingParty; }
public static void AddRelatedConcrete(this DataServiceContextWrapper context, object instance, string propName, object relatedInstance) { typeof (BaseEntityType).GetProperty("Context", BindingFlags.Instance | BindingFlags.NonPublic) .SetValue(instance, context); context.AddRelatedObject(instance, propName, relatedInstance); }