Foros de discusión
Icefaces redirect while impersonating
Bill Gosse, modificado hace 13 años.
Icefaces redirect while impersonating
Liferay Master Mensajes: 533 Fecha de incorporación: 4/07/10 Mensajes recientes
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, modificado hace 13 años.
RE: Icefaces redirect while impersonating (Solved)
Liferay Master Mensajes: 533 Fecha de incorporación: 4/07/10 Mensajes recientes
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, modificado hace 8 años.
RE: Icefaces redirect while impersonating (Solved)
New Member Mensaje: 1 Fecha de incorporación: 3/02/15 Mensajes recientes
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.