Friday, March 28, 2014

Liferay Parameter Auto Login

Introduction:

Liferay Parameter Auto Login is one of the mechanisms to login into liferay portal using simple URL and it allows to user can login simple by click some URL link and no need of sign in portlet.

What is Auto login in liferay?

Auto login is mechanism to login into liferay portal without provide user credential for each time login. Liferay provide different mechanisms.

The following are important Auto Login Mechanisms in Liferay

CAS Auto Login:

With help of this user will be authenticated by CAS at one time and next login user can directly login into without asking credentials.

Remember me Auto Login:

This also another one when user first login we liferay will store credentials in cookies when user next login then it automatically login.

Ntlm Auto Login:

 This login uses the computer user name and password to login into liferay it need AD server support.

Parameter Auto Login:

This will allow user login with help of URL.We need construct simple URL with appropriate query string and that query string should have login parameters.

Parameter Auto Login Implementation:
  1. Add Parameter Auto Login class in the list auto.login.hooks
  2. Check company.security.auth.type
  3. Construct Login URL with appropriate parameters as query string

Add Parameter Auto Login class in the list auto.login.hooks :

Liferay already have Parameter Auto Login class to achieve parameter auto login so that we can use this class to enable parameter auto login.

We need to add this class in the list auto.login.hooks so that we can enable parameter auto login.

By default parameter auto login not enabled so we need to enable by adding Parameter Auto Login in the list auto.login.hooks .

We need to override auto.login.hooks   portal property by using portal-ext.properites file or simply create Liferay Hook Plugin and override the property

Default Property

auto.login.hooks=com.liferay.portal.security.auth.CASAutoLogin,
com.liferay.portal.security.auth.FacebookAutoLogin,
com.liferay.portal.security.auth.NtlmAutoLogin,
com.liferay.portal.security.auth.OpenIdAutoLogin,
com.liferay.portal.security.auth.OpenSSOAutoLogin,
com.liferay.portal.security.auth.RememberMeAutoLogin,
com.liferay.portal.security.auth.SiteMinderAutoLogin

Note:

In the above list we don’t have Parameter Auto login class.
Now Override auto.login.hooks with help of Liferay Hook Plugin or simply use portal-ext.properties file which is available in Liferay Home directory.

The following is overridden auto.login.hooks property


auto.login.hooks=com.liferay.portal.security.auth.CASAutoLogin,
com.liferay.portal.security.auth.FacebookAutoLogin,
com.liferay.portal.security.auth.NtlmAutoLogin,
com.liferay.portal.security.auth.OpenIdAutoLogin,
com.liferay.portal.security.auth.OpenSSOAutoLogin,
com.liferay.portal.security.auth.RememberMeAutoLogin,
com.liferay.portal.security.auth.SiteMinderAutoLogin, com.liferay.portal.security.auth.ParameterAutoLogin



Check company.security.auth.type

Now we need to check company.security.auth.type based on this we need to pass userId, email address or screen name as login parameters.

Based on desired login parameter we need to override the above property and by default its email address for liferay portal.

If we want change then we need to override above property with the help of Liferay Hook Plugin or portal-ext.properties file

The following is property available by default


    # The portal can authenticate users based on their email address, screen
    # name, or user id.
    #
    company.security.auth.type=emailAddress
    #company.security.auth.type=screenName
    #company.security.auth.type=userId


Note:

If we want change authentication type simply uncomments for required property and comment the current property this can be done from either portal-ext.properies or Liferay Hook Plugin.

Construct Login URL with appropriate parameters as query string

Once we have done above 2 steps then we need to construct Login URL with appropriate parameters in query string.

Parameter Auto login use the two parameters parameterAutoLoginLogin, parameterAutoLoginPassword to construct URL.

Based on company.security.auth.type we need to pass appropriate values like userId/emailAddress/screenName and password.

Example URL for authentication type Email Address




Example URL for Authentication type userId




Example URL for Authentication type Screen Name




Note:

When we hit above URLs in web browser then user automatically login to portal. Here we don’t need of sign in portlet to login.

Important points:

Here we simple use plain user name and password and this is not secured mechanism but we will use some encryption mechanism to encrypt user name and password.

Once it reaches Parameter Auto Login class there we decrypt the data and do the authentication. For this we need to customize the Parameter Auto Login class accordingly.


Author

Wednesday, March 26, 2014

Embedding a portlet in Web Content/Liferay Article

Introduction:

Some time we may need requirement to show portlet inside Web Content or Liferay Journal Content.

Liferay have feature to embedded portlet in web content. We have simple xml tag that will embed portlet in web content portlet.

We can embed portlet in web content in two ways
  1. Using <runtime-portlet/> xml tag
  2. Using Portlet sharing java script code snippet

Using <runtime-portlet/> xml tag

The following is simple tag which can embed portlet in web content.


<div id="my-embedded-portlet">
  <runtime-portlet name="47" instance="av33" queryString=""/>
</div>

The above tag have following attributes

Name: this is portlet name or portlet Id.
Instance: this is minimum 4 characters alpha numeric string which anything.
query String:  this will uses to pass some additional parameters using query string mode



