public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException("username");
            }
            string tenantName;
            string tenantUsername;

            if (!Upn.TryParse(username, out tenantName, out tenantUsername))
            {
                return(false);  //invalid username format
            }
            try
            {
                if (!AuthenticationProxy.UserExists(tenantName, tenantUsername))
                {
                    return(false); //not exists
                }
                AuthenticationProxy.DeleteUser(tenantName, tenantUsername);
            }
            catch (Exception ex)
            {
                throw new ProviderException(ex.Message, ex);
            }
            return(true);
        }
Example #2
0
        public override string[] GetRolesForUser(string username)
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(username, out tenantName, out tenantUsername);
            return(AuthorizationProxy.GetRolesForUser(tenantName, tenantUsername));
        }
Example #3
0
        public override bool IsUserInRole(string username, string roleName)
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(username, out tenantName, out tenantUsername);
            return(AuthorizationProxy.IsUserInRole(tenantName, tenantUsername, roleName));
        }
Example #4
0
        public override void CreateRole(string roleName)
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(HttpContext.Current.User.Identity.Name, out tenantName, out tenantUsername);
            if (!string.IsNullOrEmpty(tenantName))
            {
                AuthorizationProxy.CreateRole(tenantName, roleName);
            }
        }
Example #5
0
        private string[] FromUpns(string[] upns)
        {
            string tenantName = null;

            string[] usernames = new string[upns.Length];
            for (int i = 0; i < upns.Length; i++)
            {
                Upn.TryParse(upns[i], out tenantName, out usernames[i]);
            }
            return(usernames);
        }
        public override bool ValidateUser(string username, string password)
        {
            string tenantName;
            string tenantUsername;

            if (!Upn.TryParse(username, out tenantName, out tenantUsername))
            {
                return(false);
            }
            return(AuthenticationProxy.ValidateUser(tenantName, tenantUsername, password));
        }
Example #7
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(HttpContext.Current.User.Identity.Name, out tenantName, out tenantUsername);
            string[] adamUsernames = FromUpns(usernames);
            if (!string.IsNullOrEmpty(tenantName))
            {
                AuthorizationProxy.RemoveUsersFromRoles(tenantName, adamUsernames, roleNames);
            }
        }
Example #8
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(HttpContext.Current.User.Identity.Name, out tenantName, out tenantUsername);
            if (!string.IsNullOrEmpty(tenantName))
            {
                AuthorizationProxy.DeleteRole(tenantName, roleName);
            }
            return(true);
        }
Example #9
0
        public override bool RoleExists(string roleName)
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(HttpContext.Current.User.Identity.Name, out tenantName, out tenantUsername);
            if (!string.IsNullOrEmpty(tenantName))
            {
                return(AuthorizationProxy.RoleExists(tenantName, roleName));
            }
            else
            {
                return(false);
            }
        }
Example #10
0
        public override string[] GetAllRoles()
        {
            string tenantName     = null;
            string tenantUsername = null;

            Upn.TryParse(HttpContext.Current.User.Identity.Name, out tenantName, out tenantUsername);
            if (!string.IsNullOrEmpty(tenantName))
            {
                return(AuthorizationProxy.GetAllRoles(tenantName));
            }
            else
            {
                return(null);
            }
        }
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            string tenantName;
            string tenantUsername;

            if (!Upn.TryParse(username, out tenantName, out tenantUsername))
            {
                throw new ArgumentException(string.Format("The username {0} is invalid!", username));
            }
            AdamUser adamUser = AuthenticationProxy.GetAdamUser(tenantName, tenantUsername);

            if (adamUser == null)
            {
                return(null);
            }
            object providerUserKey = new SecurityIdentifier(adamUser.Sid, 0);

            return(new ActiveDirectoryMembershipUser(this.Name, adamUser.PrincipleName, providerUserKey, adamUser.Email, string.Empty, string.Empty
                                                     , true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now));
        }
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException("username");
            }
            string tenantName;
            string tenantUsername;

            if (!Upn.TryParse(username, out tenantName, out tenantUsername))
            {
                return(false);
            }
            CheckPassword(oldPassword, MinRequiredPasswordLength, "oldPassword");
            CheckPassword(oldPassword, MinRequiredPasswordLength, "newPassword");
            if (newPassword.Length < this.MinRequiredPasswordLength)
            {
                throw new ArgumentException(string.Format("The length of the passowrd {0} must not be shorter than {1} characters!", "newPassword", MinRequiredPasswordLength));
            }
            int num1 = 0;

            for (int num2 = 0; num2 < newPassword.Length; num2++)
            {
                if (!char.IsLetterOrDigit(newPassword, num2))
                {
                    num1++;
                }
            }
            if (num1 < this.MinRequiredNonAlphanumericCharacters)
            {
                throw new ArgumentException(string.Format("Non alpha numeric characters of {0} must be more than {1}", "newPassword", MinRequiredNonAlphanumericCharacters));
            }
            if ((this.PasswordStrengthRegularExpression.Length > 0) && !Regex.IsMatch(newPassword, this.PasswordStrengthRegularExpression))
            {
                throw new ArgumentException(string.Format("The format of the password {0} is not correct!", "newPassword"));
            }

            AuthenticationProxy.ChangePassword(tenantName, tenantUsername, oldPassword, newPassword);
            return(true);
        }
        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            //extract tenant name from the current user upn
            string tenantName;
            string username;

            Upn.TryParse(HttpContext.Current.User.Identity.Name, out tenantName, out username);

            MembershipUserCollection collection = new MembershipUserCollection();

            string[] usernames = AuthenticationProxy.GetUsers(tenantName);
            totalRecords = usernames.Length;
            int start = pageIndex * pageSize;

            if (start >= 0 && start < totalRecords)
            {
                for (int i = start; i < totalRecords && i < start + pageSize; i++)
                {
                    collection.Add(System.Web.Security.Membership.GetUser((new Upn(tenantName, usernames[i])).ToString()));
                }
            }
            return(collection);
        }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            status = MembershipCreateStatus.Success;
            string tenantName;
            string tenantUsername;

            if (string.IsNullOrEmpty(username))
            {
                status = MembershipCreateStatus.InvalidUserName;
                return(null);
            }

            if (!Upn.TryParse(username, out tenantName, out tenantUsername))
            {
                status = MembershipCreateStatus.InvalidUserName;
                return(null);
            }

            if (string.IsNullOrEmpty(email))
            {
                status = MembershipCreateStatus.InvalidEmail;
                return(null);
            }

            if (string.IsNullOrEmpty(password) || password.Length < MinRequiredPasswordLength)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            int i = 0;

            for (int j = 0; j < password.Length; j++)
            {
                if (!char.IsLetterOrDigit(password, j))
                {
                    i++;
                }
            }
            if (i < MinRequiredNonAlphanumericCharacters)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }
            if ((PasswordStrengthRegularExpression.Length > 0) && !Regex.IsMatch(password, PasswordStrengthRegularExpression))
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            base.OnValidatingPassword(args);
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            try
            {
                if (AuthenticationProxy.UserExists(tenantName, tenantUsername))
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                    return(null);
                }
                AuthenticationProxy.CreateUser(tenantName, tenantUsername, password, email);
            }
            catch (Exception ex)
            {
                throw new ProviderException(ex.Message, ex);
            }
            return(GetUser(username, false));
        }