示例#1
0
        /// <summary>
        /// Creates group with specified name.
        /// </summary>
        /// <param name="name">Group name.</param>
        /// <returns>Newly created group.</returns>
        public async Task <IPrincipalAsync> CreatePrincipalAsync(string name)
        {
            if (!PrincipalBase.IsValidUserName(name))
            {
                throw new DavException("Group name contains invalid characters", DavStatus.FORBIDDEN);
            }

            GroupPrincipal groupPrincipal = new GroupPrincipal(Context.GetPrincipalContext());

            groupPrincipal.Name = name;

            groupPrincipal.Save();

            return(new Group(groupPrincipal, Context));
        }
        /// <summary>
        /// Creates user.
        /// </summary>
        /// <param name="name">User name.</param>
        /// <returns>Newly created user.</returns>
        public async Task <IPrincipalAsync> CreatePrincipalAsync(string name)
        {
            if (!PrincipalBase.IsValidUserName(name))
            {
                throw new DavException("User name contains invalid characters", DavStatus.FORBIDDEN);
            }

            UserPrincipal userPrincipal = new UserPrincipal(Context.GetPrincipalContext());

            userPrincipal.Name = name;
            userPrincipal.UserPrincipalName = name;

            userPrincipal.Enabled = true;
            userPrincipal.ExpirePasswordNow();

            Context.PrincipalOperation(userPrincipal.Save);

            return(new User(userPrincipal, Context));
        }
示例#3
0
        /// <summary>
        /// Gets object representing ACL folder/user/group.
        /// </summary>
        /// <param name="path">Relative path requested.</param>
        /// <param name="context">Instance of <see cref="DavContext"/> class.</param>
        /// <returns>Object implemening LogicalFolder/IPrincipalFolder</returns>
        internal static async Task <IHierarchyItemAsync> GetAclItemAsync(DavContext context, string path)
        {
            //If this is /acl - return fake folder which contains users and groups.
            if (path == AclFolder.PREFIX)
            {
                return(new AclFolder(context));
            }

            //if this is /acl/users - return fake folder which contains users.
            if (path == UserFolder.PREFIX)
            {
                return(new UserFolder(context));
            }

            //if this is /acl/groups - return fake folder which contains groups.
            if (path == GroupFolder.PREFIX)
            {
                return(new GroupFolder(context));
            }

            //if this is /acl/users/<user name> - return instance of User.
            if (path.StartsWith(UserFolder.PATH))
            {
                string name = EncodeUtil.DecodeUrlPart(path.Substring(UserFolder.PATH.Length));
                //we don't need an exception here - so check for validity.
                if (PrincipalBase.IsValidUserName(name))
                {
                    return(User.FromName(name, context));
                }
            }

            //if this is /acl/groups/<group name> - return instance of Group.
            if (path.StartsWith(GroupFolder.PATH))
            {
                string name = EncodeUtil.DecodeUrlPart(path.Substring(GroupFolder.PATH.Length));
                if (PrincipalBase.IsValidUserName(name))
                {
                    return(Group.FromName(name, context));
                }
            }
            return(null);
        }