Exemple #1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            IResourceIdentifier otherIdentifier = obj as IResourceIdentifier;

            if (null == otherIdentifier)
            {
                return(false);
            }

            if (!string.Equals(this.SchemaIdentifier, otherIdentifier.SchemaIdentifier, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!string.Equals(this.Identifier, otherIdentifier.Identifier, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public virtual async Task Update(
            HttpRequestMessage request,
            string identifier,
            PatchRequestBase patchRequest,
            string correlationIdentifier)
        {
            if (null == request)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(nameof(correlationIdentifier));
            }

            IResourceIdentifier resourceIdentifier = this.CreateResourceIdentifier(identifier);
            IPatch patch =
                new Patch
            {
                ResourceIdentifier = resourceIdentifier,
                PatchRequest       = patchRequest
            };
            IReadOnlyCollection <IExtension> extensions = this.ReadExtensions();
            IRequest <IPatch> updateRequest             = new UpdateRequest(request, patch, correlationIdentifier, extensions);

            await this.Provider.UpdateAsync(updateRequest).ConfigureAwait(false);
        }
        public override async Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (null == resourceIdentifier)
            {
                throw new ArgumentNullException(nameof(resourceIdentifier));
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(nameof(correlationIdentifier));
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.Identifier))
            {
                throw new ArgumentException(FileProviderResources.ExceptionInvalidResource);
            }

            IInformationNotification notification =
                VerboseInformationNotificationFactory.Instance.FormatNotification(
                    FileProviderResources.InformationDeleting,
                    correlationIdentifier,
                    FileProvider.NotificationIdentifierDeletionStarting,
                    resourceIdentifier.SchemaIdentifier,
                    resourceIdentifier.Identifier);

            this.Monitor.Inform(notification);

            await this.file.RemoveRow(resourceIdentifier.Identifier);
        }
 private void WriteResourceIdentifier(IResourceIdentifier resourceIdentifier, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("type");
     writer.WriteValue(resourceIdentifier.Type);
     writer.WritePropertyName("id");
     writer.WriteValue(resourceIdentifier.Id);
     writer.WriteEndObject();
 }
Exemple #5
0
        public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (resourceIdentifier.SchemaIdentifier.Equals(SchemaIdentifiers.Core2EnterpriseUser))
            {
                return(this.userProvider.DeleteAsync(resourceIdentifier, correlationIdentifier));
            }

            throw new  NotImplementedException();
        }
Exemple #6
0
 private void WriteResourceIdentifier(IResourceIdentifier resourceIdentifier, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("type");
     writer.WriteValue(resourceIdentifier.Type);
     writer.WritePropertyName("id");
     writer.WriteValue(resourceIdentifier.Id);
     writer.WriteEndObject();
 }
        public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (null == resourceIdentifier)
            {
                throw new ArgumentNullException(nameof(resourceIdentifier));
            }

            Task result = Task.WhenAll();

            return(result);
        }
        public override async Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            string identifier = resourceIdentifier.Identifier;

            if (int.TryParse(identifier, out int id) && _context.Users.Find(id) is MvcMovie.Models.User deleteUser)
            {
                _context.Users.Remove(deleteUser);
                await _context.SaveChangesAsync();
            }
        }
        public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            string identifier = resourceIdentifier.Identifier;

            if (this.storage.Groups.ContainsKey(identifier))
            {
                this.storage.Groups.Remove(identifier);
            }

            return(Task.CompletedTask);
        }
Exemple #10
0
        public object CreateResourceModel(IResourceIdentifier resource)
        {
            if (resource == null)
            {
                return(null);
            }

            var type = ModelRegistry.GetModelType(resource.Type);

            Log.Debug(() => $"activating session-managed instance of {type.FullName}:{{{resource.Id}}}");
            var model      = Activator.CreateInstance(type);
            var initialize = type.GetInitializeMethod();

            initialize.Invoke(model, new object[] { resource, this });
            return(model);
        }
