Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use auto login in liferay

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.06k
    Comment on it

    Hello Guys

    I am writing blog to develop auto login logic in liferay. Liferay provide auto login functionality, So we can login by screenName, userId and email address parameter's.

    We need to create hook to implement AutoLogin interface, so follow below steps to create auto login in liferay.

    Step 1: Create CustomAutoLogin.java and put below code :

    public class CustomAutoLogin implements AutoLogin {
        public String[] login(HttpServletRequest request,
                HttpServletResponse response) throws AutoLoginException {
    
            String emailAddress = request.getParameter("emailAddress");// login by email address
            if (emailAddress == null || emailAddress.isEmpty())
                return null;
    
            try {
                long companyId = PortalUtil.getCompanyId(request);
                User user = UserLocalServiceUtil.getUserByEmailAddress(companyId,
                        emailAddress);
                return new String[] { String.valueOf(user.getUserId()),
                        user.getPassword(),
                        String.valueOf(user.isPasswordEncrypted()) };
            } catch (Exception e) {
                return null;
            }
    
        }
    } 
    

    Step 2: Create hook :

    <?xml version="1.0"?>
    <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd">
    
    <hook>
        <portal-properties>portal.properties</portal-properties>
    </hook>
    

    Put below property in portal.properties :

    auto.login.hooks=com.bhagwan.CustomAutoLogin
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: