From dfef781e339d0a3ab3255264e5de0bae89804ede Mon Sep 17 00:00:00 2001 From: ahmd-nabil Date: Mon, 11 Dec 2023 19:04:26 +0200 Subject: [PATCH] Add default implementation in UserDetails Closes gh-14275 Signed-off-by: ahmd-nabil --- .../core/userdetails/UserDetails.java | 16 ++++++++++---- .../context/showcase/CustomUserDetails.java | 22 +------------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/springframework/security/core/userdetails/UserDetails.java b/core/src/main/java/org/springframework/security/core/userdetails/UserDetails.java index 664725631e..bab08c5a2a 100644 --- a/core/src/main/java/org/springframework/security/core/userdetails/UserDetails.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/UserDetails.java @@ -67,14 +67,18 @@ public interface UserDetails extends Serializable { * @return true if the user's account is valid (ie non-expired), * false if no longer valid (ie expired) */ - boolean isAccountNonExpired(); + default boolean isAccountNonExpired() { + return true; + } /** * Indicates whether the user is locked or unlocked. A locked user cannot be * authenticated. * @return true if the user is not locked, false otherwise */ - boolean isAccountNonLocked(); + default boolean isAccountNonLocked() { + return true; + } /** * Indicates whether the user's credentials (password) has expired. Expired @@ -82,13 +86,17 @@ public interface UserDetails extends Serializable { * @return true if the user's credentials are valid (ie non-expired), * false if no longer valid (ie expired) */ - boolean isCredentialsNonExpired(); + default boolean isCredentialsNonExpired() { + return true; + } /** * Indicates whether the user is enabled or disabled. A disabled user cannot be * authenticated. * @return true if the user is enabled, false otherwise */ - boolean isEnabled(); + default boolean isEnabled() { + return true; + } } diff --git a/test/src/test/java/org/springframework/security/test/context/showcase/CustomUserDetails.java b/test/src/test/java/org/springframework/security/test/context/showcase/CustomUserDetails.java index ccbc7a00f0..6bdb82cbad 100644 --- a/test/src/test/java/org/springframework/security/test/context/showcase/CustomUserDetails.java +++ b/test/src/test/java/org/springframework/security/test/context/showcase/CustomUserDetails.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,26 +54,6 @@ public class CustomUserDetails implements UserDetails { return this.username; } - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return true; - } - @Override public String toString() { return "CustomUserDetails{" + "username='" + this.username + '\'' + '}';