Пример #1
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.InputObject))
                {
                    ObjectId = InputObject.ObjectId;
                }
                else if (this.IsParameterBound(c => c.ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId);
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromDisplayName(DisplayName);
                }

                ConfirmAction(
                    Force.IsPresent,
                    string.Format(ProjectResources.RemovingApplication, ObjectId),
                    ProjectResources.RemoveApplication,
                    ObjectId.ToString(),
                    () => ActiveDirectoryClient.RemoveApplication(ObjectId));

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                EndDate = StartDate.AddYears(1);
                if (this.IsParameterBound(c => c.ApplicationObject))
                {
                    ObjectId = ApplicationObject.ObjectId;
                }
                else if (this.IsParameterBound(c => c.ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId);
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromDisplayName(DisplayName);
                }

                if (Password != null && Password.Length > 0)
                {
                    string decodedPassword = SecureStringExtensions.ConvertToString(Password);
                    // Create object for password credential
                    var passwordCredential = new PasswordCredential()
                    {
                        EndDate   = EndDate,
                        StartDate = StartDate,
                        KeyId     = Guid.NewGuid().ToString(),
                        Value     = decodedPassword
                    };
                    if (ShouldProcess(target: ObjectId.ToString(), action: string.Format("Adding a new password to application with objectId {0}", ObjectId)))
                    {
                        WriteObject(ActiveDirectoryClient.CreateAppPasswordCredential(ObjectId, passwordCredential));
                    }
                }
                else if (this.IsParameterBound(c => c.CertValue))
                {
                    // Create object for key credential
                    var keyCredential = new KeyCredential()
                    {
                        EndDate   = EndDate,
                        StartDate = StartDate,
                        KeyId     = Guid.NewGuid().ToString(),
                        Value     = CertValue,
                        Type      = "AsymmetricX509Cert",
                        Usage     = "Verify"
                    };
                    if (ShouldProcess(target: ObjectId.ToString(), action: string.Format("Adding a new certificate to application with objectId {0}", ObjectId)))
                    {
                        WriteObject(ActiveDirectoryClient.CreateAppKeyCredential(ObjectId, keyCredential));
                    }
                }
                else
                {
                    throw new InvalidOperationException("No valid keyCredential or passowrdCredential to update!!");
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.ApplicationObject))
                {
                    ObjectId = ApplicationObject.ObjectId;
                }
                else if (this.IsParameterBound(c => c.ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId);
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromDisplayName(DisplayName);
                }

                if (this.IsParameterBound(c => c.KeyId))
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingAppCredentialWithId, KeyId, ObjectId),
                        ProjectResources.RemoveCredential,
                        ObjectId.ToString(),
                        () => ActiveDirectoryClient.RemoveAppCredentialByKeyId(ObjectId, KeyId));
                }
                else
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingAllAppCredentials, ObjectId.ToString()),
                        ProjectResources.RemoveCredential,
                        ObjectId.ToString(),
                        () => ActiveDirectoryClient.RemoveAllAppCredentials(ObjectId));
                }

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.ApplicationObject))
                {
                    ObjectId = ApplicationObject.ObjectId;
                }
                else if (this.IsParameterBound(c => c.ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId);
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromDisplayName(DisplayName);
                }

                WriteObject(ActiveDirectoryClient.GetAppCredentials(ObjectId), enumerateCollection: true);
            });
        }
Пример #5
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (!this.IsParameterBound(c => c.EndDate))
                {
                    WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed);
                    EndDate = StartDate.AddYears(1);
                }

                if (this.IsParameterBound(c => c.ApplicationObject))
                {
                    ObjectId = ApplicationObject.ObjectId;
                }
                else if (this.IsParameterBound(c => c.ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromApplicationId(ApplicationId);
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    ObjectId = ActiveDirectoryClient.GetAppObjectIdFromDisplayName(DisplayName);
                }

                if (Password != null && Password.Length > 0)
                {
                    string decodedPassword = SecureStringExtensions.ConvertToString(Password);
                    // Create object for password credential
                    var passwordCredential = new PasswordCredential()
                    {
                        EndDate   = EndDate,
                        StartDate = StartDate,
                        KeyId     = KeyId == default(Guid) ? Guid.NewGuid().ToString() : KeyId.ToString(),
                        Value     = decodedPassword
                    };
                    if (!String.IsNullOrEmpty(CustomKeyIdentifier))
                    {
                        passwordCredential.CustomKeyIdentifier = Encoding.UTF8.GetBytes(CustomKeyIdentifier);
                    }
                    if (ShouldProcess(target: ObjectId, action: string.Format("Adding a new password to application with objectId {0}", ObjectId)))
                    {
                        WriteObject(ActiveDirectoryClient.CreateAppPasswordCredential(ObjectId, passwordCredential));
                    }
                }
                else if (CertValue != null)
                {
                    // Create object for key credential
                    var keyCredential = new KeyCredential()
                    {
                        EndDate             = EndDate,
                        StartDate           = StartDate,
                        KeyId               = KeyId == default(Guid) ? Guid.NewGuid().ToString() : KeyId.ToString(),
                        Value               = CertValue,
                        Type                = "AsymmetricX509Cert",
                        Usage               = "Verify",
                        CustomKeyIdentifier = CustomKeyIdentifier
                    };
                    if (ShouldProcess(target: ObjectId, action: string.Format("Adding a new certificate to application with objectId {0}", ObjectId)))
                    {
                        WriteObject(ActiveDirectoryClient.CreateAppKeyCredential(ObjectId, keyCredential));
                    }
                }
                else
                {
                    throw new InvalidOperationException("No valid keyCredential or passwordCredential to update!!");
                }
            });
        }