Exemple #11
0
        public override async Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            string identifier = resourceIdentifier.Identifier;

            Core2EnterpriseUser user = await this.context.Users.Where(u => u.Identifier == identifier).FirstOrDefaultAsync();

            if (user == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            this.context.Users.Remove(user);
            await this.context.SaveChangesAsync();
        }
        private static bool HasMember(IResourceIdentifier containerIdentifier, string memberAttributePath, string memberIdentifier)
        {
            if (null == containerIdentifier)
            {
                throw new ArgumentNullException(nameof(containerIdentifier));
            }

            if (string.IsNullOrWhiteSpace(memberAttributePath))
            {
                throw new ArgumentNullException(nameof(memberAttributePath));
            }

            if (string.IsNullOrWhiteSpace(memberIdentifier))
            {
                throw new ArgumentNullException(nameof(memberIdentifier));
            }

            if (string.IsNullOrWhiteSpace(containerIdentifier.Identifier))
            {
                throw new ArgumentException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionInvalidIdentifier);
            }

            if (!string.Equals(memberAttributePath, AttributeNames.Members, StringComparison.Ordinal))
            {
                string exceptionMessage =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterAttributePathNotSupportedTemplate,
                        memberAttributePath);
                throw new NotSupportedException(exceptionMessage);
            }

            if (!string.Equals(SchemaIdentifiers.Core2Group, containerIdentifier.SchemaIdentifier, StringComparison.Ordinal))
            {
                throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterNotSupported);
            }

            bool result =
                string.Equals(SampleProvider.IdentifierGroup, containerIdentifier.Identifier, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(SampleProvider.IdentifierUser, memberIdentifier, StringComparison.OrdinalIgnoreCase);

            return(result);
        }
        public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (string.IsNullOrWhiteSpace(resourceIdentifier?.Identifier))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            // call service
            try
            {
                Guid identifier = new Guid(resourceIdentifier.Identifier);
                _storageService.DeleteGroup(identifier);
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return(Task.CompletedTask);
        }
Exemple #14
0
        public virtual async Task Delete(HttpRequestMessage request, string identifier, string correlationIdentifier)
        {
            if (null == request)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(identifier))
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(nameof(correlationIdentifier));
            }

            IReadOnlyCollection <IExtension> extensions       = this.ReadExtensions();
            IResourceIdentifier            resourceIdentifier = this.CreateResourceIdentifier(identifier);
            IRequest <IResourceIdentifier> deletionRequest    =
                new DeletionRequest(request, resourceIdentifier, correlationIdentifier, extensions);

            await this.Provider.DeleteAsync(deletionRequest).ConfigureAwait(false);
        }
 public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
 {
     throw new NotImplementedException();
 }
 public override Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
 {
     this.Resource = null;
     return(Task.FromResult(0));
 }
        public override async Task Delete(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
        {
            if (null == resourceIdentifier)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameResourceIdentifier);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(FileProvider.ArgumentNameCorrelationIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResource);
            }

            string informationStarting =
                 string.Format(
                     CultureInfo.InvariantCulture,
                     AzureTestProvisioningResources.InformationDeleting,
                     resourceIdentifier.SchemaIdentifier,
                     resourceIdentifier.Identifier);
            ProvisioningAgentMonitor.Instance.Inform(informationStarting, true, correlationIdentifier);

            await this.file.RemoveRow(resourceIdentifier.Identifier);
        }
 /// <summary>
 /// Creates a to-one resource linkage object
 /// </summary>
 /// <param name="resourceIdentifier"></param>
 public ToOneResourceLinkage(IResourceIdentifier resourceIdentifier)
 {
     Identifiers = resourceIdentifier != null ? new[] { resourceIdentifier } : new IResourceIdentifier[] {};
 }
 public abstract Task DeleteAsync(IResourceIdentifier resourceIdentifier, string correlationIdentifier);
 /// <summary>
 /// Creates a To-many resource linkage object
 /// </summary>
 /// <param name="resourceIdentifiers"></param>
 /// <exception cref="NotImplementedException"></exception>
 public ToManyResourceLinkage(IResourceIdentifier[] resourceIdentifiers)
 {
     Identifiers = resourceIdentifiers ?? new IResourceIdentifier[] {};
 }
