Saturday, 28 September 2013

How to configure Apache Tomcat in Eclipse IDE?

Apache Tomcat (or simply Tomcat) is an open source web server and Servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications. This can be managed manually or configured in any IDE.
This tutorial provides step by step explanation of how to configure Apache Tomcat in Eclipse IDE.

Environment Used

  • JDK 6 (Java SE 6)
  • Eclipse Indigo IDE for Java EE Developers (3.7.1)
  • Apache Tomcat 6.x
  • Windows OS/Ubuntu OS

Installing JDK

JDK should be installed with proper environment set up. Read this page for installing the JDK and setting up the environment. Installing JDK automatically installs JRE.

Installing Eclipse IDE

We use Eclipse IDE throughout this tutorial. If you need to install Eclipse, you can read this page.

Installing Apache Tomcat

Tomcat should be installed before configuring it in Eclipse IDE. If you need to install Apache Tomcat, you can read this page.

Configuring Apache Tomcat in Eclipse IDE

The step for configuring Apache Tomcat in Eclipse IDE is similar for Windows and Ubuntu OS.

Open Eclipse IDE

Add Server

Make sure you are in Java EE perspective and in “Servers” area, right click -> New -> Server.
Here you will see list of servers that can be configured in the installed Eclipse IDE version. You will find Tomcat v6.0 Server under “Apache” folder as shown below.
Select “Tomcat v6.0 Server” and click Next.

Configuring Apache Tomcat installation location

Select the Tomcat Root folder which has bin folder and click Next.
There are no resources to be configured and hence click Finish.
The configured Apache Tomcat Server will be displayed in the “Servers” view.

Start Server

It is easy to manage the server instance. Right-click on the server and start and stop it to ensure its proper working.

Test your installation

After starting the Tomcat, open browser and type http://localhost:8080. You should see the Apache Tomcat home page as shown below.

Custom Landing Page Hook


After a user logs into Liferay, it is a common requirement to be able to redirect them to a different page based on their Organization or Site membership. This hook allows you to specify the desired redirection behavior using a properties file setting. Based on the properties file, it will redirect the user to their private page, public page, their default site's public/private homepage, or their default organization's public/private homepage.
It's a Custom Landing Page Hook developed in Liferay 6.1.1 GA2. It will allow you to choose on which page user will land on after login. Right now it's having below options for landing page.
Set this property as per your needs for landing page after user log in. It could be from one of the value from below options
  1. userPrivatePage
  2. userPublicPage
  3. sitePublicPage
  4. sitePrivatePage
  5. organizationPublicPage
  6. organizationPrivatePage
custom.landing.page.type={userPrivatePage/userPublicPage/sitePublicPage/sitePrivatePage/organizationPublicPage/organizationPrivatePage} 
This propery need to be set in portal.properties located in Custom Landing Page hook itself. Either you can modify it directly in war. Or you can download the source code from Git repositry and you can build war from source with your desired changes.

Friday, 27 September 2013

Liferay4you: Installing Liferay on WebSphere 8.0Liferay Home is...

Liferay4you: Installing Liferay on WebSphere 8.0Liferay Home is...: Installing Liferay on WebSphere 8.0 Liferay Home  is in a folder called  liferay  in the home folder of the user ID that is running We...

Thursday, 26 September 2013

The Portal section of the control panel

The Portal section of the control panel is used for most administrative tasks. You’ll find there an interface for the creation and maintenance of the following portal entities: users, organizations, user groups, sites, teams, site templates, page templates, and roles. Additionally, you can configure many settings, including the following: password policies, portal settings, custom fields, monitoring, and plugins configuration.
portal-section-control-panel.png
The Portal Section of the control panel allows portal administrators to manage users, organizations, sites, teams, site templates, page templates, and roles, as well as various portal settings.
Since we explained how to manage sites, teams, site templates, and page templateswe’ll focus on using the control panel for user management. 
As a portal administrator, you’ll use the Portal section of the control panel to create your portal structure, implement security, and administer your users. Configurable portal settings include mail host names, email notifications and authentication options including single sign-on and LDAP integration. Note that only users with the administrator role, which is a portal scoped role, have permission to view this section of the control panel. You can, of course, grant permissions to one or more sections to custom roles.

