• AuthType:3 Ways to Login Liferay

    Posted on December 13, 2015 by Hamidul Islam in Liferay.

    liferay-authentication-type


    aim

    In this article we will see whats authtype in Liferay. Authtype is simply authentication type in liferay portal. When we login into liferay portal we use liferay out of box sign in portlet. This sign in portlet use authType String to determine the type authentication.


    Liferay uses 3 types of authentication to login. These are

    • By Email Address
    • By Screen Name
    • By User Id

    This  can be configured in the run time through control panel.

    authType

    On the basis of this configuration liferay sign in portlet will look different. So if the authentication type is Email Address then Sign In portlet will show Email Address to enter. Similarly the Sign In portlet will show Screen Name if the authType is Screen Name and so on.

    Code for getting authType:

    Sometime we have to know whats the authType in our code while development. The authType can be retrieved from company object. But Company in Liferay is actually is an interface which is in com.liferay.portal.model package. So how can we get company object? Here is the code

    Using predefined company object in JSP

    <%@page import="com.liferay.portal.util.PortalUtil"%>
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%>

    <portlet:defineObjects />
    <theme:defineObjects />

    <%
    String authType = company.getAuthType();
    out.println(authType);
    %>

    From themeDisplay get company object then authType

    <%@page import="com.liferay.portal.util.PortalUtil"%>
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%>

    <portlet:defineObjects />
    <theme:defineObjects />

    <%
    String authType = themeDisplay.getCompany().getAuthType();
    out.println(authType);
    %>

    Using PortalUtil

    <%@page import="com.liferay.portal.util.PortalUtil"%>
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%>

    <portlet:defineObjects />
    <theme:defineObjects />

    <%
    String authType = PortalUtil.getCompany(request).getAuthType();
    out.println(authType);
    %>

    In the above we have used JSP for code snippets. We can also get authType in portlet class either using PortalUtil class or using ThemeDisplay object.

    Additional Information:

    In liferay source code there is a class CompanyConstants which defines three constants for authType

    com.liferay.portal.model.CompanyConstants

    public static final String AUTH_TYPE_EA = "emailAddress";

    public static final String AUTH_TYPE_ID = "userId";

    public static final String AUTH_TYPE_SN = "screenName";

    We can use the above three constants something like below

    if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {

    //Authentication by email

    }else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {

    //Authntication Screen Name

    }else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {

    //Authentication by User Id

    }

2 Responses so far.

  1. Hassan Bakri says:

    Hi Mr Hamidul Islam I'm Wondering How I could Implement Tow-Way Authentication (like in gmail) in Liferay

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

Top
%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close