Inside Paulo Abrantes' head
[ start | index | login or register ]
start > 2006-12-26 > 1

SnipSnap Hack: Secure Login

Created by pabrantes. Last edited by pabrantes, one year and 327 days ago. Viewed 1,276 times. #4
[diff] [history] [edit] [rdf]
labels
attachments

SnipSnap Hack: Secure Login

Well in the past few days I've been playing with >>HTTPS and SnipSnap. If you're interested in having a secure login solution with your snipsnap then this is for you.

First you have to setup the virtual host with SSL within apache - or any other webserver you're using. To see how setup a virtual host with SSL within apache you can check >>Email: Going from your localmail box to a distributed mailbox where I explain how to setup your webmail solution which includes setting up an SSL virtual host.
Now that you have setup an SSL virtual host that then proxies to your local jetty. You have two different ways of getting your snipsnap secured.

  • The easy way
  • The hackish way

The easy way

On the easy you only need to login into snipsnap using your administrator account and edit the config snip. You'll have a variable called app.real.protocol which is probably setted to http you then edit it to https. Also remember to check your app.real.host which migth be setted to http:// your_host, if so, remove the http:// part.

Now save the snip and your done. Currently all your snipsnap will run under https. Being each page secure, including the login. The problem with this is that the web engine spiders don't like to crawl https, they crawl http. If you want your snipsnap content to be crawled then, this is not your solution. Check the hackish below.

The hackish way

I've called this the hackish way although this hasn't much about hacking, just a few simple modifications. What we are going to do is find the login links and make them use https. How can we do this? Well it's easy.

You go into the JSP directory of snipsnap source, this is at src/apps/default. There you'll find another directory called util. In that directory there will be a JSP called mainbuttons.jsp. Now this JSP is the one responsible for the start, index, login/logout, etc links that show up on the top of snipsnap. Besides this login link, you have login link when you are trying to commenting a blog post although you aren't logged. We'll get there later.
First open the mainbuttons.jsp file with your favourite editor, and look up for a link to exec/login.jsp. Now that's something like:

<a href="exec/login.jsp"><fmt:message key="menu.login"/></a>

Now we want it to change to https, although we also have to provide the host and real path to your blog. So you edit that line for the following:

<a href="
<c:out value='https://${app.configuration.realHost}/${app.configuration.path}/exec/login.jsp'/>">
<fmt:message key="menu.login"/>
</a>

The c:out tag is >>JSTL core tag and mainly writes things. The app.configuration.realHost and the app.configuration.path are the values hold in the app.real.host and app.real.path on your config snip. Once again strip out any http:// that might show up in your app.real.host variable (don't worry it won't break anything).

Now there's another change you have to do, that's on the link found in the sentence "Please login to post a comment" when you access a blog post without being logged on.
So we open the comment.jsp file and find the following code:

[...snip...] <s:check roles="Authenticated" invert="true" > <fmt:message key="login.please"> <fmt:param><fmt:message key="post.comment"/></fmt:param> </fmt:message> </s:check> [...snip...]

Now this tells you that the link is within the localisation file - which in my opinion might have not been the best choice, but that I'll leave up to the developers. So you go into the locatisation directory, which is under src/apps/default/WEB-INF/classes/i18n and at least you edit the localisation file your using. If it's the english one you edit the messages_en.properties and you find the label login.please and change it to following value:

Please <a href="https://{0}/{1}/exec/login.jsp">login</a> to {2}

Now since we are sending two more values to this label we have to change the JSP source. so the source of comment.jsp I just showed becomes the following:

[...snip...] <s:check roles="Authenticated" invert="true" > <fmt:message key="login.please"> <fmt:param><c:out value="${app.configuration.realHost}"/></fmt:param> <fmt:param><c:out value="${app.configuration.path}"/></fmt:param> <fmt:param><fmt:message key="post.comment"/></fmt:param> </fmt:message> </s:check> [...snip...]

Now you just need to compile snipsnap again and deploy it. Your login links will now be under https and your snipsnap will now provide secure login.

If you have any problems setting up the secure login on your snipsnap you can always find my email in my profile, pabrantes.

Please login to www.pabrantes.net.
Who am I?
paulo-roca2My name is Paulo Abrantes AKA pabrantes and I'm a software developer. I'm currently employed at >>CIIST working as a Java developer in >>FenixEDU.

This blog is mostly about Java programming, domain driven design and snipsnap bliki developing. Everything written in this blog is my personal opinion and it may not reflect the opinions of my employer and co-workers.


Blog subscription
subscribe by rss subscribe by email

Links
>> Home
>> Paulo's Profile
>> Post History
>> Add to Technorati Favorites
>> Paulo's Photo Gallery
>> WishList
>> Posting without Login

Search Blog
Fellow Bloggers

Recent Posts

Java Programming: Bytecode Injection
Intermission: Sorry For Downtime
Software Developing: Studying The Bliki Domain Model
SnipSnap Developing: Trying to settle a roadmap
System Administration: Load Balancing with Apache
Blogging: Two years have passed
Software Developing: The SnipSnap Saga
Java Programming: Getting your code spicy with Groovy
Software Developing: Fluent Interfaces
Software Developing: Implementing a ShoutBox on SnipsSnip
Software Developing: SnipSnap, SnipIt and SnipSnip
Java Programming: Proxies and Access Control
Java Programming: Proxies and References
Java Programming: References' Package
YALM: Yet Another Layout Modification

For older posts, please refer to post-history for a complete Post History

Logged in Users: (0)
… and 4 Guests.
This is a modified version of snipsnap.org created by >>Paulo Abrantes