Installing Liferay on WebSphere 8.0

Liferay Home is in a folder called liferay in the home folder of the user ID that is running WebSphere.

Preparing WebSphere for Liferay

When the application server binaries have been installed, start the Profile Management Tool to create a profile appropriate for Liferay.
  1. Click on Create…. Choose Application Server. Click Next.
  2. Click the Advanced profile creation option and then click Next. Why Advanced? You can specify your own values for settings such as the location of the profile and names of the profile, node and host. You can assign your own ports. You can optionally choose whether to deploy the administrative console and sample application and also add web-server definitions if you wish. Web server definitions are used with IBM HTTP Server. For more information about these options, please see the WebSphere documentation.
    Websphere-8_html_5a8a0a4b.png
    Figure 14.48: Choose the Advanced profile option to specify your own settings.
  3. Check the box Deploy administrative console. This gives you a web-based UI for working with your application server. Skip the default applications. You’d only install these on a development machine. Click Next.
  4. Set profile name and location. Ensure you specify a performance tuning setting other than Development, since you’re installing a server for production use. Click Next.
    Websphere-8_html_m3feb4e9f.png
    Figure 14.49: Use a performance tuning setting other than Development. We’ve selected Standard here. Please see the WebSphere documentation for further information about performance tuning settings.
  5. Choose node and host names for your server. These will be specific to your environment. Click Next.
    Websphere-8_html_1327271c.png
    Figure 14.50: Choose node and host names appropriate to your environment.
  6. Administrative security in WebSphere is a way to restrict who has access to the administrative tools. For simplicity, we’ve disabled it but you may want to have it enabled in your environment. Please see WebSphere’s documentation for further information. Click Next.
    Websphere-8_html_2eb820b.png
    Figure 14.51: We’ve disabled administrative security but you may want to enable it.
  7. Each profile needs a security certificate, which comes next in the wizard. If you don’t have certificates already, choose the option to generate a personal certificate and a signing certficate and click Next.
  8. Once the certificates are generated, set a password for your keystore. Click Next.
    Websphere-8_html_m6b754c08.png
    Figure 14.52: Set a password for your keystore.
  9. Next, you can customize the ports this server profile uses. Be sure to choose ports that are open on your machine. When choosing ports, installation detects existing WebSphere installations and if it finds activity, it increments ports by one.
    Websphere-8_html_m2eef7200.png
    Figure 14.53: WebSphere gives you a nice user interface for customizing the ports your server uses.
  10. If you want WebSphere to start automatically when the machine is booted, you configure it next. This differs by operating system. When you’re finished configuring this the way you want, click Next.
  11. WebSphere ships with IBM HTTP Server, which is a rebranded version of Apache. If you want to front your WebSphere server with IBM HTTP Server, you’d configure this next. Please see WebSphere’s documentation for details on this. When finished, click Next.
  12. WebSphere then creates your profile and finishes with a message telling you the profile was created successfully. You’re now ready to install Liferay!

Copying portal dependencies

Liferay ships with dependency .jars it needs to have on the global classpath. These should be copied to WebSphere’s global folder provided for this purpose:
[Install Location]/WebSphere/AppServer/lib/ext
Once you’ve copied the .jars here, start the server profile you’re planning to use for Liferay. Once it starts, you’re ready to configure your database.

Database Configuration

