Saturday, March 27, 2010

Creating Liferay Themes

Liferay Themes customize the overall look and feel of Liferay and were introduced in version 3.5 of the portal. There are two ways to develop themes for Liferay. They are using,
  • Liferay Plugins SDK
  • Using Portal Pack on NetBeans IDE With Theme Plugin Support

Here I explained how to develop themes using Portal Pack on NetBeans. Before you start, install the Portal Pack 3.0.2 plugins on NetBeans IDE 6.5, 6.5.x, or 6.7 version. You can download the latest Portal Pack plugin from here.

You can refer this to Install the portal pack plugins and add the Liferay server to NetBeans.

Create a Web Application That Uses Liferay Portal Server as the Target Runtime:
  • Choose New Project from the File menu.
  • By default, Java Web and Web Application are selected from Categories and Projects respectively.
  • Click Next.
  • Type a name for the project, and click Next.
  • In this example, name the project CustomTheme.
  • Select WLiferay Portal Server5.1.x/5.2.x as the server, and click Next.
  • Click Finish.
To Create a Liferay Theme:
  • Right-click the project (CustomTheme) and choose New → Other.
  • A window appears.
  • Choose WebSpace/Liferay Plugins from Categories and Import/Create New Themefrom File Types, and click Next.
  • Type a Theme ID and Theme Name. You can also specify a theme folder.
  • In this example, use Custom_theme and Custom Theme as the Theme ID and Theme Name respectively. If you are creating more than one theme, it is better to create a Theme Folder as well.
  • Click Finish.
Making Changes to the Theme:
  • You can change the theme by adding new images to images/common folder and edit the custom.css file.
Deploy the theme:
  • To deploy the custom theme, right-click the project and choose Deploy.
  • The theme is deployed to the Liferay Server, and you can apply the theme to the Liferay instance on your machine.
Build a .war file of the theme:
  • Copy the folder of the theme (Which is in Liferay webapps folder) to a seperate location.
  • Using command prompt navigate to that folder location.
  • Then enter the following command in the command prompt.
jar -cvf themename.war *
  • Then it will create a file called themename.war file and you can use it to deploy in other liferay instances.

Tuesday, March 16, 2010

Integrate Liferay with CAS server.

Central Authentication Service (CAS) server is a single sign on (SSO) protocol for the web. Its purpose is to permit a user to access multiple applications while providing their credentials (such as userid and password) only once. It also allows web applications to authenticate users without gaining access to a user's security credentials, such as a password.

CAS was conceived and developed by Shawn Bayern of Yale University Technology and Planning. In December 2004, CAS became a project of the Java Architectures Special Interest Group, which is as of 2008 responsible for its maintenance and development. Formerly called "Yale CAS", CAS is now also known as "JA-SIG CAS". In oder to implement SSO with Liferay, I used the CAS server.

Following steps gives all the steps that I followed implemennting SSO in Liferay. I used Liferay (liferay-portal-tomcat-6.0-5.2.3), CAS Server (cas-server-3.3.5-release) and CAS client (cas-client-2.0.11).

Setting up CAS server:
  • Download the CAS server from
  • Rename the cas-server-3.3.5\modules\cas-server-webapp-3.3.5.war to cas-web.war.
  • Drop the cas-web.war file into Tomcat's webapps directroy. (For testing purposes I used the Liferay's tomcat but in a production environment CAS servershould really run on its own tomcat instance.
  • Then edit the server.xml file in tomcat and uncomment the SSL section to open up port 8443 as shown below.

Setting up the CAS client:

Generate the SSL cert with Java keytool:

  • In any directory ( I use my root ) enter the command:
keytool -genkey -alias tomcat -keypass changeit -keyalg RSA
  • Answer the questions as shown in the image: (note that your firstname and lastname MUST be hostname of your server and cannot be a IP address; this is very important as an IP address will fail client hostname verification even if it is correct)
  • Then enter the command:
keytool -export -alias tomcat -keypass changeit -file %FILE_NAME%
I use server.cert for %FILE_NAME%.
  • Finally import the cert into Java's keystore with this command.
keytool -import -alias tomcat -file %FILE_NAME% -keypass changeit -keystore %JAVA_HOME%/jre/lib/security/cacerts
  • Startup the CAS server by startup.bat in the bin folder.
  • Now you are ready to startup your CAS server. Simply startup Tomcat and access CAS with https://localhost:8443/cas-web/login You should see the CAS login screen and no errors in your catalina logs.

Setting up Liferay Portal:
  • Remove the sevencogs theme and the sample data by deleting the two sevencogs folders at the liferay-portal-5.2.3\ tomcat-6.0.18\webapps folder and by deleting the and lportal.script files at the liferay-portal-5.2.2\data\hsql folder.
  • Now if you run the liferay you should be able to login to portal by
Password: test
  • In the webapps/ROOT/WEB-INF/web.xml file add a new filter as shown below(add it as the first filter).
  • Then add the filter mapping directly above the first existing filter mapping as shown below.
  • Then add the following to the rest of the auto login filters.(Just after the last existing auto login filter)
  • Now Start up the Liferay and Go to sign in.
  • It will redirect you you CAS login page.
  • Then Enter the
NetID = test
Password = test
  • Then you will returned back to the Liferay home page as logged in user test.

Tuesday, March 2, 2010

Liferay JIRA with my own JIRA installation.

Although I was able to configure the jira portlet to work with my own JIRA installation (You can find all the steps at my previous post) there was a serious issue with that. When I logged in as a valid user to my Running JIRA (on http://localhost:8090) I can create new projects(only if logged in as administrator), and create new issues to any of projects. In JIRA there is a unique ID for each project. (Eg: 10000, 10010 etc) When you create a new project, JIRA will assign an new unused ID for that and that ID is used everywhere within the database in order to identify the project. Project details are stored in jiradb/project table and issue details are stored in jiradb/jiraissue table. You can go to your database and see them if you want.

The problem with World of Liferay -JIRA portlet was it uses some constant project IDs and names in order to display the issue summery to the user. It stores this constants values in interface. The view_jira.jspf file uses these constant IDs when creating the objects for the projects to display. So in order to change this, I had to change this view_jira.jspf completely.

I connected to the database of JIRA (jiradb) and select all the project IDs, their name and keys from the table project. Then I created the Jiraproject objects according to these data. The code is shown in below.

String[] prjIDs = new String[20];
String[] prjNames = new String[20];
String[] prjKeys = new String[20];
int meme =0;

Connection conn = null;
String myurl = "jdbc:mysql://";
String mydbName = "jiradb";
String mydriver = "com.mysql.jdbc.Driver";
String myuserName = "root";
String mypassword = "";
try {
conn = DriverManager.getConnection(myurl+mydbName,myuserName,mypassword);
Statement s = conn.createStatement ();
ResultSet resultset = s.executeQuery ("SELECT ID, pname, pkey FROM project");

while ( )
String myID = resultset.getString("ID");
String myName = resultset.getString("pname");
String myKey = resultset.getString("pkey");

prjIDs[meme] = myID;
prjNames[meme] = myName;
prjKeys[meme] = myKey;
meme = meme+1;
} catch (Exception e) {
for (int i = 0; i <>
Object[] jiraProject = new Object[] {Integer.parseInt(prjIDs[i]), prjKeys[i], prjNames[i]};
int projectId = (Integer)jiraProject[0];
String projectKey = (String)jiraProject[1];
String projectName = (String)jiraProject[2];