views:

10

answers:

0

Hi all,

Currently, I get stuck on checking administrator rights for a user. Somehow we can check this for a user to see if that user have a right properly to access profile ? In SP 2007, I found an article resolved this :

public static SharedServiceRights GetUserSSPRights(object context, string username) {

const string contextType = "Microsoft.Office.Server.ServerContext, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"; const string sharedServiceACE = "Microsoft.Office.Server.Infrastructure.SharedServiceAccessControlEntry, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c";

        Type sharedServiceAccessControlListType = Type.GetType("Microsoft.Office.Server.Infrastructure.SharedServiceAccessControlList, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
            MethodInfo sharedServiceAccessControlListMethod =
                sharedServiceAccessControlListType.GetMethod("GetInstance",
                    BindingFlags.NonPublic |
                    BindingFlags.Public |
                    BindingFlags.Instance |
                    BindingFlags.InvokeMethod |
                    BindingFlags.FlattenHierarchy |
                    BindingFlags.Static,
                    null,
                    new Type[] { Type.GetType(contextType) },
                    null
                   );

            object acl = sharedServiceAccessControlListMethod.Invoke(
                null,
                new object[] { context }
                );

            System.Reflection.PropertyInfo itemProp = acl.GetType().GetProperty("Item",
                   BindingFlags.NonPublic |
                   BindingFlags.Instance |
                   BindingFlags.InvokeMethod |
                   BindingFlags.GetProperty |
                   BindingFlags.Public
                   );

            //SharedServiceAccessControlEntryWrapper aclEntry =
            //    (SharedServiceAccessControlEntryWrapper)itemProp.GetValue(
            //        acl,
            //        new object[] { username }
            //        );

            object aclEntry =
                   itemProp.GetValue(
                       acl,
                       new object[] { username }
                       );
            //SharedServiceAccessControlEntryWrapper aclEntry1;
            if (aclEntry != null)
            {
                SharedServiceAccessControlEntryWrapper aclEntry1 = new SharedServiceAccessControlEntryWrapper(aclEntry);
                if (aclEntry1 != null)
                {
                    return aclEntry1.Rights;
                }
                else
                {
                    // the user is not even in the list
                    return SharedServiceRights.None;
                }
            }
            else
            {
                // the user is not even in the list
                return SharedServiceRights.None;
            }

            // check if the user has any permissions


    }
    #endregion

    #region Check User Have SSP Rights
    public static bool CheckUserHaveSSPRights(object context, string username, SharedServiceRights rightMask)
    {
        return (GetUserSSPRights(context, username) & rightMask) == rightMask;
    }
    #endregion

Thanks all Any help appreciated,

Standley

related questions