If you want WebSphere to manage the database connections, follow the instructions below. Note this is not necessary if you’re planning on using Liferay’s standard database configuration; in that case, skip this section. You’ll set your database information in Liferay’s setup wizard after the install.
02-websphere-jdbc-providers.png
  1. Start WebSphere.
  2. Open the Administrative Console and log in.
  3. Click Resources → JDBC Providers.
  4. Click New.
  5. For name, enter the name of JDBC provider (e.g. MySQL JDBC Provider).
  6. For Implementation class name, enter:
    com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
    
  7. Click Next.
  8. Clear any text in classpath. You already copied the necessary .jars to a location on the server’s class path.
  9. Click Next.
  10. Click Finish.
  11. Click Data Sources under Additional Properties.
  12. Click New.
  13. Enter a name: liferaydatabasesource.
  14. Enter JNDI: jdbc/LiferayPool.
  15. Everything else should stay at the default values. Save the data source.
  16. When finished, go back into the data source and click Custom Properties and then click the Show Filter Functionbutton. This is the second from last of the small icons under the New and Delete buttons.
  17. Type user into the search terms and click Go.
    02-modifying-data-source-properties-in-websphere.png
  18. Select the user property and give it the value of the user name to your database. Click OK and save to master configuration.
  19. Do another filter search for the url property. Give it a value that points to your database. For example, the MySQL URL would be: jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false. Click OK and save to master configuration.
  20. Do another filter search for the password property. Enter the password for the user ID you added earlier as the value for this property. Click OK and save to master configuration.
  21. Go back to the data source page by clicking it in the breadcrumb trail. Click the Test Connection button. It should connect successfully.
Once you’ve set up your database, you can set up your mail session.

Mail Configuration

If you want WebSphere to manage your mail sessions, use the following procedure. If you want to use Liferay’s built-in mail sessions, you can skip this section.
  1. Click Resources → Mail → Mail Providers.
  2. Click the Built-In Mail Provider for your node and server.
  3. Click Mail Sessions and then click the New button.
  4. Give it a name of liferaymail and a JNDI name of mail/MailSession. Click OK and save to master configuration.
  5. Click Security → Global Security and deselect Use Java 2 security to restrict application access to local resources if it is selected. Click Apply.
Great! Now you’re ready to deploy Liferay.

Deploy Liferay

  1. Click Applications → New Application → New Enterprise Application.
  2. Browse to the Liferay .war file and click Next.
  3. Leave Fast Path selected and click Next, then click Next again.
  4. Make sure your server is selected and click Next.
  5. Keep the context root set to / and click Next.
  6. Click Finish. When Liferay has installed, click Save to Master Configuration.

Start Liferay

  1. If you plan to use Liferay’s setup wizard, skip to the next step. If you wish to use WebSphere’s data source and mail session, create a file called portal-ext.properties in your Liferay Home folder. Place the following text in the file:
    jdbc.default.jndi.name=jdbc/LiferayPool
    mail.session.jndi.name=mail/MailSession
    setup.wizard.enabled=false
    
  2. Select the Liferay application and click Start.
    Websphere-8_html_m7420ff51.png
    Figure 14.56: Starting Liferay on WebSphere.
  3. In the setup wizard, select and configure your database type. Click Finish when you’re done.
    Liferay then creates the tables it needs in the database.

Liferay OpenDS and CAS Integration

Integrating OpenDS and CAS in Liferay 

I am using Liferay 5.2.3, openDs-2.2.0 and CAS (http://www.jasig.org/cas)


OpenDS LDAP

1) Open DS (http://www.opends.org/) . I am going with minimal configuration for LDAP.

Steps to Follow:

1) Install plain open DS from http://www.opends.org/, without default configuration.

While installation I changed the default port form 389 to 10389.

a) provided hostname [PC name]:abc

b) Create Admin as say: cn=admin,ou=system with password changeit.

c) create a Base DN entry as: dc=company,dc=com

d) Create user entry under ou=people. under this basedn entry.

