Thursday, March 1, 2012

CILogon and Liferay Part 4: The Liferay Theme

This is part 4 of a set of blog posts detailing a procedure for setting up CILogon to provide authentication for a Liferay Portal.

Technically, this step is optional.  What we're doing here is changing the Sign In link in the upper right corner of the Liferay page to point to your CILogon servlets.  If you intend to come at the portal from a different site then you can skip this step, although it would still be good to have this link either changed or disabled so that it's consistent with your logon approach.

First, you need to create a Liferay Theme plugin.  If your Liferay SDK isn't already set up, take a few minutes and follow the procedure here.

It's a LOT easier to modify an existing theme than to build one from scratch.  If you already have a  theme you're using, modify that.  If you don't, you can import the default Liferay theme and use it.  (It can be found in [liferay-portal-home]/[tomcat-home]/webapps/ROOT/html/themes/classic).  If you have the Liferay plugin for Eclipse, it can handle the details for you.

If you need to do it by hand, you can run the following ant command in the themes folder of your SDK:

create myAwesomeTheme "My Awesome Theme"

Ant will create an empty theme project for you.  Then, you can copy the files from the /classic themes folder described above into the /docroot folder of your theme project.  Do NOT delete the /_diffs folder!

The way we make changes to a them in Liferay is to override the files, not edit them directly.  This helps you to keep your changes straight and easy to keep track of.

In the _diffs folder, create a folder called templates.  Now, from the templates folder under docroot, copy the portal_normal.vm and init_custom.vm files.

Open init_custom.vm.  It should be blank.  Add the following line:

#set( $custom_sign_in_url = "[MyAwesomeDomain]/portal/startRequest" )


Save it and close it.

Now, in portal_normal.vm, find the line



#if(!$is_signed_in)
<a href="$sign_in_url" id="sign-in" rel="nofollow">$sign_in_text</a>
#end


And change it to



#if(!$is_signed_in)
<a href="$custom_sign_in_url" id="sign-in" rel="nofollow">$sign_in_text</a>
#end



So it uses your custom velocity variable that points to the CILogon servlets.

Now you can deploy your theme to Liferay and apply it!

No comments:

Post a Comment