private DynamicTableEntity ConvertToTargetRoleEntity(DynamicTableEntity sourceEntity, IdentityCloudContext sourcesContext) { DynamicTableEntity targetEntity = null; //RoleClaim record if (sourceEntity.PartitionKey.StartsWith(Constants.RowKeyConstants.PreFixIdentityRole) && sourceEntity.RowKey.StartsWith(Constants.RowKeyConstants.PreFixIdentityRoleClaim)) { sourceEntity.Properties.TryGetValue("ClaimType", out EntityProperty claimTypeProperty); string claimType = claimTypeProperty.StringValue; sourceEntity.Properties.TryGetValue("ClaimValue", out EntityProperty claimValueProperty); string claimValue = claimValueProperty.StringValue; string roleName = GetRoleNameBySourceId(sourceEntity.PartitionKey, sourcesContext); targetEntity = new DynamicTableEntity(KeyHelper.GenerateRowKeyIdentityRole(roleName), KeyHelper.GenerateRowKeyIdentityRoleClaim(claimType, claimValue), Constants.ETagWildcard, sourceEntity.Properties); targetEntity.Properties["KeyVersion"] = new EntityProperty(KeyHelper.KeyVersion); } else if (sourceEntity.RowKey.StartsWith(Constants.RowKeyConstants.PreFixIdentityRole)) { sourceEntity.Properties.TryGetValue("Name", out EntityProperty roleNameProperty); string roleName = roleNameProperty.StringValue; targetEntity = new DynamicTableEntity(KeyHelper.GeneratePartitionKeyIdentityRole(roleName), KeyHelper.GenerateRowKeyIdentityRole(roleName), Constants.ETagWildcard, sourceEntity.Properties); targetEntity.Properties["KeyVersion"] = new EntityProperty(KeyHelper.KeyVersion); } return(targetEntity); }
/// <summary> /// Generates Row and Id keys. /// Partition key is equal to the UserId /// </summary> public void GenerateKeys() { RowKey = PeekRowKey(); PartitionKey = KeyHelper.GeneratePartitionKeyIdentityRole(Name); KeyVersion = KeyHelper.KeyVersion; }