Sample Remember Me cookie Portlet

This sample Portlet demonstrate how to use Remember Me cookie service to find out userId for the user on anonymous page.

public class RememberMePortlet extends javax.portlet.GenericPortlet {
PortletServiceHome psh;
* @see javax.portlet.Portlet#init()
public void init() throws PortletException{
try {
javax.naming.Context ctx = new javax.naming.InitialContext();
psh = (PortletServiceHome)ctx.lookup(RememberMeCookieService.JNDI_NAME);
} catch (NamingException e) {
// TODO Auto-generated catch block

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response

try {
RememberMeCookieService rememberMeService = psh.getPortletService(RememberMeCookieService.class);
System.out.println("RememberMeCookie is enabled");
System.out.println("User Name " + rememberMeService.getUserID(request));
System.out.println("Is Remember Me Cookie Set " + rememberMeService.isCookieSet(request));
response.getWriter().println("Invalidate remember me cookie");
System.out.println("RememberMeCookie is disabled");
} catch (SecurityException e) {

You can download this portlet from here

No comments: