chiradee
chiradee

Reputation: 105

How to kill session/logout other user in liferay programatically

I am aware that you can kill session of other users if you are logged in as admin in liferay using the control panel -> users -> monitoring. But I'm wondering if I can do it programatically? Because I'm trying to create a user management that has force logout. Thanks.

Upvotes: 0

Views: 1519

Answers (1)

Parth Ghiya
Parth Ghiya

Reputation: 6949

Option 1 :

Use following lines of code as seen in Liferay src.

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);

Option 2:

Use

    AuthenticatedSessionManagerUtil.logout(request, response);

As seen in LogoutAction.java

Upvotes: 1

Related Questions