Exemplo n.º 1
0
        /// <summary>
        /// Returns the directory of a user by path.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="path">The path.</param>
        /// <returns>
        /// The directory or <see langword="null" /> if not found.
        /// </returns>
        protected static IDirectory GetDirectory(ICloudPrincipal user, string path)
        {
            if (user == null)
            {
                return(null);
            }

            var userDir = user.Directory;

            if (userDir == null)
            {
                return(null);
            }

            var fs = userDir.FileSystem;

            if (fs == null)
            {
                return(null);
            }

            path = (path ?? string.Empty).Trim();
            if (path == string.Empty)
            {
                path = "/";
            }

            return(fs.GetDirectory(path));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the sync object for a user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>The sync object.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="user" /> is <see langword="null" />.
        /// </exception>
        public object this[ICloudPrincipal user]
        {
            get
            {
                if (user == null)
                {
                    throw new ArgumentNullException("user");
                }

                return(this[user.Identity.Name]);
            }
        }
Exemplo n.º 3
0
        /// <inheriteddoc />
        public UserFileSystem(ICloudPrincipal user)
            : base()
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            this.User = user;

            this._ROOT = new UserDirectory(this,
                                           user.GetDataDirectory(), null);
        }
        /// <inheriteddoc />
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // check login
                ICloudPrincipal loggedInUser = null;
                {
                    var data = (context.Request.ServerVariables["HTTP_AUTHORIZATION"] ?? string.Empty).Trim();
                    if (string.IsNullOrWhiteSpace(data) == false)
                    {
                        if (data.ToLower().StartsWith("basic "))
                        {
                            try
                            {
                                var base64EncodedData = data.Substring(data.IndexOf(" ")).Trim();
                                var blobData          = Convert.FromBase64String(base64EncodedData);

                                var strData = new UTF8Encoding().GetString(blobData);

                                var semicolon = strData.IndexOf(":");
                                if (semicolon > -1)
                                {
                                    var username = strData.Substring(0, semicolon).ToLower().Trim();
                                    if (username == string.Empty)
                                    {
                                        username = null;
                                    }

                                    string pwd = null;
                                    if (semicolon < (strData.Length - 1))
                                    {
                                        pwd = strData.Substring(semicolon + 1);
                                    }

                                    if (string.IsNullOrEmpty(pwd))
                                    {
                                        pwd = null;
                                    }

                                    loggedInUser = context.GetPrincipalRepository()
                                                   .TryFindPrincipalByLogin(username, pwd);
                                }
                            }
                            catch
                            {
                                // ignore errors here
                            }
                        }
                    }
                }

                if (loggedInUser == null)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    context.Response.AddHeader("WWW-Authenticate", "BASIC Realm=Cloud.NET");

                    return;
                }

                var req = new CloudRequest()
                {
                    Context   = context,
                    Principal = loggedInUser,
                };

                req.Context.Response.StatusCode = (int)HttpStatusCode.OK;

                this.OnProcessRequest(req);
            }
            catch (Exception ex)
            {
                context.Response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                context.Response.StatusDescription = (ex.GetBaseException() ?? ex).Message ?? string.Empty;
            }
            finally
            {
                context.Response.End();
            }
        }