Foren
Icefaces redirect while impersonating
Bill Gosse, geändert vor 13 Jahren.
Icefaces redirect while impersonating
Liferay Master Beiträge: 533 Beitrittsdatum: 04.07.10 Neueste Beiträge
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?
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?
Bill Gosse, geändert vor 13 Jahren.
RE: Icefaces redirect while impersonating (Solved)
Liferay Master Beiträge: 533 Beitrittsdatum: 04.07.10 Neueste Beiträge
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!
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, geändert vor 8 Jahren.
RE: Icefaces redirect while impersonating (Solved)
New Member Beitrag: 1 Beitrittsdatum: 03.02.15 Neueste Beiträge
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.
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.