public SPIisWebServiceApplicationInstance(ObjectInstance prototype, SPIisWebServiceApplication iisWebServiceApplication)
            : this(prototype)
        {
            if (iisWebServiceApplication == null)
            {
                throw new ArgumentNullException("iisWebServiceApplication");
            }

            m_iisWebServiceApplication = iisWebServiceApplication;
        }
        internal static OutputQueue IsUserProfileServiceApplicationAvailable(out bool isAvailable)
        {
            var outputQueue = new OutputQueue();

            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisite, UserDisplay.PrerequisiteUserProfileAvailable));
            try
            {
                SPIisWebServiceApplication app = null;
                outputQueue.Add(UserProfileService.GetUserProfileApplication(out app));
                isAvailable = app != null;
            }
            catch (Exception exception)
            {
                isAvailable = false;
                outputQueue.Add(exception.Message, OutputType.Error, null, exception);
            }
            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisiteComplete, UserDisplay.PrerequisiteUserProfileAvailable, isAvailable ? UserDisplay.CheckingPrerequisitePassed : UserDisplay.CheckingPrerequisiteFailed));
            return(outputQueue);
        }
Beispiel #3
0
        internal static OutputQueue UserHasAccess(out bool hasAccess, string accountName = null)
        {
            var outputQueue = new OutputQueue();

            hasAccess = false;

            if (string.IsNullOrEmpty(accountName))
            {
                accountName = WindowsIdentity.GetCurrent().Name;
            }

            var mossContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, new SPSiteSubscriptionIdentifier(Guid.Empty));

            using (var scope = new SPServiceContextScope(mossContext))
            {
                SPIisWebServiceApplication app = null;
                outputQueue.Add(GetUserProfileApplication(out app));
                if (app != null)
                {
                    var accessControl = app.GetAccessControl();
                    if (accessControl != null)
                    {
                        var accessRules = accessControl.GetAccessRules();

                        foreach (var rule in accessRules)
                        {
                            if (rule.Name.ToUpperInvariant().EndsWith(accountName.ToUpperInvariant(), StringComparison.CurrentCultureIgnoreCase))
                            {
                                hasAccess = rule.AllowedRights == SPIisWebServiceApplicationRights.FullControl;
                                if (hasAccess)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(outputQueue);
        }
Beispiel #4
0
        internal static OutputQueue EnsureUserAccess(string accountName = null)
        {
            var outputQueue = new OutputQueue();

            if (string.IsNullOrEmpty(accountName))
            {
                accountName = WindowsIdentity.GetCurrent().Name;
            }

            var mossContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, new SPSiteSubscriptionIdentifier(Guid.Empty));

            using (var scope = new SPServiceContextScope(mossContext))
            {
                SPIisWebServiceApplication app = null;
                outputQueue.Add(GetUserProfileApplication(out app));
                if (app != null)
                {
                    var isAdmin = false;
                    outputQueue.Add(UserIsAdministrator(out isAdmin, accountName));
                    if (!isAdmin)
                    {
                        var aac = app.GetAdministrationAccessControl();
                        aac.AddAccessRule(new SPAclAccessRule <SPCentralAdministrationRights>(new NTAccount(accountName), SPCentralAdministrationRights.FullControl));
                        app.SetAdministrationAccessControl(aac);
                    }

                    var hasAccess = false;
                    outputQueue.Add(UserHasAccess(out hasAccess, accountName));
                    if (!hasAccess)
                    {
                        var ac = app.GetAccessControl();
                        ac.AddAccessRule(new SPAclAccessRule <SPIisWebServiceApplicationRights>(new NTAccount(accountName), SPIisWebServiceApplicationRights.FullControl));
                        app.SetAccessControl(ac);
                    }
                    app.Update();
                }
            }

            return(outputQueue);
        }
Beispiel #5
0
        internal static OutputQueue GetUserProfileApplication(out SPIisWebServiceApplication serviceApplication)
        {
            var outputQueue = new OutputQueue();

            serviceApplication = null;

            var serviceContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, new SPSiteSubscriptionIdentifier(Guid.Empty));

            try
            {
                var upmType  = TypeUserProfileManager;
                var upapType = TypeUserProfileApplicationProxy;

                var upmConstructor = upmType.GetConstructor(new[] { typeof(SPServiceContext), typeof(bool), typeof(bool) });
                var upm            = upmConstructor.Invoke(new object[] { serviceContext, false, false });
                var prop           = upm.GetType().GetProperty("UserProfileApplicationProxy", BindingFlags.Instance | BindingFlags.NonPublic);

                var proxy = prop.GetValue(upm, null);
                var prop1 = upapType.GetProperty("UserProfileApplication", BindingFlags.Instance | BindingFlags.NonPublic);

                var app = prop1.GetValue(proxy, null);

                serviceApplication = app as SPIisWebServiceApplication;

                if (serviceApplication == null)
                {
                    throw new ArgumentNullException(string.Format(System.Globalization.CultureInfo.CurrentCulture, Exceptions.NullException, "serviceApplication"));
                }
            }
            catch (Exception exception)
            {
                outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, Exceptions.UserProfileServiceApplicationNotFound, exception.Message), OutputType.Error, null, exception);
            }

            return(outputQueue);
        }