Page Banner

Access API method without user authentication in Liferay 6.2

While building a full-fledged web project is greatly leveraged by Liferay, it might so happen that we require to access some API method before the user is authenticated, where a common example could be a custom login hook. In the normal scenario, such method access would generate a security exception. In such cases we have to explicitly expose the method for guest access, which can be achieved simply by adding an annotation above the method definition in the implementing class for that method, like so:

public class MyClassServiceImpl extends MyClassServiceBaseImpl {

@AccessControlled(guestAccessEnabled=true)         /*To make this method 

                                                   accessible without logging in*/

    public int methodOne() throws PortalException, SystemException


       //Do something

       return resultOne;


    public int methodTwo() throws PortalException, SystemException /*Method not accessible



       //Do something else

       return resultTwo;



Princeton IT is the leading software development company in USA. Get in touch!