portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ruwan Abeykoon" <ru...@srilogic.com>
Subject Re: JS1.6 JSR168 portlets: cannot get username
Date Fri, 22 Jul 2005 15:16:24 GMT
Hi,
I had the same problem, solved in the following way. I do not know whether
the solution it is good.

outline of the solution,
created Pluto factory for render request and action requests.
overridden Pluto RenderRequestImpl and ActionRequestImpl
introduces the custom factories in conf/assembly/pluto-factories.xml

I have provided the code fragments with this. Some customized fragments are
removed.

Regards,
Ruwan.


class
com.srilogic.portal.jetspeed.fusion.engine.request.factory.ActionRequestFact
ory
----------------------------------------------------------------------------
---------

package com.srilogic.portal.jetspeed.fusion.engine.request.factory;

import java.util.Map;

import javax.portlet.ActionRequest;
import javax.servlet.ServletConfig;

import org.apache.pluto.factory.ActionRequestFactory;
import org.apache.pluto.om.window.PortletWindow;

import
com.srilogic.portal.jetspeed.fusion.engine.request.impl.ActionRequestImpl;

/**

 *
 * To change this generated comment edit the template variable
"typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class ActionRequestFactoryImpl implements ActionRequestFactory {

    /**
     * @see org.apache.pluto.factory.Factory#init(ServletConfig, Map)
     */
    public void init(ServletConfig config, Map properties) throws Exception
{
    }

    // org.apache.pluto.factory.ActionRequestFactory
implementation -------------------------------
    public ActionRequest getActionRequest(PortletWindow portletWindow,

javax.servlet.http.HttpServletRequest servletRequest,

javax.servlet.http.HttpServletResponse servletResponse)
    {
        ActionRequest actionRequest = new ActionRequestImpl(portletWindow,
servletRequest);
        return actionRequest;
    }




// -------------------------------------------------------------------------
-------------------

    // additional
methods --------------------------------------------------------------------
-----
    /**
     * @see org.apache.pluto.factory.Factory#destroy()
     */
    public void destroy() throws Exception {
    }




// -------------------------------------------------------------------------
-------------------
}


class
com.srilogic.portal.jetspeed.fusion.engine.request.factory.RenderRequestFact
oryImpl
same as ActionRequestFactoryImpl implements RenderRequestFactory
----------------------------------------------------------------------------
---------------

class
com.srilogic.portal.jetspeed.fusion.engine.request.impl.ActionRequestImpl
----------------------------------------------------------------------------
----
package com.srilogic.portal.jetspeed.fusion.engine.request.impl;

import java.security.Principal;

import javax.portlet.ActionRequest;
import javax.portlet.PortletPreferences;
import javax.servlet.http.HttpSession;

import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
import org.apache.pluto.om.window.PortletWindow;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.rundata.RunDataService;

import
com.srilogic.portal.jetspeed.fusion.engine.request.factory.FusionRequestServ
ice;
import
com.srilogic.portal.jetspeed.service.security.ConnectEyeFacadeService;

/**
 * @author ruwan
 * Provides the jetspeed fusion bridge for couple of methods and
 */
public class ActionRequestImpl extends
org.apache.pluto.core.impl.ActionRequestImpl implements ActionRequest
{


    public ActionRequestImpl(PortletWindow portletWindow,
                             javax.servlet.http.HttpServletRequest
servletRequest)
    {
        super(portletWindow, servletRequest);
    }
 public Principal getUserPrincipal()
 {
  JetspeedRunDataService runDataService =
  (JetspeedRunDataService)TurbineServices.getInstance()
   .getService(RunDataService.SERVICE_NAME);

 User jsUser =runDataService.getCurrentRunData().getUser();
 if(jsUser = null)
  {
  return null;
 }
 if(JetspeedSecurity.getAnonymousUserName().equals(jsUser.getUserName()))
 {
  return null;
 }
//TODO:implement some principal reuse mechanism
 FusionPrincipal principal = new FusionPrincipal(jsUser.getUserName());
 return principal;
 }

 /* (non-Javadoc)
  * @see javax.servlet.http.HttpServletRequest#getAuthType()
  */
 public String getAuthType()
 {
  JetspeedRunDataService runDataService =
    (JetspeedRunDataService)TurbineServices.getInstance()
       .getService(RunDataService.SERVICE_NAME);
  return runDataService.getCurrentRunData().getRequest().getAuthType();
 }
}


class
com.srilogic.portal.jetspeed.fusion.engine.request.impl.RenderRequestImpl
same as
com.srilogic.portal.jetspeed.fusion.engine.request.impl.ActionRequestImpl
extend from org.apache.pluto.core.impl.RenderRequestImpl
----------------------------------------------------------------------------
------


in conf/assembly/pluto-factories.xml change the following fragments
-------------------------------------------------------------------

  <bean id="javax.portlet.ActionRequest"

class="org.apache.jetspeed.components.factorybeans.PlutoFactoryFactoryBean"
  >
       <!-- property
name="className"><value>org.apache.pluto.factory.impl.ActionRequestFactoryIm
pl</value></property-->
       <property
name="className"><value>com.srilogic.portal.jetspeed.fusion.engine.request.f
actory.ActionRequestFactoryImpl</value></property>
       <property name="servletConfig"><ref
bean="javax.servlet.ServletConfig"/></property>
  </bean>

  <bean id="javax.portlet.RenderRequest"

class="org.apache.jetspeed.components.factorybeans.PlutoFactoryFactoryBean"
  >
  <!--property
name="className"><value>org.apache.pluto.factory.impl.RenderRequestFactoryIm
pl</value></property-->
  <property
name="className"><value>com.srilogic.portal.jetspeed.fusion.engine.request.f
actory.RenderRequestFactoryImpl</value></property>
       <property name="servletConfig"><ref
bean="javax.servlet.ServletConfig"/></property>
       <property name="props">
        <map>
         <entry key="myproperty">
          <value>myvalue</value>
         </entry>
        </map>
       </property>
  </bean>



----- Original Message -----
From: "R.T.H.Chin" <r.t.h.chin@tbm.tudelft.nl>
To: "Jetspeed Developers List" <jetspeed-dev@portals.apache.org>
Sent: Friday, July 22, 2005 2:42 PM
Subject: JS1.6 JSR168 portlets: cannot get username


> Hi,
>
> I am developing some portlets for Jetspeed1.6 according to the Java
> Portlet Specification. Everything works fine except for one thing: I
> cannot get the username of the client. These all return null:
>
> request.getAuthType();
> request.getRemoteUser();
> request.getUserPrincipal();
>
> On the other hand this works fine:
>
> Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
>
> However, as far as I know I can only use this to retreive
> user.name.given, user.name.family etc. but no username. I need the
> username to store a unique identifier for a user, for example when
> making forum posts.
>
> Is there any way to solve this?
>
> Thanks in advance,
> Roy Chin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message