Site icon Pro Liferay

AuthType:3 Ways to Login Liferay

liferay-authentication-type


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

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

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

[example title=”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);
%>

[/example]

[example title=”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);
%>

[/example]

[example title=”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);
%>

[/example]

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

[example title=”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”;

[/example]

We can use the above three constants something like below

[example]

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

}

[/example]

Exit mobile version