Tip to know portlet Id and Instance Id for any portlet

Step: 1

Drag and drop desired portlet in any page



Step: 2

Go to portlet configuration

The following sample portlet which reside in page.


Step: 3

Find sharing tab and click on sharing then you can some java script code there you can see portlet id and instance id.

The following screen shows portlet id and instance id




Steps to Embedding portlet in web content

Step: 1

Drag and Drop the web content display portlet in any page


The following is blank web content display portlet in page



Step: 2

In the blank web content portlet you can find toggle button +add link and click on add link
Now provide web content title and in the Html editor (CK Editor) click on source button to add < runtime- portlet/> tag in the content editor


Step: 3

Now add run time portlet tag and pass portlet name/id and if portlet is instanceable then pass instance id as attributes

Assume we are going to add asset publisher portlet so this portlet is instanceable. We already know how to find portlet id and instance id

The following screen shows add portlet run time tag in web content



Finally click on publish button so that web content will be published and we can see asset publisher portlet in web content portlet.

The following screen shows asset publisher portlet inside web content display portlet


Using Portlet sharing java script code snippet

Liferay have default feature to share every portlet in anywhere in other websites. Liferay have provided java script code snippet to share portlet in other websites.

This is simple java script snippet and we can use in any html page so that we can see portlet. This portlet will be render as iframe in the page.

The following is steps to use Portlet sharing snippet in web content and to show portlet

Step: 1

Drag and drop desired portlet in any page



Step: 2

Go to portlet configuration


Step: 3

Find sharing tab and click on sharing then you can some java script code snippet and copy the code snippet



Step: 4

Drag and Drop the web content display portlet in any page


The following is blank web content display portlet in page



Step: 5

In the blank web content you can find toggle button +add link click on add link
Now give Web content name and in the Html editor (CK Editor) click on source button to portlet sharing java script code snippet



Step: 6

Add the portlet sharing java script code snippet in web content editor that is we already copy



Finally click on publish button so that web content will be published and we can see asset publisher portlet in web content portlet.

The following screen shows asset publisher portlet inside web content display portlet.




Note:

When we want share portlet and want to use portlet in other places we need consider following things

We need to add following xml tag in portlet liferay-portlet.xml file


<add-default-resource>true</add-default-resource>
<system>true</system>


Also need to consider following property (if required add portlet id in the following property list)


portlet.add.default.resource.check.whitelist=3,56_INSTANCE_0000,
58,82,86,87,88,103,113,145,164,166,170,177,
PortletY_WAR_OpenPortletAuiDialgportlet


More about Portlet ID and Instance Id

Generating Portlet ID for Plugin portlet for single instance portlet

The Portlet Id pattern is following


PortletName_WAR_PluginPortletCotextName

Portlet Name:

You can find the portler Name in portlet.xml file as the tag 
<portlet-name>PortletX</portlet-name>

_WAR

 This constant string for any plug-in portlet

Plug-in Portlet Context Name:

This is context of your plug-in portlet after deployment.

This name you can find in portlet build.xml file of your portlet

The following is Example:

 build.xml file as follows

<?xml version="1.0"?>
<!DOCTYPE project>
<project name="OpenPortletAuiDialg-portlet" basedir="." default="deploy">
            <import file="../build-common-portlet.xml" />
</project>

Example of portlet Id for single instance portlet:


PortlrtY_WAR_ OpenPortletAuiDialg-portlet

Multi Instance Portlets

When portlet is multi instance then we can more portlets to one page.

We need to add following tag in liferay-portlet.xml file and values should be true

<instanceable>true</instanceable>

When we add the tag then we can add same portlet for multiple in the page.

Make sure tag position in
 liferay-portlet.xml file

Example:

<portlet>
                        <portlet-name>PortletY</portlet-name>
                        <icon>/icon.png</icon>
                        <instanceable>true</instanceable>
                        <header-portlet-css>/css/main.css</header-portlet-css>
                        <footer-portlet-javascript>
                                    /js/main.js
                        </footer-portlet-javascript>
                        <css-class-wrapper>portlety-portlet</css-class-wrapper>
                        <add-default-resource>true</add-default-resource>
</portlet>

Generating Portlet Id to single instance portlet

The Portlet Id pattern like


PortletName_WAR_PluginPortletCotextName_
INSTANCE_4CharectesAlphaNumeriString

Portlet Name

You can find the portlet Name in portlet.xml file as the tag
<portlet-name>PortletX</portlet-name>

_WAR_

This constant string for any plug-in portlet

Plug-in Portlet Context Name:

This is context of your plugin portlet after deployment.
This name you can find in build.xml file of your portlet.

_INSTANCE_

 This is another constant string for multiple instance portlets.

4 or more Characters Alpha Numeric String (your choice):

 Any string which consist of alphabets and numeric character

Example as follows

vD3e

Example Portlet Id for Multiple Instance Portlet:


PortletX_WAR_OpenPortletAuiDialgportlet_INSTANCE_vD3B

Note:

To make unique id for portlet they have used such pattern.

Author

Recent Posts

Recent Posts Widget

Popular Posts