Beispiel #1
0
        public CreateSTF(long securityCode, long xmlBlockSize, string filename, long endMarker, Root DirectoryHierarchyManager)
        {
            #region Routine for creating STF
            FileStream   STFStream = new FileStream(string.Format("{0}.{1}", Environment.CurrentDirectory + @"\" + ConfigurationSettings.AppSettings["AllEntityLocation"] + filename, ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]), FileMode.Create, FileAccess.Write);
            BinaryWriter writeSTF  = new BinaryWriter(STFStream);

            writeSTF.Write(securityCode);              //Security Code
            writeSTF.Write(true);                      //Setting IsFolder Property
            writeSTF.Write(xmlBlockSize);              //Writing XML File Size
            IncludeXML("HierarchySize.xml", writeSTF); //Writing XML Document

            long numberOfFiles = LockParameters.NumberOfFiles;
            writeSTF.Write(numberOfFiles);   //Writing number of files included
            ByteOffset  = 25 + xmlBlockSize; //Byte Offset before files
            ByteOffset += numberOfFiles * 24;
            for (long FileKey = 0; FileKey < numberOfFiles; ++FileKey)
            {
                FileAttrib SelectFile = LockParameters.GetFileAttrib((int)FileKey);
                writeSTF.Write(FileKey);                                                                   //Writing FileID
                writeSTF.Write(LockParameters.GetFileAttrib((int)FileKey).FileStartLocation + ByteOffset); //Writing File Start Location
                writeSTF.Write(LockParameters.GetFileAttrib((int)FileKey).FileEndLocation + ByteOffset);   //Writing File End Location
            }

            for (long FileKey = 0; FileKey < numberOfFiles; ++FileKey)
            {
                IncludeFile(LockParameters.GetFileAttrib((int)FileKey), writeSTF);
            }

            writeSTF.Write(endMarker);
            writeSTF.Close();
            STFStream.Close();

            #endregion
        }
Beispiel #2
0
        public HttpResponseMessage GetLocks()
        {
            var statusCode    = HttpStatusCode.OK;
            var locksResponse = new LocksResponseContract();

            try
            {
                LockParameters parameters = LockParameters.ParseGetLocksParameters(HttpContext.Current.Request.QueryString);
                locksResponse.UserId = parameters.UserId;

                // Check if the user exists.
                this.userDal.GetUser(parameters.UserId);

                IList <LockModel> locks = this.lockDal.GetLocks();
                locksResponse.Locks   = locksResponse.ConvertToContract(locks);
                locksResponse.Message = "List of locks.";
            }
            catch (InvalidParameterException paramException)
            {
                locksResponse.Message = paramException.Message;
                statusCode            = HttpStatusCode.BadRequest;
            }
            catch (UserNotFoundException userException)
            {
                locksResponse.Message = userException.Message;
            }

            return(Request.CreateResponse(statusCode, locksResponse, formatter));
        }
        public static string BuildRequestBody(LockParameters lockParams)
        {
            var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));
            var lockinfo = new XElement("{DAV:}lockinfo", new XAttribute(XNamespace.Xmlns + "D", "DAV:"));
            lockinfo.Add(GetLockScope(lockParams.LockScope));
            lockinfo.Add(GetLockType());
            if (lockParams.Owner != null)
                lockinfo.Add(GetLockOwner(lockParams.Owner));

            doc.Add(lockinfo);
            return doc.ToStringWithDeclaration();
        }
Beispiel #4
0
        public HttpResponseMessage CreateLock()
        {
            var statusCode   = HttpStatusCode.OK;
            var lockResponse = new LockResponseContract();

            try
            {
                LockParameters parameters = LockParameters.ParsePutLockParameters(HttpContext.Current.Request.QueryString);
                lockResponse.UserId = parameters.UserId;

                // Check if the user exists.
                UserModel user = this.userDal.GetUser(parameters.UserId);

                // Check if users specified in access list exist.
                foreach (int allowedUser in parameters.AllowedUsers)
                {
                    this.userDal.GetUser(allowedUser);
                }

                // If the user is an admin they can create a lock with an access list.
                if (user.IsAdmin)
                {
                    LockModel lockModel = this.lockDal.CreateLock(parameters.LockName, parameters.AllowedUsers);
                    if (lockModel == null)
                    {
                        lockResponse.Message = "Failed to create the lock.";
                    }

                    lockResponse.LockState    = lockModel.State;
                    lockResponse.LockId       = lockModel.LockId;
                    lockResponse.LockName     = parameters.LockName;
                    lockResponse.AllowedUsers = parameters.AllowedUsers;
                    lockResponse.Message      = "Lock created successfully.";
                }
                else
                {
                    lockResponse.Message = "User unauthorized.";
                    statusCode           = HttpStatusCode.Unauthorized;
                }
            }
            catch (InvalidParameterException paramException)
            {
                lockResponse.Message = paramException.Message;
                statusCode           = HttpStatusCode.BadRequest;
            }
            catch (UserNotFoundException userException)
            {
                lockResponse.Message = userException.Message;
            }

            return(Request.CreateResponse(statusCode, lockResponse, formatter));
        }
