1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / S3 only for my Sitefinity

S3 only for my Sitefinity

5 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Apr 2010
    Link to this post
    Hi,

    Could someone explain how you can protect your content to be deliverer only for one Sitefinity web site using public shared files. Exist some way to manage using some custom handler or generated sessions credentials to prevent consume your content by others websites. All suggestions tips or links  welcome.

    regards.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    22 Apr 2010
    Link to this post
    Hello Pierre,

    If S3 refers to Amazon S3 storage, you can generate a URL with an expiration date. You may find this post useful - How to Generate URL for Amazon s3 file - Signed URL

    ‘Signed URL' is the url which is valid for specific time period that's why its also know as " Time Limited Signed URL ".


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Apr 2010
    Link to this post
    Hi Ivan,

    Yes, but how i can manage in my sf solution for static files. I have more than 400 Mb of files linked to my solution actually are pointing to the storage manager not in libraries. Could you explain how i can redirect the request of this files to some handler and after use S3 with expiration data changing the path on the fly to accessing. I use the suggested S3 telerik library associated to RadEditor and libraries but is not clear for me if i need to change all paths manually or i can use one internal and secured handler to manage from sf. I have found some complementary tips to hold the Url but what about manage static files from sf directly from custom code. Could integrate this handler or redirect with Libraries and physical storage files together.
    Thanks, Romi

    #region S3 Privacy thanks to mtranda from S3 forum
     
        private static string ComputeS3HashedURL(string Bucket, string FileKey, DateTime expiration, string AccessKey, string SecretKey)
        {
            string returnString = string.Empty;
            System.Security.Cryptography.HMAC hmacProvider = System.Security.Cryptography.HMAC.Create();
            hmacProvider.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(SecretKey);
            string expirationString = ConvertToUnixTimestamp(expiration).ToString();
            string assembledRequest = "GET\n\n\n" + expirationString + "\n/" + Bucket + "/" + FileKey;
            byte[] hashedSignature = hmacProvider.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(assembledRequest));
            returnString = Convert.ToBase64String(hashedSignature);
            return "http://" + Bucket + ".s3.amazonaws.com/" + FileKey + "?AWSAccessKeyId=" + AccessKey + "&Expires=" + expirationString + "&Signature=" + Uri.EscapeDataString(returnString);
        }
     
        private static double ConvertToUnixTimestamp(DateTime date)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            TimeSpan diff = date - origin;
            return Math.Floor(diff.TotalSeconds);
        }
        #endregion
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    22 Apr 2010
    Link to this post
    Hello Pierre,

    You could create a custom provider that inherits from AmazonProvider class and override OnExecuting and OnExecuted where you could modify the bucket and the url

      protected override void OnExecuted(ExecutedEventArgs args, bool fireEvents)
          {
              IContent currentItem = args.Data as IContent;
            
              switch (args.CommandName)
              {
                  case "CreateContent":
                   //  do something
     
    SaveContentToExternal(stagedContent, library);
                                  manager.SaveContent(stagedContent,  ContentStatus.Published);
                      break;
                  case "UpdateContent":
                                 
                          
                  // do something
                      break;
     
              }
     
          }
     
           
     
          private string contentUrl = string.Empty;
     
          private void SaveContentToExternal(IContent item, ILibrary library)
          {
              if (item.Content is byte[])
              {
                  /// do the work
                  byte[] content = (byte[]) item.Content;
                  string url = // here form the url and set some expiration
                  item.Content = contentUrl =  url;
              }
          }

    Another option is overriding S3StorageHandler behavior. In ProcessRequest method you could change the behavior of the default module.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    23 Apr 2010
    Link to this post
    Hi,

    Yes this is perfect to manage libraries using signed url but how i can parse on fly my other static resources. For sample the new Telerik MVC have one content delivery network that can parse the resources to deliver static files from somewhere defined in the web.config. I searching one method to redirect all demands of static files to the s3 and signing the demands. In this sample used by Omar using one StaticContentFilter he suggest one method to make this but is not usable when u use at same time the Radcompressor or other compressing method for cms pages. The object is during the request remove the old path and use the new static defined. Could you suggest some other way to perform one on fly replacement.

    Cheers, Romi
Register for webinar
5 posts, 0 answered