Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
William Gosse
Icefaces redirect while impersonating
February 25, 2011 9:24 AM
Answer

William Gosse

Rank: Regular Member

Posts: 249

Join Date: July 4, 2010

Recent Posts

I’m doing page redirects form my IceFaces portlets with the following code:

FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
try {
externalContext.redirect(parentRedirect);
} catch (IOException e) {
s_log.error(e.getMessage(), e);
}

This works fine but if I’m impersonating another user in Liferay I get switched back to me.

I imagine the FacesContext knows nothing about my impersonation.

Does anyone know anyway for me to have my cake and eat it too?
William Gosse
RE: Icefaces redirect while impersonating (Solved)
February 25, 2011 1:33 PM
Answer

William Gosse

Rank: Regular Member

Posts: 249

Join Date: July 4, 2010

Recent Posts

With some help from Neil Griffin I got this to work:

public static void doRedirect(String redirect) {

try {
long doAsUserId = getUser().getUserId();
long realUserId = getThemeDisplay().getRealUser().getUserId();
if (doAsUserId != realUserId) {
Company company = getThemeDisplay().getCompany();
String encDoAsUserId = Encryptor.encrypt(company.getKeyObj(),
String.valueOf(doAsUserId));
redirect += "?doAsUserId=" + encDoAsUserId;
}

FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
externalContext.redirect(redirect);
} catch (Exception e) {
_log.error(e);
}
}


Thanks Nell!
Jarred Keuch
RE: Icefaces redirect while impersonating (Solved)
June 25, 2015 11:57 AM
Answer

Jarred Keuch

Rank: New Member

Posts: 1

Join Date: February 3, 2015

Recent Posts

Works for me. Thanks!

One modification...

redirect += "?doAsUserId=" + encDoAsUserId;
should be
redirect += "?doAsUserId=" + URLEncoder.encode(encDoAsUserId, "UTF-8");

We ran into cases that didn't work without the URL encoding.