e) Connect OpenDS via JExplorer LDAP Browser ( http://jxplorer.org/) and you can see those entries as.:

For connecting via JExplorer use:

Host: abc , port:10389
protocal: LDAP V3
BaseDN: dc=company,dc=com
Level: user + password
userDn: cn=admin,ou=system
password: changeit

You should see something like:



Now we are done with LDAP Setting successfully.
Liferay + LDAP
2) Install Liferay Tomcat Bundle downloaded from http://www.liferay.com/ (I am using liferay 5.2.3).

a) Open up the bundle extract it to some directory say: d:\ in windows.

b) Start liferay (TOMCAT_HOME/bin/start) of the above bundle.

c) Go to control panel of Liferay: (Login as bruno admin and under drop down menu "control panel")

d) In control Panel Go to Portal->Settings->Authentication->LDAP.
Here provide the details as:

Enabled :Check
Base provider URL: ldap://abc:10398/
BaseDN: dc=company,dc=com
Principal: cn=admin,ou=system
credentails=chageit[Photo]
Now test the LDAP connection using "Test LDAP Connection" button. It should give you successful result.
Under users section provide details as:
Authentication Search Filter:(mail=@email_address@)
Import Search Filter (objectClass=inetOrgPerson)
Screen Name: cn
Password: userPassword
EmailAddress:mail
FirstName: givenName
LastName: sn
JobTitle: title
Group: groupMembership

After this Click on "Test LDAP Users" You should see the users we created while LDAP setup.

Here under import /export section: check import Enabled, export Eanbled.
userDn: ou=people,dc=company,dc=com
Leave rest details as default.
Save the details and you are set to go.You can test via logging form user;s in LDAP in Liferay :)....
Now we will proceed with Integration of CAS over these settings which we have done till now.

3) CAS Integration: 

a) Download CAS : cas-server-3.3.5-release from http://www.jasig.org/cas. Explode the Zip file and you will find cas-server-webapp-3.3.5.war in modules folder.
b) Prepare a fresh installtion of tomcat say at port : 8081 because liferay will be running on 8080.
a) For this open the server.xml file in fresh insalled tomcat and chnage port 8080 to 8081.
b)Un-comment the following section to enable https. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" />
c)Rename the cas-server-webapp-3.3.5.war as cas-web.war and put it in webapps folder of the fresh tomcat installation.
d)Start this tomcat server.
e) After starting the tomcat. Stop the tomcat server, you should see cas-web folder now in webapps directory.
f) Now go to cas-web/web-inf folder open deployerConfigContext.xml and provide following enteries:
g) Under : <property name="authenticationHandlers"> ....<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient" />......add
<bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler"> <property name="filter" value="cn=%u" /> <property name="searchBase" value="ou=People,dc=company,dc=com" /> <property name="contextSource" ref="contextSource" /> </bean>

h). Since we are creating a reference to contextSource above, so we need to add a bean with that reference. Add a new bean entry as: <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <property name="urls"> <list> <value>ldap://abc:10389/</value> </list> </property> <property name="userDn" value="cn=admin,ou=system"/> <property name="password" value="changeit"/> <property name="baseEnvironmentProperties"> <map> <entry> <key> <value>java.naming.security.authentication</value> </key> <value>simple</value> </entry> </map> </property></bean>
3) save ths file.
4) Now we will configure Liferay to enable CAS authentication. For this goto Liferay -> control panel >Settings->Authentication->CAS
5) Do the following changes:
Enabled: checked
Import from LDAP: checked
Login URL: https://abc:8443/cas-web/login (Assuming CAS is also on abc)
Logout URL: https://abc:8443/cas-web/logout
server name: abc:8080 (Liferay is on 8080)
Service URL: http://abc:8080/c/portal/login
validate URL: https://abc:8443/cas-web/proxyValidate
save the settings.
Now shutdown Liferay and Tomcat (CAS one) both.
Now we have completed our basic conficuration, the only thing missing is the certificate by which authentication will be done via CAS. So let's generate certificated and make it trusted for things to work like butter :)
Generate the SSL cert with Java keytool ;
In any directory enter the command :
keytool -genkey -alias tomcat -keypass password -keyalg RSA
Answers the Q's (note that your firstname and lastname MUST be hostname of your server and cannot be a IP address)
Enter keystore password: changeit 
What is your first and last name? [Unknown]: abc
What is the name of your organizational unit? [Unknown]: abc
What is the name of your City or Locality? [Unknown]: 
What is the name of your State or Province? [Unknown]: 
What is the two-letter country code for this unit? [Unknown]: Is CN=abc, OU=abc, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct? [no]: yes
Then Enter command:
keytool -export -alias tomcat -keypass changeit -file server.cert
This command exports the cert you generated from your personal keystore (In windows .keystore file) . To save the certificate on file named server.cert
Finally import the cert into Java's keystore with this command.
keytool -import -alias tomcat -file server.cert keypass changeit -keystore %JAVA_HOME%/jre/lib/security/cacerts
Note: This import of certificate should be done for all the JRE's [The tomcat JRE for CAS and the JRE for Liferay], probably the liferay bundle would be having its own JRE, so import the certificate there as well as in the Tomcat installation JRE or JDK , should be Java_home :).

