Add default implementation in UserDetails

Closes gh-14275

Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
This commit is contained in:
ahmd-nabil 2023-12-11 19:04:26 +02:00 committed by Josh Cummings
parent 1b39c1248a
commit dfef781e33
2 changed files with 13 additions and 25 deletions

View File

@ -67,14 +67,18 @@ public interface UserDetails extends Serializable {
* @return <code>true</code> if the user's account is valid (ie non-expired), * @return <code>true</code> if the user's account is valid (ie non-expired),
* <code>false</code> if no longer valid (ie expired) * <code>false</code> 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 * Indicates whether the user is locked or unlocked. A locked user cannot be
* authenticated. * authenticated.
* @return <code>true</code> if the user is not locked, <code>false</code> otherwise * @return <code>true</code> if the user is not locked, <code>false</code> otherwise
*/ */
boolean isAccountNonLocked(); default boolean isAccountNonLocked() {
return true;
}
/** /**
* Indicates whether the user's credentials (password) has expired. Expired * Indicates whether the user's credentials (password) has expired. Expired
@ -82,13 +86,17 @@ public interface UserDetails extends Serializable {
* @return <code>true</code> if the user's credentials are valid (ie non-expired), * @return <code>true</code> if the user's credentials are valid (ie non-expired),
* <code>false</code> if no longer valid (ie expired) * <code>false</code> 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 * Indicates whether the user is enabled or disabled. A disabled user cannot be
* authenticated. * authenticated.
* @return <code>true</code> if the user is enabled, <code>false</code> otherwise * @return <code>true</code> if the user is enabled, <code>false</code> otherwise
*/ */
boolean isEnabled(); default boolean isEnabled() {
return true;
}
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; 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 @Override
public String toString() { public String toString() {
return "CustomUserDetails{" + "username='" + this.username + '\'' + '}'; return "CustomUserDetails{" + "username='" + this.username + '\'' + '}';