我正在 Liferay 7 中实现自定义登录 - 一个用于登录挂钩 portlet 的模块,一个用于 ActionCommand 的模块。
我还为登录后事件生成了类。问题是重定向在此类或登录挂钩 porlet 的 JSP 上都不起作用。
这是我的 LifecycleAction 代码:
@Component(
immediate = true,
property = {
"key=login.events.post"
},
service = LifecycleAction.class
)
public class UserLoginPostAction implements LifecycleAction {
private static final Log LOGGER = LogFactoryUtil.getLog(UserLoginActionCommand.class);
@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
HttpServletRequest request = lifecycleEvent.getRequest();
HttpServletResponse response = lifecycleEvent.getResponse();
HttpSession session = request.getSession();
try {
User currentUser = PortalUtil.getUser(request);
LOGGER.info("USER|" + currentUser.getFirstName() + "|" + currentUser.getGroup().toString());
LOGGER.info("LASTPATH|" + session.getAttribute("LAST_PATH"));
LastPath lastPath = (LastPath) session.getAttribute("LAST_PATH");
LOGGER.info(lastPath.getPath());
session.setAttribute(WebKeys.LAST_PATH, lastPath);
response.sendRedirect(lastPath.getPath());
} catch (PortalException | IOException exception) {
LOGGER.error(exception);
}
}
}
这是我的 portlet 登录 JSP 代码:
<c:choose>
<c:when test="<%= themeDisplay.isSignedIn() %>">
<%
response.sendRedirect(WebKeys.LAST_PATH);
%>
</c:when>
<c:otherwise>
...
我的记录器能够在控制台上显示正确的值。
谢谢。
登录后的转发有点棘手。
如果您使用 LAST_PATH 和会话属性,则不需要发送重定向行,因为这将由 Liferay 处理。最后一个路径可能会受到 URL 参数的影响,如“重定向”。
如果您要使用发送重定向方法。构建您的 URL,然后将您创建的 URL 传递到 sendRedirect() 调用。不要使用会话参数。
PS:如果您要修改登录名,请查看认证管道 https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/authentication-pipelines而是对登录 portlet 进行大量覆盖。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)