Skip to content

Commit 7604248

Browse files
committed
Add default implementation in UserDetails
Closes gh-14275 Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
1 parent 57ab151 commit 7604248

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

core/src/main/java/org/springframework/security/core/userdetails/UserDetails.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,36 @@ public interface UserDetails extends Serializable {
6767
* @return <code>true</code> if the user's account is valid (ie non-expired),
6868
* <code>false</code> if no longer valid (ie expired)
6969
*/
70-
boolean isAccountNonExpired();
70+
default boolean isAccountNonExpired() {
71+
return true;
72+
}
7173

7274
/**
7375
* Indicates whether the user is locked or unlocked. A locked user cannot be
7476
* authenticated.
7577
* @return <code>true</code> if the user is not locked, <code>false</code> otherwise
7678
*/
77-
boolean isAccountNonLocked();
79+
default boolean isAccountNonLocked() {
80+
return true;
81+
}
7882

7983
/**
8084
* Indicates whether the user's credentials (password) has expired. Expired
8185
* credentials prevent authentication.
8286
* @return <code>true</code> if the user's credentials are valid (ie non-expired),
8387
* <code>false</code> if no longer valid (ie expired)
8488
*/
85-
boolean isCredentialsNonExpired();
89+
default boolean isCredentialsNonExpired() {
90+
return true;
91+
}
8692

8793
/**
8894
* Indicates whether the user is enabled or disabled. A disabled user cannot be
8995
* authenticated.
9096
* @return <code>true</code> if the user is enabled, <code>false</code> otherwise
9197
*/
92-
boolean isEnabled();
98+
default boolean isEnabled() {
99+
return true;
100+
}
93101

94102
}

test/src/test/java/org/springframework/security/test/context/showcase/CustomUserDetails.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,26 +54,6 @@ public String getUsername() {
5454
return this.username;
5555
}
5656

57-
@Override
58-
public boolean isAccountNonExpired() {
59-
return true;
60-
}
61-
62-
@Override
63-
public boolean isAccountNonLocked() {
64-
return true;
65-
}
66-
67-
@Override
68-
public boolean isCredentialsNonExpired() {
69-
return true;
70-
}
71-
72-
@Override
73-
public boolean isEnabled() {
74-
return true;
75-
}
76-
7757
@Override
7858
public String toString() {
7959
return "CustomUserDetails{" + "username='" + this.username + '\'' + '}';

0 commit comments

Comments
 (0)