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(IKeyHelper keyHelper) { RowKey = PeekRowKey(keyHelper); PartitionKey = keyHelper.GeneratePartitionKeyIdentityRole(Name); KeyVersion = keyHelper.KeyVersion; }