From c6571cfba13053ba107a43291b80813216cc8fa3 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Fri, 13 Sep 2024 09:19:06 +0200 Subject: [PATCH] XWIKI-22430: Logging out does not unlock pages that were being edited * Provide an abstract event for authentication --- .../AbstractUserAuthenticationEvent.java | 68 +++++++++++++++++++ .../UserAuthenticatedEvent.java | 20 +----- .../UserUnauthenticatedEvent.java | 20 +----- 3 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/AbstractUserAuthenticationEvent.java diff --git a/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/AbstractUserAuthenticationEvent.java b/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/AbstractUserAuthenticationEvent.java new file mode 100644 index 000000000000..82058c145b56 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/AbstractUserAuthenticationEvent.java @@ -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); + } +} diff --git a/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserAuthenticatedEvent.java b/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserAuthenticatedEvent.java index 1e91ada491de..5716ef2c6628 100644 --- a/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserAuthenticatedEvent.java +++ b/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserAuthenticatedEvent.java @@ -19,7 +19,6 @@ */ package org.xwiki.security.authentication; -import org.xwiki.observation.event.Event; import org.xwiki.user.UserReference; /** @@ -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. * @@ -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); } } diff --git a/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserUnauthenticatedEvent.java b/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserUnauthenticatedEvent.java index bcf04a643954..bc3984054971 100644 --- a/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserUnauthenticatedEvent.java +++ b/xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserUnauthenticatedEvent.java @@ -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; @@ -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. */ @@ -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); } }