public void Save() { ManagementService serviceClient = ManagementServiceHelper.CreateManagementServiceClient(this.settings); ServiceIdentity serviceId = serviceClient.GetServiceIdentityByName(this.Name); if (serviceId == null) { serviceId = serviceClient.CreateServiceIdentity(this.Name, Encoding.UTF8.GetBytes(this.Password), ServiceIdentityKeyType.Password, ServiceIdentityKeyUsage.Password); ServiceIdentityKey key = new ServiceIdentityKey { EndDate = DateTime.MaxValue.AddDays(-1).ToUniversalTime(), StartDate = DateTime.UtcNow.ToUniversalTime(), Type = ServiceIdentityKeyType.Symmetric.ToString(), Usage = ServiceIdentityKeyUsage.Signing.ToString(), Value = this.Key, DisplayName = String.Format(CultureInfo.InvariantCulture, "Symmetric key for {0}", this.Name) }; serviceClient.AddRelatedObject(serviceId, "ServiceIdentityKeys", key); } else { if (serviceId.Description != this.Description) { serviceId.Description = this.Description; serviceClient.UpdateObject(serviceId); } serviceClient.UpdateServiceIdentityKey(this.Name, Encoding.UTF8.GetBytes(this.Password), ServiceIdentityKeyType.Password); serviceClient.UpdateServiceIdentityKey(this.Name, this.Key, ServiceIdentityKeyType.Symmetric); } serviceClient.SaveChanges(SaveChangesOptions.Batch); }
public static void ResetNamespace(Uri rpAddress, AccessControlSettings settings) { rpAddress = new UriBuilder(rpAddress) { Scheme = "http", Port = -1 }.Uri; var serviceClient = ManagementServiceHelper.CreateManagementServiceClient(settings); foreach (var g1 in from g in serviceClient.RuleGroups where g.Name.StartsWith(rpAddress.AbsoluteUri) select g) { serviceClient.DeleteRuleGroupByNameIfExists(g1.Name); } serviceClient.SaveChanges(); }
public static AccessControlList GetAccessControlList(Uri relyingPartyUri, AccessControlSettings settings) { var localPath = relyingPartyUri.LocalPath; relyingPartyUri = new UriBuilder(relyingPartyUri) { Scheme = "http", Port = -1, Path = localPath.Substring(0, localPath.EndsWith("/") ? localPath.Length - 1 : localPath.Length) }.Uri; var relyingPartyAddress = relyingPartyUri.AbsoluteUri; var serviceClient = ManagementServiceHelper.CreateManagementServiceClient(settings); var longestPrefixRpAddress = GetLongestPrefixRelyingPartyAddress(serviceClient, relyingPartyAddress); if (longestPrefixRpAddress != null) { var relyingParty = GetRelyingPartyByAddress(serviceClient, longestPrefixRpAddress); if (relyingParty != null) { return(new AccessControlList(relyingPartyUri, relyingParty, serviceClient)); } } throw new InvalidOperationException(); }
public void Delete() { ManagementService serviceClient = ManagementServiceHelper.CreateManagementServiceClient(this.settings); serviceClient.DeleteServiceIdentityIfExists(this.Name); }