Beispiel #5
0
        public HttpResponseMessage ModifyLockState()
        {
            bool?          result       = null;
            LockParameters parameters   = null;
            var            statusCode   = HttpStatusCode.OK;
            var            lockResponse = new LockResponseContract();

            try
            {
                parameters          = LockParameters.ParsePostLockParameters(HttpContext.Current.Request.QueryString);
                lockResponse.LockId = parameters.LockId;
                lockResponse.UserId = parameters.UserId;

                // Check to see if the user exists.
                this.userDal.GetUser(parameters.UserId);

                result = this.lockDal.ModifyLockState(parameters.LockId, parameters.UserId, parameters.LockState);
                lockResponse.LockState = result.Value ? parameters.LockState.ToString() : "Failed";

                lockResponse.Message = result.Value ?
                                       String.Format(CultureInfo.InvariantCulture, "Door {0}ed successfully.", parameters.LockState) :
                                       String.Format(CultureInfo.InvariantCulture, "Door {0} failed.", parameters.LockState);

                this.eventsDal.CreateEvent(parameters.LockId, parameters.UserId, lockResponse.LockState);
            }
            catch (InvalidParameterException paramException)
            {
                lockResponse.Message = paramException.Message;
                statusCode           = HttpStatusCode.BadRequest;
            }
            catch (UserNotFoundException userException)
            {
                lockResponse.Message = userException.Message;
            }
            catch (UnauthorizedUserException userAuthException)
            {
                lockResponse.Message = userAuthException.Message;
                statusCode           = HttpStatusCode.Unauthorized;

                this.eventsDal.CreateEvent(parameters.LockId, parameters.UserId, "Unauthorized");
            }
            catch (LockNotFoundException lockException)
            {
                lockResponse.Message = lockException.Message;
            }

            return(Request.CreateResponse(statusCode, lockResponse, formatter));
        }
Beispiel #6
0
        public static string BuildRequestBody(LockParameters lockParams)
        {
            var doc      = new XDocument(new XDeclaration("1.0", "utf-8", null));
            var lockinfo = new XElement("{DAV:}lockinfo", new XAttribute(XNamespace.Xmlns + "D", "DAV:"));

            lockinfo.Add(GetLockScope(lockParams.LockScope));
            lockinfo.Add(GetLockType());
            if (lockParams.Owner != null)
            {
                lockinfo.Add(GetLockOwner(lockParams.Owner));
            }


            doc.Add(lockinfo);
            return(doc.ToStringWithDeclaration());
        }
Beispiel #7
0
        public void LockFolder(string absoluteFolderPath, string Password)
        {
            #region LockFolder implementation
            LockParameters.FlushAll();
            Validate PasswordValidate = new PasswordValidation(Password);
            PasswordValidate.ValidateData();
            string   DirectoryName        = GetLeafDirectoryName(absoluteFolderPath);
            Validate FolderExistsValidate = new SBNExists(Path.GetFileName(DirectoryName));
            FolderExistsValidate.ValidateData();
            CreateFolderHierarchy createFolderHierarchy = new CreateFolderHierarchy(absoluteFolderPath);
            Root   fileSystemHierarchyManager           = createFolderHierarchy.FolderHierarchy;
            string DirName = Path.GetFileName(absoluteFolderPath);
            ConfigurationManager SaveConfiguration = new ConfigurationManager();
            SaveConfiguration.WriteFileHierarchyXml("HierarchySize.xml", fileSystemHierarchyManager);
            System.IO.FileInfo finfo = new FileInfo("HierarchySize.xml");
            long SizeOfXmlBlock      = finfo.Length;
            try
            {
                CreateSTF STF = new CreateSTF(SECURITYCODE, SizeOfXmlBlock, DirName, ENDMARKER, fileSystemHierarchyManager);
            }
            catch (Exception ex)
            {
                throw (new ApplicationException(ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"] + " File Creation Failed"));
            }
            IEncrypt Encrypter = new InstantiateElement().CreateNewInstance(ConfigurationSettings.AppSettings["Encrypter_Assembly"], DirName, Password) as IEncrypt;
            Encrypter.EncryptFile();
            System.IO.File.Delete(ConfigurationSettings.AppSettings["AllEntityLocation"] + DirName + "." + ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]);
            if (bool.Parse(ConfigurationSettings.AppSettings["DeleteSource"]) == true)
            {
                if (System.IO.Directory.Exists(absoluteFolderPath))
                {
                    System.IO.Directory.Delete(absoluteFolderPath, true);
                }
            }

            if (System.IO.File.Exists("HierarchySize.xml"))
            {
                System.IO.File.Delete("HierarchySize.xml");
            }



            #endregion
        }
Beispiel #8
0
        public HttpResponseMessage GetLockState()
        {
            var statusCode   = HttpStatusCode.OK;
            var lockResponse = new LockResponseContract();

            try
            {
                LockParameters parameters = LockParameters.ParseGetLockParameters(HttpContext.Current.Request.QueryString);
                lockResponse.LockId = parameters.LockId;
                lockResponse.UserId = parameters.UserId;

                // Check to see if the user exists.
                this.userDal.GetUser(parameters.UserId);

                lockResponse.LockState = this.lockDal.GetLockState(parameters.LockId);
                lockResponse.Message   = "State of lock.";
            }
            catch (InvalidParameterException paramException)
            {
                lockResponse.Message = paramException.Message;
                statusCode           = HttpStatusCode.BadRequest;
            }
            // We do not want to give information on what input is incorrect.
            // Keeping the response generic so that malicious intent is not
            // provided with too much information.
            catch (UserNotFoundException userException)
            {
                lockResponse.Message = userException.Message;
            }
            catch (LockNotFoundException lockException)
            {
                lockResponse.Message = lockException.Message;
            }

            return(Request.CreateResponse(statusCode, lockResponse, formatter));
        }