I'm working on a servlet within a Liferay portal environment and need to check user permissions to determine if a user has access to view a specific file. However, I'm encountering difficulties accessing the necessary context and objects to perform these permission checks.
Servlet code snippet to get permissionchecker object but it returns null
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.PermissionThreadLocal;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
}
}
What are the steps should I follow to get this permission check object. My aim is to check whether the user which hitting the servlet URL have access to view the file or not.
I would follow the approach to get credentials from what you provided so far, the
requestin that case, and according to the answers, authorize or associate exceptions to response codes