コード例 #1
0
 private object AuthenticateActiveDirectory(IObjectSpace objectSpace) {
     var windowsIdentity = WindowsIdentity.GetCurrent();
     if (windowsIdentity != null) {
         string userName = windowsIdentity.Name;
         var user = (IAuthenticationActiveDirectoryUser)objectSpace.FindObject(UserType, new BinaryOperator("UserName", userName));
         if (user == null) {
             if (_createUserAutomatically) {
                 var args = new CustomCreateUserEventArgs(objectSpace, userName);
                 if (!args.Handled) {
                     user = (IAuthenticationActiveDirectoryUser)objectSpace.CreateObject(UserType);
                     user.UserName = userName;
                     if (Security != null) {
                         //Security.InitializeNewUser(objectSpace, user);
                         Security.CallMethod("InitializeNewUser", new object[]{objectSpace, user});
                     }
                 }
                 objectSpace.CommitChanges();
             }
         }
         if (user == null) {
             throw new AuthenticationException(userName);
         }
         return user;
     }
     return null;
 }
コード例 #2
0
        private object AuthenticateActiveDirectory(IObjectSpace objectSpace)
        {
            var windowsIdentity = WindowsIdentity.GetCurrent();

            if (windowsIdentity != null)
            {
                string userName = windowsIdentity.Name;
                var    user     = (IAuthenticationActiveDirectoryUser)objectSpace.FindObject(UserType, new BinaryOperator("UserName", userName));
                if (user == null)
                {
                    if (_createUserAutomatically)
                    {
                        var args = new CustomCreateUserEventArgs(objectSpace, userName);
                        if (!args.Handled)
                        {
                            user          = (IAuthenticationActiveDirectoryUser)objectSpace.CreateObject(UserType);
                            user.UserName = userName;
                            if (Security != null)
                            {
                                //Security.InitializeNewUser(objectSpace, user);
                                Security.CallMethod("InitializeNewUser", new object[] { objectSpace, user });
                            }
                        }
                        objectSpace.CommitChanges();
                    }
                }
                if (user == null)
                {
                    throw new AuthenticationException(userName);
                }
                return(user);
            }
            return(null);
        }
        private object AuthenticateActiveDirectory(IObjectSpace objectSpace)
        {
            string userName = WindowsIdentity.GetCurrent().Name;
            IAuthenticationActiveDirectoryUser user = (IAuthenticationActiveDirectoryUser)objectSpace.FindObject(UserType, new BinaryOperator("UserName", userName));

            if (user == null)
            {
                if (createUserAutomatically)
                {
                    CustomCreateUserEventArgs args = new CustomCreateUserEventArgs(objectSpace, userName);
                    if (!args.Handled)
                    {
                        user          = (IAuthenticationActiveDirectoryUser)objectSpace.CreateObject(UserType);
                        user.UserName = userName;
                        //if (base.Security is ICanInitializeNewUser) {
                        //    ((ICanInitializeNewUser)base.Security).InitializeNewUser(objectSpace, user);
                        //}
                        if (Security is SecurityStrategyBase)
                        {
                            System.Reflection.MethodInfo mi = typeof(SecurityStrategyBase).GetMethod("InitializeNewUserCore", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                            mi.Invoke(Security, new object[] { objectSpace, user });
                        }
                    }
                    objectSpace.CommitChanges();
                }
            }
            if (user == null)
            {
                throw new AuthenticationException(userName);
            }
            return(user);
        }
コード例 #4
0
        private object AuthenticateActiveDirectory(IObjectSpace objectSpace)
        {
            var windowsIdentity = WindowsIdentity.GetCurrent();

            if (windowsIdentity != null)
            {
                string userName = windowsIdentity.Name;
                object user     = objectSpace.FindObject(UserType, new BinaryOperator("UserName", userName));
                if (user == null)
                {
                    if (_createUserAutomatically)
                    {
                        CustomCreateUserEventArgs args = new CustomCreateUserEventArgs(objectSpace, userName);
                        if (CustomCreateUser != null)
                        {
                            CustomCreateUser(this, args);
                            user = (IAuthenticationActiveDirectoryUser)args.User;
                        }
                        if (!args.Handled)
                        {
                            user = objectSpace.CreateObject(UserType);
                            ((IAuthenticationActiveDirectoryUser)user).UserName = userName;
                            if (Security != null)
                            {
                                //Security.InitializeNewUser(objectSpace, user);

                                // Make this a best-effort attempt to call InitializeNewUser - the ICanInitializeNewUser
                                // interface isn't accessable so we can't check if UserType actually implements it.
                                try { Security.CallMethod("InitializeNewUser", new object[] { objectSpace, user }); }
                                catch { }
                            }
                        }
                        bool strictSecurityStrategyBehavior = SecurityModule.StrictSecurityStrategyBehavior;
                        SecurityModule.StrictSecurityStrategyBehavior = false;
                        objectSpace.CommitChanges();
                        SecurityModule.StrictSecurityStrategyBehavior = strictSecurityStrategyBehavior;
                    }
                }

                if (user == null)
                {
                    throw new AuthenticationException(userName);
                }
                return(user);
            }
            return(null);
        }
コード例 #5
0
        private static void AuthenticationActiveDirectoryProvider_CustomCreateUser(object sender, CustomCreateUserEventArgs e)
        {
            AuthenticationActiveDirectoryProvider provider = (AuthenticationActiveDirectoryProvider)sender;
            CustomPermissionPolicyUser            user     = e.ObjectSpace.CreateObject <CustomPermissionPolicyUser>();

            user.UserName = e.UserName;
            user.IsActiveDirectoryUser = true;
            provider.CanInitializeNewUser.InitializeNewUser(e.ObjectSpace, user);
            e.User    = user;
            e.Handled = true;
        }