Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lift filter to force ssl

Tags:

scala

lift

struts

in a struts application, I have a filter that forces certain pages to be accessed only over https via redirection. I'm thinking in porting it to lift so my question is: In the this environment, is there a "lift" way to implement such filter or is it similar/the same as in struts ? Thanks

like image 679
xain Avatar asked Jun 28 '10 17:06

xain


People also ask

How do I force SSL connections to a site?

To force SSL connections to a site edit the .htaccess file in the folder containing the site. You can do this through cPanel File Manager or via FTP (download the file, edit it and upload again). After saving the file, try visiting your website using an http:// URL - you'll find that it gets redirected to the https:// version

How do I force HTTPS on a specific folder?

The .htaccess file can also be used to force HTTPS on specific folders. However, the file should be placed in the folder that will have the HTTPS connection. Make sure to change the folder references to the actual directory names. After making the changes, clear your browser’s cache and try to connect to your site via HTTP.

How do I force a shared SSL certificate for a folder?

Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folder with your actual domain name and folder you want to force the SSL on. To force your visitors to use your Shared SSL certificate:

What is delegatingfilterproxy in servlet?

Servlet container does not have any information about the Spring’s application context, but spring security needs security filters to execute the task.. Since DelegatingFilterProxy is a servlet filter, the application server register it as a normal filter in the context.


1 Answers

In Lift, the SiteMap defines the rules for page access. You can create a SiteMap entry that does a Redirect to the https site on certain pages:

// create an object that does a redirect to the https server if the
// request is on http
object RequireSSL extends Loc.EarlyResponse(
  () => {
    for {
      r <- S.request
      lowLevelReq <- Box !! r if lowLevelReq.scheme == "http"
    } {
      S.redirectTo("https://"+lowLevelReq.serverName+lowLevelReq.contextPath)
    }
    Empty
  })

// Build SiteMap
def entries = (Menu("Home") / "index") ::
(Menu("Secure") / "secure" >> RequireSSL) ::
Nil

Hope this helps.

like image 130
David Pollak Avatar answered Sep 28 '22 00:09

David Pollak