Re: Authentication of AJAX requests from Portlet

Khaled TLILI <[email protected]> Fri, 16 Nov 2007 12:54:51 +0100
Newsgroups gmane.comp.cms.jahia.devel
Message-ID <[email protected]>
Hi,

First time you access a page whith a portlet, the method render() is 
executed. During this method, you can save the remote user and its roles 
in the session APPLICATION_SCOPE.
Then, from a httpServletRequest you can access to these values from the 
session.

A generic solution is to create an Object that will wrapper all shared 
values between portlets and servlets.

Example
======
class SharedValues {
private int remoteUser;
private String[] roles;

/*getter and setter*/
....
}


------------------------------------

renderRequest(...){
....
SharedValues sv = 
(SharedValues)portletSession.getAttribute("com.myapp.sharedValues",PortletSession.APPLICATION_SCOPE);
if(sv == null){
     SharedValues sv = new SharedValues();
   /*fill shared values*/
   ...
   
portletSession.setAttribute("com.myapp.sharedValues",sv,PortletSession.APPLICATION_SCOPE)
}
}

------------------------------------

SharedValues sv = (SharedValues) HttpServletRequest.getSession().getAttribute("com.myapp.sharedValues")


Regards,
KT.




[email protected] a écrit :
> Hi,
>
> We are developing a number of Portlets and are planning to make heavy use
> of AJAX to prevent page loads. We are authenticating to the Jahia server
> using LDAP, and we want to use the userid to track who has created/updated
> records in our application database. We are also mapping LDAP groups to
> Roles (defined in web.xml) and want to programmatically decide what
> functionality is available based on the role.
>
> In a simple test application we can retrieve the userid using
> PortletRequest.getRemoteUser() in Portlet code, but it is not available
> from HttpServletRequest.getRemoteUser() for AJAX requests to servlets in
> our Portlet WebApp. We have the same problem with roles - they are
> available in the Portlet, but not in Servlets (or JSPs rendered from
> Servlets called via an AJAX request).
>
> Is there any way that we can authenticate our AJAX calls so that they have
> the same user and roles as Portlet requests?
>
> Thanks,
> Andrew May
> IT - Sr. Developer
> Abercrombie & Fitch
>
> _______________________________________________
> dev_list mailing list
> [email protected]
> http://lists.jahia.org/cgi-bin/mailman/listinfo/dev_list
>
>   

_______________________________________________
dev_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/dev_list