Unable to redirect a user without license

Hi,

I’m using a script to remove the license of users that have not used confluence since a defined lapse of time. In order to do that, I remove the membership of confluence-users.
But when I do that, if the user has still his Confluence page opened, he is not redirected to the login page.
So I tried to create a script to do that but it failed for different reasons.

The first script (listener with scriptrunner) was conceived with the GroupMemberShipDeletedEvent, in order redirect the user to the login page when removed from the confluence-users group.

import org.apache.log4j.Logger
import javax.ws.rs.core.Response
import org.apache.log4j.Level
import com.atlassian.plugin.webresource.assembler.UrlModeUtils
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import com.atlassian.sal.api.UrlMode;
def logger = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
logger.info("*******************goupe delete*****************************")
@BaseScript CustomEndpointDelegate delegate
def applicationProperties = ComponentLocator.getComponent(ApplicationProperties)
logger.info(applicationProperties.getBaseUrl(UrlMode.ABSOLUTE))
Response.temporaryRedirect(URI.create("${applicationProperties.getBaseUrl(UrlMode.ABSOLUTE)}/login.action?logout=true")).build()

When I use this script, I encounter no error but there is no redirection for the user that has been removed from the group.

The second script (listener with scriptrunner) was conceived with the NoConfluencePermissionEvent, in order to use the logout method when the user loose the permission after being removed from the confluence-users group.

import org.apache.log4j.Logger
import com.atlassian.confluence.user.ConfluenceUser
import com.atlassian.confluence.user.actions.LogoutAction
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.user.GroupManager
import javax.ws.rs.core.Response
import org.apache.log4j.Level
import com.atlassian.plugin.webresource.assembler.UrlModeUtils
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import groovy.transform.BaseScript
import com.atlassian.sal.api.UrlMode;
import com.atlassian.confluence.user.UserAccessor
def logger = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
logger.info("*******************Opération non autorisée*****************************")
@BaseScript CustomEndpointDelegate delegate
def applicationProperties = ComponentLocator.getComponent(ApplicationProperties)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def groupManager = ComponentLocator.getComponent(GroupManager)

LoginManager loginManager = ComponentLocator.getComponent(LoginManager)

logger.info(applicationProperties.getBaseUrl(UrlMode.ABSOLUTE))
logger.info(AuthenticatedUserThreadLocal.get().getName())

LogoutAction out= new LogoutAction()
out.execute()

When I use this script, I encounter a error but there is no redirection for the user that has been removed from the group.

Thanks for your help.

Kind regards,

Florent