You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by "R.T.H.Chin" <r....@tbm.tudelft.nl> on 2005/07/22 10:42:50 UTC
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
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org
Re: JS1.6 JSR168 portlets: cannot get username
Posted by David Sean Taylor <da...@bluesunrise.com>.
R.T.H.Chin wrote:
> 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();
>
You need to configure a JAASSessionValidator
org.apache.jetspeed.modules.actions.JAASSessionValidator
Here are the instructions from the javadocs:
/**
* JAAS Session validator populates the Jetspeed User via the
servlet.getUserPrincipal() call
* When using this session validator, Authentication is delegated to
the Application Server.
* Recommend disabling all user login functionality via Jetspeed, and
using your web.xml
* to protect access to all Jetspeed resources (place after
resource-ref or welcome-file-list:
*
* <security-constraint>
* <display-name>Jetspeed Security</display-name>
* <web-resource-collection>
* <web-resource-name>Protected Area</web-resource-name>
* <!-- Define the context-relative URL(s) to be protected -->
* <url-pattern>/*</url-pattern>
*
* <!-- If you list http methods, only those methods are protected -->
* <http-method>DELETE</http-method>
* <http-method>GET</http-method>
* <http-method>POST</http-method>
* <http-method>PUT</http-method>
* </web-resource-collection>
* <auth-constraint>
* <!-- Anyone with one of the listed roles may access this area -->
* <role-name>user</role-name>
* <role-name>admin</role-name>
* </auth-constraint>
*
* <!--
* <user-data-constraint>
* <transport-guarantee>CONFIDENTIAL</transport-guarantee>
* </user-data-constraint>
* -->
* </security-constraint>
*
* <login-config>
* <auth-method>BASIC</auth-method>
* <realm-name>Jetspeed BASIC Authentication</realm-name>
* </login-config>
*
* <!-- Default login configuration uses form-based authentication -->
* <!--
* <login-config>
* <auth-method>FORM</auth-method>
* <realm-name>Example Form-Based Authentication Area</realm-name>
* <form-login-config>
*
<form-login-page>/jsp/security/protected/login.jsp</form-login-page>
*
<form-error-page>/jsp/security/protected/error.jsp</form-error-page>
* </form-login-config>
* </login-config>
* -->
*
* <!-- Security roles referenced by this web application -->
* <security-role>
* <role-name>admin</role-name>
* </security-role>
* <security-role>
* <role-name>user</role-name>
* </security-role>
* <security-role>
* <role-name>guest</role-name>
* </security-role>
*
* Place the following the the servlet element where the Turbine
servlet is defined:
*
* <security-role-ref>
* <role-name>user</role-name> <!--passed to isUserInRole()-->
* <role-link>user</role-link> <!--Jetspeed role name-->
* </security-role-ref>
*
* <security-role-ref>
* <role-name>admin</role-name>
* <role-link>admin</role-link>
* </security-role-ref>
*
* <security-role-ref>
* <role-name>guest</role-name>
* <role-link>guest</role-link>
* </security-role-ref>
*
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org
Re: JS1.6 JSR168 portlets: cannot get username
Posted by Ruwan Abeykoon <ru...@srilogic.com>.
Hi Chin,
Chin, discard the solution in my earlier reply.
The method described by David, would help me as well. Thanks.
Regards,
Ruwan.
----- Original Message -----
From: "R.T.H.Chin" <r....@tbm.tudelft.nl>
To: "Jetspeed Developers List" <je...@portals.apache.org>
Sent: Monday, July 25, 2005 12:54 PM
Subject: Re: JS1.6 JSR168 portlets: cannot get username
> Hi Ruwan,
>
> I was hoping for a more simple solution, but thanks anyway. I will try
this.
>
> Kind regards,
> Roy Chin
>
> Ruwan Abeykoon wrote:
>
> >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.
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org
Re: JS1.6 JSR168 portlets: cannot get username
Posted by "R.T.H.Chin" <r....@tbm.tudelft.nl>.
Hi Ruwan,
I was hoping for a more simple solution, but thanks anyway. I will try this.
Kind regards,
Roy Chin
Ruwan Abeykoon wrote:
>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....@tbm.tudelft.nl>
>To: "Jetspeed Developers List" <je...@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
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org
Re: JS1.6 JSR168 portlets: cannot get username
Posted by Ruwan Abeykoon <ru...@srilogic.com>.
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....@tbm.tudelft.nl>
To: "Jetspeed Developers List" <je...@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