-
1. Re: How can I get current portal user from javax.portlet.Por
freesoul Apr 20, 2008 7:08 AM (in response to freesoul)Yesterday I can't understand jboss portlet container very well, so I didn'i konw the relationship between javax.portlet.ActionRequest and org.jboss.portlet.JBossActionRequest, but now I get it.
public class org.jboss.portlet.JBossActionRequest extends org.jboss.portal.portlet.impl.jsr168.api.ActionRequestImpl { }
and implements javax.portlet.ActionRequest interface.
So we can get current user in struts2 like that:((org.jboss.portlet.JBossActionRequest) PortletActionContext .getActionRequest()).getUser();
-
2. Re: How can I get current portal user from javax.portlet.Por
csagar Apr 28, 2008 7:08 AM (in response to freesoul)Hi freesoul.
i am stuck with the same problem of retriving the current logge in user of the portal.I have this code with me,
--------------------------------------------------------------------------------------
/*****************************************
* *
* JBoss Portal: The OpenSource Portal *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
*****************************************/
package org.jboss.portlet1.hello;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.UnavailableException;
import org.jboss.portal.api.PortalRuntimeContext;
import org.jboss.portal.api.navstate.NavigationalStateContext;
import org.jboss.portal.api.session.PortalSession;
import org.jboss.portal.core.controller.ControllerContext;
public class HelloWorldJSPPortlet extends GenericPortlet implements PortalRuntimeContext
{
private ControllerContext ctx;
private PortalSession psession;
private String userId;
/*private UserProfileModule userProfileModule;*/
/*@Override
public void init(PortletConfig config) throws PortletException {
// TODO Auto-generated method stub
super.init(config);
userProfileModule = (UserProfileModule)getPortletContext().getAttribute("UserProfileModule");
}*/
protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
{
rResponse.setContentType("text/html");
//PortalRuntimeContext context=(PortalRuntimeContext)this.getPortletContext();
//userId=context.getUserId();
//ControllerContext ctx;
//userId=getUserId();
//System.out.println("user:"+userId);
String sYourName = (String) rRequest.getParameter("yourname");
if(sYourName != null)
{
rRequest.setAttribute("yourname", sYourName);
PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view2.jsp");
prd.include(rRequest, rResponse);
}
else
{
//rRequest.setAttribute("yourname", userId);
PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view.jsp");
prd.include(rRequest, rResponse);
}
}
public void processAction(ActionRequest aRequest, ActionResponse aResponse) throws PortletException, IOException, UnavailableException
{
String sYourname = (String) aRequest.getParameter("yourname");
// do something
aResponse.setRenderParameter("yourname", sYourname);
}
protected void doHelp(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
{
rResponse.setContentType("text/html");
PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/help.jsp");
prd.include(rRequest, rResponse);
}
protected void doEdit(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
{
rResponse.setContentType("text/html");
PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/edit.jsp");
prd.include(rRequest, rResponse);
}
public NavigationalStateContext getNavigationalStateContext() {
// TODO Auto-generated method stub
return null;
}
public PortalSession getSession() {
// TODO Auto-generated method stub
return null;
}
public String getUserId() {
// TODO Auto-generated method stub
//((org.jboss.portlet.JBossActionRequest) PortletContext
// .getActionRequest()).getUser();
return null;
}
}
-----------------------------------------------------------------------------
This is the sample code provided in helloworldjspportlet zip here---
I need to get the current user of the system to display a jsp page in the portlet. According to docs ,i tried to implement the PortalRuntimeContext interface , but no success.....
You seem to be successful in it.however i am not using the struts framework. is it possible to retrieve the current user ?
waiting for reply.
thanks
csagar -
3. Re: How can I get current portal user from javax.portlet.Por
rivetlogic May 6, 2008 12:58 PM (in response to freesoul)Hi,
request.getRemoteUser() should give you the currently logged in user or null if not logged in. You could use the UserModule or UserProfileModule JNDI entries to get the necessary user information.
Regards,
Shagul -
4. Re: How can I get current portal user from javax.portlet.Por
yogessr May 7, 2008 1:32 AM (in response to freesoul)Hi,
You can use the below mentioned API to get the currently logged in user
renderRequest.getUserPrincipal().getName();
or
actionRequest.getUserPrincipal().getName();