Exemple #21
0
 public TModel CreateResourceModel <TModel>(IResourceIdentifier resource)
 {
     return((TModel)CreateResourceModel(resource));
 }
Exemple #22
0
 private UniformResourceIdentifier(IResourceIdentifier identifier, IResourceQuery query)
 {
     this.Identifier = identifier ?? throw new ArgumentNullException(UniformResourceIdentifier.ArgumentNameIdentifier);
     this.Query      = query ?? throw new ArgumentNullException(UniformResourceIdentifier.ArgumentNameQuery);
     this.IsQuery    = null == this.Identifier || string.IsNullOrWhiteSpace(this.Identifier.Identifier);
 }
        private async Task UpdateMembers(
            IResourceIdentifier resourceIdentifier,
            PatchOperation membershipOperation,
            string correlationIdentifier)
        {
            if (null == resourceIdentifier)
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameResourceIdentifier);
            }

            if (null == membershipOperation)
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameMembershipOperation);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameCorrelationIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResourceIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.SchemaIdentifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResourceIdentifier);
            }

            IAmazonIdentityManagementService proxy = null;
            try
            {
                proxy = AWSClientFactory.CreateAmazonIdentityManagementServiceClient(this.credentials);

                Group group = await this.RetrieveGroup(resourceIdentifier.Identifier, proxy);
                if (null == group)
                {
                    string warning =
                    string.Format(
                        CultureInfo.InvariantCulture,
                        AmazonProvisioningAgentResources.WarningEntryNotFoundTemplate,
                        typeof(Group).Name,
                        resourceIdentifier.Identifier);
                    ProvisioningAgentMonitor.Instance.Warn(warning, correlationIdentifier);
                    return;
                }

                switch (membershipOperation.Name)
                {
                    case OperationName.Add:
                        foreach (OperationValue value in membershipOperation.Value)
                        {
                            await this.AddMember(group.GroupName, value.Value, proxy, correlationIdentifier);
                        }
                        break;
                    case OperationName.Remove:
                        foreach (OperationValue value in membershipOperation.Value)
                        {
                            await this.RemoveMember(group.GroupName, value.Value, proxy, correlationIdentifier);
                        }
                        break;
                    default:
                        string unsupportedOperation = Enum.GetName(typeof(OperationName), membershipOperation.Name);
                        throw new NotSupportedException(unsupportedOperation);
                }
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                    proxy = null;
                }
            }
        }
        public override async Task Delete(
            IResourceIdentifier resourceIdentifier, 
            string correlationIdentifier)
        {
            if (null == resourceIdentifier)
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameResourceIdentifier);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameCorrelationIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResource);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.SchemaIdentifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResource);
            }

            string informationStarting =
                 string.Format(
                     CultureInfo.InvariantCulture,
                     AmazonProvisioningAgentResources.InformationDeleting,
                     resourceIdentifier.SchemaIdentifier,
                     resourceIdentifier.Identifier);
            ProvisioningAgentMonitor.Instance.Inform(informationStarting, true, correlationIdentifier);

            IAmazonIdentityManagementService proxy = null;
            try
            {
                proxy = AWSClientFactory.CreateAmazonIdentityManagementServiceClient(this.credentials);

                string warning;
                switch (resourceIdentifier.SchemaIdentifier)
                {
                    case SchemaIdentifiers.Core2EnterpriseUser:
                        Amazon.IdentityManagement.Model.User user = 
                            await this.RetrieveUser(resourceIdentifier.Identifier, proxy);
                        if (null == user || string.IsNullOrWhiteSpace(user.UserName))
                        {
                            warning =
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    AmazonProvisioningAgentResources.WarningEntryNotFoundTemplate,
                                    typeof(Amazon.IdentityManagement.Model.User).Name,
                                    resourceIdentifier.Identifier);
                            ProvisioningAgentMonitor.Instance.Warn(warning, correlationIdentifier);
                            return;
                        }
                        DeleteUserRequest deleteRequestUser = new DeleteUserRequest(user.UserName);
                        await proxy.DeleteUserAsync(deleteRequestUser);
                        return;

                    case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                        Group group = 
                            await this.RetrieveGroup(resourceIdentifier.Identifier, proxy);
                        if (null == group || string.IsNullOrWhiteSpace(group.GroupName))
                        {
                            warning =
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    AmazonProvisioningAgentResources.WarningEntryNotFoundTemplate,
                                    typeof(Group).Name,
                                    resourceIdentifier.Identifier);
                            ProvisioningAgentMonitor.Instance.Warn(warning, correlationIdentifier);
                            return;
                        }
                        DeleteGroupRequest deleteRequestGroup = new DeleteGroupRequest(group.GroupName);
                        await proxy.DeleteGroupAsync(deleteRequestGroup);
                        return;

                    default:
                        throw new NotSupportedException(resourceIdentifier.SchemaIdentifier);
                }
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                    proxy = null;
                }
            }
        }
Exemple #25
0
 public Patch(IResourceIdentifier resourceIdentifier, PatchRequestBase request)
 {
     this.ResourceIdentifier = resourceIdentifier ?? throw new ArgumentNullException(nameof(resourceIdentifier));
     this.PatchRequest       = request ?? throw new ArgumentNullException(nameof(request));
 }
 public override Task Delete(IResourceIdentifier resourceIdentifier, string correlationIdentifier)
 {
     this.Resource = null;
     return Task.FromResult(0);
 }
        private async Task UpdateExternalIdentifier(
            IResourceIdentifier resourceIdentifier,
            string correlationIdentifier,
            string value = null)
        {
            if (null == resourceIdentifier)
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameResourceIdentifier);
            }

            if (string.IsNullOrWhiteSpace(correlationIdentifier))
            {
                throw new ArgumentNullException(AmazonWebServicesProvider.ArgumentNameCorrelationIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResourceIdentifier);
            }

            if (string.IsNullOrWhiteSpace(resourceIdentifier.SchemaIdentifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidResourceIdentifier);
            }

            IAmazonIdentityManagementService proxy = null;
            try
            {
                proxy = AWSClientFactory.CreateAmazonIdentityManagementServiceClient(this.credentials);

                switch (resourceIdentifier.SchemaIdentifier)
                {
                    case SchemaIdentifiers.Core2EnterpriseUser:
                        Amazon.IdentityManagement.Model.User user =
                            await this.RetrieveUser(resourceIdentifier.Identifier, proxy);
                        if (null == user)
                        {
                            return;
                        }

                        UpdateUserRequest updateUserRequest =
                            new UpdateUserRequest(user.UserName)
                            {
                                NewUserName = value
                            };

                        await proxy.UpdateUserAsync(updateUserRequest);
                        break;

                    case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                        Group group =
                            await this.RetrieveGroup(resourceIdentifier.Identifier, proxy);
                        if (null == group)
                        {
                            return;
                        }

                        UpdateGroupRequest updateGroupRequest =
                            new UpdateGroupRequest(group.GroupName)
                            {
                                NewGroupName = group.GroupName
                            };

                        await proxy.UpdateGroupAsync(updateGroupRequest);
                        break;

                    default:
                        throw new NotSupportedException(resourceIdentifier.SchemaIdentifier);
                }
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                    proxy = null;
                }
            }
        }