Posts

Showing posts from September, 2014

Auditing the sucessful logged-in users in liferay

In Liferay we have some events to like application startup, global events, login events and many more. If we want to audit the login user on which IP address he logged-in in liferay we have events like 1.login.events.pre 2.login.events.post login.events.pre : Which Executes Before Login Action. login.events.post: Which Excutes After Login. we want to track the user login on which IP Address used so we will write the login.events.post which will be execute after login completes. In Portal.Properties login.events.post = com.sample.hook.LoginSuccessAudit. Create a class called LoginSuccessAudit public class LoginSuccessAudit extends Action { @Override public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {                    User user = PortalUtil.getUser(request);                    System.out.println("IP Address is"+user.getLoginIP());             } } By this we can audit the successfully logged-in use

Audting the Login Failure in liferay

In Liferay we can audit login failure for the user just by writing the hook. We have property which we need to add in portal.properties file as.        auth.failure = com.sample.events.hook.LoginFailureAudit. Then create a class and extend with the AuthFailure public class LoginFailureAudit implements AuthFailure {      public void onFailureByEmailAddress(long companyId, String emailAddress, Map<String, String[]> headerMap, Map<String, String[]> parameterMap) throws AuthException { long userId = UserLocalServiceUtil.getUserByScreenName(companyId, emailAddress).getUserId(); User user = UserLocalServiceUtil.getUser(userId); System.out.println("login failure attempts are"+user.getFailedLoginAttempts()); } public void onFailureByScreenName(long companyId, String screenName, Map<String, String[]> headerMap, Map<String, String[]> parameterMap) throws AuthException { long userId = UserLocalServiceUtil.getUserByScreenName(companyId,

Refreshing the portlet at certain intervals in liferay

In our Project we have requirement to refresh the portlet at certain interval of times. Thanks to liferay we have utility method to get the refreshURL. Have a look into the  PortletURLUtil class. we have  getRefreshURL (---....)  method to the current portlet URL. So we have used in the following way in the jsp. As already we know "request" and "themeDisplay" Objects are predefined objects. <%@page import="com.liferay.portlet.PortletURLUtil"%> <script type="text/javascript"> setTimeout(openUrl, 5000); // Wait 5 seconds function openUrl(){    window.open('<%=PortletURLUtil.getRefreshURL(request, themeDisplay) %>'); } </script> Thats it will refresh the portlet for every 5 seconds. In  PortletURLUtil   also we have one more method to clone the URL,  clone (----) public static PortletURL clone( PortletURL portletURL, MimeResponse mimeResponse) throws PortletException { ---- --- }

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate

Sometimes we have to know SQL query hiting in DB to retrieve the list. Suppose When we are writing the DynamicQuery , Some times we have to know SQL query it is generating to hit DB. So generally it is useful when we are debugging the Query it is generated. In hibernate we used the write the property in XML file as hibernate.show.sql to view the query. In Liferay also we can also set the below property to true in the portal-ext.properties to view the SQL query at the console. hibernate.show_sql=true. By adding the above property it will just reterive the parameters. What if we want to display the parameters. Add the below properties in log4j.properties it will display the paramters also. # logs the SQL statements #log4j.logger.org.hibernate.SQL=debug # Logs the JDBC parameters passed to a query #log4j.logger.org.hibernate.type=trace In Liferay log4j is located in the below location tomcat-7.0.42\webapps\ROOT\WEB-INF\classes Also we want to see hibernate ses

Reindex the documents

Whenever we are using the lucene search, sometimes content is not able to search even it is present. so we need to reindex the content in the control panel of the server adminstration. We have one more option, when we add the below property it will index the content during the server startup, so manually it is not required to reindex the content in the control panel. So add the below property in the "portal-ext.properties". so it will index during the startup.       # Set this to true if you want to index your entire library of files on     # startup. This property is available so that automated test environments     # index on startup. Do not set this to true on production systems or else     # your index will be indexed on every startup.     #     index.on.startup=true.