Skip to content

Commit

Permalink
XWIKI-22430: Logging out does not unlock pages that were being edited
Browse files Browse the repository at this point in the history
  * Provide an abstract event for authentication
  • Loading branch information
surli committed Sep 13, 2024
1 parent 084ef7f commit c6571cf
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.xwiki.security.authentication;

import java.util.Objects;

import org.xwiki.observation.event.Event;
import org.xwiki.stability.Unstable;
import org.xwiki.user.UserReference;

/**
* Abstract event related to authentication.
*
* @version $Id$
* @since 16.8.0RC1
*/
@Unstable
public abstract class AbstractUserAuthenticationEvent implements Event
{
/**
* The reference related to an authenticated user for whom the event has been triggered.
*/
private final UserReference userReference;

/**
* This event will match only events of the same type affecting the same user.
*
* @param userReference The reference related to an authenticated user for whom the event
* has been triggered.
*/
public AbstractUserAuthenticationEvent(UserReference userReference)
{
this.userReference = userReference;
}

/**
* @return the {@link UserReference} of the user for whom the event is triggered.
*/
public UserReference getUserReference()
{
return this.userReference;
}

@Override
public boolean matches(Object other)
{
return other instanceof AbstractUserAuthenticationEvent
&& Objects.equals(((AbstractUserAuthenticationEvent) other).getUserReference(), this.userReference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.xwiki.security.authentication;

import org.xwiki.observation.event.Event;
import org.xwiki.user.UserReference;

/**
Expand All @@ -28,13 +27,8 @@
* @version $Id$
* @since 13.3RC1
*/
public class UserAuthenticatedEvent implements Event
public class UserAuthenticatedEvent extends AbstractUserAuthenticationEvent
{
/**
* The reference related to an authenticated user for whom a {@link UserAuthenticatedEvent} has been triggered.
*/
private final UserReference userReference;

/**
* This event will match only events of the same type affecting the same user.
*
Expand All @@ -43,21 +37,13 @@ public class UserAuthenticatedEvent implements Event
*/
public UserAuthenticatedEvent(UserReference userReference)
{
this.userReference = userReference;
}

/**
* @return the {@link UserReference} of the authenticated user.
*/
public UserReference getUserReference()
{
return this.userReference;
super(userReference);
}

@Override
public boolean matches(Object other)
{
return other instanceof UserAuthenticatedEvent;
return other instanceof UserAuthenticatedEvent && super.matches(other);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package org.xwiki.security.authentication;

import org.xwiki.observation.event.Event;
import org.xwiki.stability.Unstable;
import org.xwiki.user.UserReference;

Expand All @@ -33,13 +32,8 @@
* @since 15.10.13
*/
@Unstable
public class UserUnauthenticatedEvent implements Event
public class UserUnauthenticatedEvent extends AbstractUserAuthenticationEvent
{
/**
* The reference related to an authenticated user for whom a {@link UserUnauthenticatedEvent} has been triggered.
*/
private final UserReference userReference;

/**
* Default constructor without user reference for matching.
*/
Expand All @@ -56,20 +50,12 @@ public UserUnauthenticatedEvent()
*/
public UserUnauthenticatedEvent(UserReference userReference)
{
this.userReference = userReference;
}

/**
* @return the {@link UserReference} of the authenticated user.
*/
public UserReference getUserReference()
{
return this.userReference;
super(userReference);
}

@Override
public boolean matches(Object other)
{
return other instanceof UserUnauthenticatedEvent;
return other instanceof UserUnauthenticatedEvent && super.matches(other);
}
}

0 comments on commit c6571cf

Please sign in to comment.