Fórumok

Logout and redirect from filter

Anil KC, módosítva 11 év-val korábban

Logout and redirect from filter

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2012.12.21. Legújabb bejegyzések
I have a certain service pre action filter which needs user to redirect to a page after user is logged out programatically. Is there any way to do this? How to logout user and redirect to a page?
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Logout and redirect from filter

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi
To logout programatically use below sniplet

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
themeDisplay.getURLSignOut();


For redirect try this
Anil KC, módosítva 11 év-val korábban

RE: Logout and redirect from filter

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2012.12.21. Legújabb bejegyzések
It just returns Logout URL. How to logout and then redirect programatically in a method?
thumbnail
mohammad azaruddin, módosítva 11 év-val korábban

RE: Logout and redirect from filter

Expert Bejegyzések: 492 Csatlakozás dátuma: 2012.09.17. Legújabb bejegyzések
Hi
To logout programatically use below sniplet(in your action class)

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
actionResponse.sendRedirect(themeDisplay.getURLSignOut());

And after logout u might use Post Logout Event(not sure whether it is proper way)

Regards
thumbnail
Jitendra Rajput, módosítva 11 év-val korábban

RE: Logout and redirect from filter

Liferay Master Bejegyzések: 875 Csatlakozás dátuma: 2011.01.07. Legújabb bejegyzések
To logout pragmatically and redirect to custom page you can try with below approach.

Copy code from LogoutAction.java and paste in your custom method. when you want to logout pro grammatically user your custom method.
Once you are done with logout use SendRedirect as suggested in above post you can redirect to your custom page.

Below is the code for force user logout.

HttpSession session = request.getSession();

			EventsProcessorUtil.process(
				PropsKeys.LOGOUT_EVENTS_PRE, PropsValues.LOGOUT_EVENTS_PRE,
				request, response);

			String domain = CookieKeys.getDomain(request);

			Cookie companyIdCookie = new Cookie(
				CookieKeys.COMPANY_ID, StringPool.BLANK);

			if (Validator.isNotNull(domain)) {
				companyIdCookie.setDomain(domain);
			}

			companyIdCookie.setMaxAge(0);
			companyIdCookie.setPath(StringPool.SLASH);

			Cookie idCookie = new Cookie(CookieKeys.ID, StringPool.BLANK);

			if (Validator.isNotNull(domain)) {
				idCookie.setDomain(domain);
			}

			idCookie.setMaxAge(0);
			idCookie.setPath(StringPool.SLASH);

			Cookie passwordCookie = new Cookie(
				CookieKeys.PASSWORD, StringPool.BLANK);

			if (Validator.isNotNull(domain)) {
				passwordCookie.setDomain(domain);
			}

			passwordCookie.setMaxAge(0);
			passwordCookie.setPath(StringPool.SLASH);

			Cookie rememberMeCookie = new Cookie(
				CookieKeys.REMEMBER_ME, StringPool.BLANK);

			if (Validator.isNotNull(domain)) {
				rememberMeCookie.setDomain(domain);
			}

			rememberMeCookie.setMaxAge(0);
			rememberMeCookie.setPath(StringPool.SLASH);

			CookieKeys.addCookie(request, response, companyIdCookie);
			CookieKeys.addCookie(request, response, idCookie);
			CookieKeys.addCookie(request, response, passwordCookie);
			CookieKeys.addCookie(request, response, rememberMeCookie);

			try {
				session.invalidate();
			}
			catch (Exception e) {
			}

			EventsProcessorUtil.process(
				PropsKeys.LOGOUT_EVENTS_POST, PropsValues.LOGOUT_EVENTS_POST,
				request, response);

			request.setAttribute(WebKeys.LOGOUT, true);