public override void ExecuteCmdlet()
        {
            ADObjectFilterOptions options = new ADObjectFilterOptions
            {
                SPN = ServicePrincipalName,
                Id  = ObjectId
            };

            ExecutionBlock(() =>
            {
                // At max 1 SP can be returned with SPN and Id options
                var sp = ActiveDirectoryClient.FilterServicePrincipals(options).FirstOrDefault();

                if (sp == null)
                {
                    throw new InvalidOperationException("ServicePrincipal does not exist.");
                }

                // Get AppObjectId
                string applicationObjectId = ActiveDirectoryClient.GetObjectIdFromApplicationId(sp.ApplicationId.ToString());

                if (!string.IsNullOrEmpty(DisplayName))
                {
                    ApplicationUpdateParameters parameters = new ApplicationUpdateParameters()
                    {
                        DisplayName = DisplayName
                    };

                    if (ShouldProcess(target: sp.Id.ToString(), action: string.Format("Updating properties on application associated with a service principal with object id '{0}'", sp.Id)))
                    {
                        ActiveDirectoryClient.UpdateApplication(applicationObjectId, parameters);
                    }
                }
            });
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (!string.IsNullOrEmpty(ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromApplicationId(ApplicationId);
                }

                bool deleteAllCredentials = false;
                if (All.IsPresent)
                {
                    deleteAllCredentials = true;
                }

                if (KeyId != Guid.Empty)
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingAppCredentialWithId, KeyId, ObjectId),
                        ProjectResources.RemoveCredential,
                        ObjectId,
                        () => ActiveDirectoryClient.RemoveAppCredentialByKeyId(ObjectId, KeyId));
                }
                else if (deleteAllCredentials)
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingAllAppCredentials, ObjectId.ToString()),
                        ProjectResources.RemoveCredential,
                        ObjectId,
                        () => ActiveDirectoryClient.RemoveAllAppCredentials(ObjectId));
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (!string.IsNullOrEmpty(ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromApplicationId(ApplicationId);
                }

                WriteObject(ActiveDirectoryClient.GetAppCredentials(ObjectId), enumerateCollection: true);
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (!string.IsNullOrEmpty(ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromApplicationId(ApplicationId);
                }

#pragma warning disable 0618
                if (!string.IsNullOrEmpty(Password))
#pragma warning restore 0618
                {
                    // Create object for password credential
                    var passwordCredential = new PasswordCredential()
                    {
                        EndDate   = EndDate,
                        StartDate = StartDate,
                        KeyId     = Guid.NewGuid().ToString(),
#pragma warning disable 0618
                        Value = Password
#pragma warning restore 0618
                    };
                    if (ShouldProcess(target: ObjectId, action: string.Format("Adding a new password to application with objectId {0}", ObjectId)))
                    {
                        WriteObject(ActiveDirectoryClient.CreateAppPasswordCredential(ObjectId, passwordCredential));
                    }
                }
                else if (!string.IsNullOrEmpty(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, 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!!");
                }
            });
        }
Esempio n. 5
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (!string.IsNullOrEmpty(ApplicationId))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromApplicationId(ApplicationId);
                }

                ApplicationUpdateParameters parameters = new ApplicationUpdateParameters
                {
                    DisplayName             = DisplayName,
                    Homepage                = HomePage,
                    IdentifierUris          = IdentifierUris,
                    ReplyUrls               = ReplyUrls,
                    AvailableToOtherTenants = AvailableToOtherTenants
                };

                if (ShouldProcess(target: ObjectId, action: string.Format("Updating an application with object id '{0}'", ObjectId)))
                {
                    ActiveDirectoryClient.UpdateApplication(ObjectId, parameters);
                }
            });
        }