After this....Yeah we are all set.......
Start OpenDS, Start CAS Tomcat, Start Liferay.
Form home click "sign in" in liferay, you will be redirected to CAS login screen. Enter the credentials which we added in LDAP [Note: CAS authenticates with userId not email which liferay does], so put Id we used in LDAP into CAS login screen with password, put password and submit. You should now be redirected to Liferay and logged in with Signed in User.
Some Problems that I faced during above activity:
1) Exporting to LDAP fails if the user doesn't have a Job Title: Well provide jobTitle...Its required by Liferay. so go to LDAP browser and for each user provide value for title.
2) I have to use Passwords as plain text as passwords are exported to LDAP via Liferay is in form of Plain Text.
3) CAS uses username for authentication and for liferay its the ScreenName. so authentication is for screenname even if we supply email as authentication in Liferay.
4) Unable to validate ProxyTicketValidator [[edu.yale.its.tp.cas.client.ProxyTicketValidator proxyList=[null] : This error comes up whenever the certificates are not matching on both the JVM's where CAS and Liferay is running. So, just ensure they are correct and at proper place, This problem will be resolved.

Wednesday, 25 September 2013

Use of structure and template


Here I have try to put information as simple as possible.
Here you will see how we can use structure and template in web content.

To understand the use of structure and template we will take example of video playing functionality.
 Structure will be useful to upload the video and  template would be responsible to display the content in specific format.



Video player using structure and template

Just follow below steps :



1) Go to control panel >> web content section
2) Click on structure tab and Create sample structure (i.e video structure) (see below screenshot)

 Now as per screen shot , click on add row and define video_link filed name and type would be Document and media. Now save it.We are done with structure which has only once filed right now. you can add as many fields as you want.
3)Click on template tab and create one template (i.r video template) (See below screenshot)


Now as per screenshot, you can see one button called "Launch editor" just click on that and put below code into it :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://releases.flowplayer.org/js/flowplayer-3.2.9.min.js"></script>

<!-- set up container for the player -->
<a id="player" style="width:500px;height:320px;display:block"></a>

<!-- third argument is flowplayer configuration. you cannot use events -->
<script language="JavaScript">
flashembed("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.10.swf", {
    config: {
        clip: 'http://localhost:8080$video_link.getData()',
        plugins: {
            controls: null
        }
    }
});
</script>

4) Now create one web content and associate structure and template to that web content.
5) so when you associate video link structure , web content will have once field to upload the video called video_link which we had created in structure.(See below screen shot)

 6) once you upload the video just click on publish button and publish this document.
7) Now to show this video we will use web content display portelt and configure our web content into that which we have created using video structure and video template.(See below screenshot)




So now you can see the beauty of structure and template in liferay CMS portlet.

Hope this will be useful to reduce effort at some place where you are thinking to create separate portlet to upload video and play video.