Explicitly Logout the User programmatically in Websphere Portal 8 & redirect to the default login page

一个人想着一个人 提交于 2019-12-10 19:53:01

问题


I am a bit new to WS portal & have a requirement wherein on a specific scenario we want the user to logout & redirect him to the default portal login page. I have tried to invalidate the session clear the cookies & do a response.sendRedirect as in response.sendRedirect("/wps/myportal/"); , but in vain. Please guide.


回答1:


You can configure logout page using wp_configservice:

redirect.logout=true
redirect.logout.ssl=false
redirect.logout.url=protocol://host_name/logout_page

After configuring it, clicking on standard logout will redirect you to the specified page.




回答2:


If you're using JSF portlets, you can do something along the lines of the following - this should actually log the user session out as well as returning them to the default login page.

In reality you'll probably want to consider caching the initial context lookup by moving out the lookup code ( Context ctx = new InitialContext(); PortletServiceHome stateMgrServiceHome = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.state.service.PortletStateManagerService");)

public void doLogOut() 
{
     String logoutUrl = generateLogoutURL(getPortletRequest(), getPortletResponse());
     redirectToUrl(logoutUrl);

}

    public String generateLogoutURL(PortletRequest request, PortletResponse response) throws RpmPortalException {
            final String methodName = "generateLogoutURL";
            String logoutURL = "";
            Context ctx = new InitialContext();
            PortletServiceHome stateMgrServiceHome = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.state.service.PortletStateManagerService");
            PortletStateManager stateMgr = null;

            LogoutActionAccessorController logoutCtrl = null;
            try {
                stateMgr = stateMgrService.getPortletStateManager(request, response);

                final URLFactory urlFactory = stateMgr.getURLFactory();
                EngineURL url = urlFactory.newURL(null);

                LogoutActionAccessorFactory logoutFct = (LogoutActionAccessorFactory) stateMgr.getAccessorFactory(LogoutActionAccessorFactory.class);
                logoutCtrl = logoutFct.newLogoutActionController(url.getState());

                logoutURL = url.writeDispose(new StringWriter()).toString();
            } catch (StateException e) {
                //do whatever you want

            } catch (IOException e) {
                //do whatever you want
            } finally {
                if (stateMgr != null) {
                    stateMgr.dispose();
                }

                if (logoutCtrl != null) {
                    logoutCtrl.dispose();
                }
            }

            return logoutURL;
        }
public void redirectToUrl(String url) {

        try {
            FacesContext context = getFacesContext();
            if (context != null) {
                context.getExternalContext().redirect(url);
                context.responseComplete();
            }
        } catch (IOException e) {
            //Do whatever you want
        }

    }



回答3:


In the standard configuration of Portal, directing a user to any page with /wps/portal... as the root instead of /wps/myportal/... will force the user to log out and the session to end. So you could just create a friendly URL for your login page and redirect the user to /wps/portal/friendlyLoginUrl




回答4:


Just an addition to what zargarf said, by default the following js is executed when you click on logout is mentioned below :

javascript:if(stproxy && stproxy.isLoggedIn){stproxy.login.logout();}


来源:https://stackoverflow.com/questions/16585019/explicitly-logout-the-user-programmatically-in-websphere-portal-8-redirect-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!