I'm trying to generate a logout link so i don't have to use the default logout link from websphere portal. I tried this:
MyLogoutUrlGenerator:
public String generateLogoutUrl(RenderRequest req, RenderResponse res)
throws [...] {
String logoutUrl = "";
Context ctx = new InitialContext();
PortletServiceHome stateMgrServiceHome = (PortletServiceHome) ctx
.lookup("portletservice/com.ibm.portal.state.service.PortletStateManagerService");
PortletStateManagerService service = (PortletStateManagerService) stateMgrServiceHome
.getPortletService(PortletStateManagerService.class);
PortletStateManager stateMgr = service.getPortletStateManager(req, res);
final URLFactory urlFactory = stateMgr.getURLFactory();
EngineURL url = urlFactory.newURL(null);
LogoutActionAccessorFactory logoutFactory = (LogoutActionAccessorFactory) stateMgr
.getAccessorFactory(LogoutActionAccessorFactory.class);
logoutUrl = url.writeDispose(new StringWriter()).toString();
stateMgr.dispose();
return logoutUrl;
}
Controller.java:
@RenderMapping()
public ModelAndView showLatestNews(PortletPreferences pref, RenderRequest req, RenderResponse res) {
ModelAndView mav = new ModelAndView("news/newsflash");
[...]
try {
mav.addObject("logoutUrl", generateLogoutUrl(req, res));
} catch ([...]){
e.printStackTrace();
}
return mav;
}
newflash.jsp:
...
<a href="${logoutUrl}">Logout</a>
...
This is a modified version of a piece of code i found in this post. But i can't get it to work. I've saw a lot of posts like this:
redirect.logout=true
redirect.logout.ssl=false
redirect.logout.url=protocol://host_name/logout_page
But this doesn't help me.
I just want to generate a logout url which i can pass to the <a></a>
. I'm using Websphere Portal 8.5 and Spring 4.3.2.
Thanks in advance.
Usually a logout link is added to the Portal Theme; I'm assuming you want to trigger logout from a different location?
I would suggest rather doing this in the theme (dynamic content spot) in e.g. the header. You then don't need any java code for this.
For example, in the commonActions.jsp in your theme:
This is default way to do it. You can then access this link yourself via javascript if you need to use it elsewhere.