Skip to content

Commit 450b536

Browse files
committed
Refine SimpleGrantedAuthority
1. Rename field `role` to `authority` since role is specific authority, this change breaks JDK deserialization, it should be merged into major release. 2. Add Javadoc to state that role should be prefixed. Signed-off-by: Yanming Zhou <[email protected]>
1 parent a4f813a commit 450b536

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,26 @@
2727
* {@link org.springframework.security.core.Authentication Authentication} object.
2828
*
2929
* @author Luke Taylor
30+
* @author Yanming Zhou
3031
*/
3132
public final class SimpleGrantedAuthority implements GrantedAuthority {
3233

3334
private static final long serialVersionUID = 620L;
3435

35-
private final String role;
36+
private final String authority;
3637

37-
public SimpleGrantedAuthority(String role) {
38-
Assert.hasText(role, "A granted authority textual representation is required");
39-
this.role = role;
38+
/**
39+
* Constructs a {@code SimpleGrantedAuthority} using the provided authority.
40+
* @param authority The provided authority such as prefixed role
41+
*/
42+
public SimpleGrantedAuthority(String authority) {
43+
Assert.hasText(authority, "A granted authority textual representation is required");
44+
this.authority = authority;
4045
}
4146

4247
@Override
4348
public String getAuthority() {
44-
return this.role;
49+
return this.authority;
4550
}
4651

4752
@Override
@@ -50,19 +55,19 @@ public boolean equals(Object obj) {
5055
return true;
5156
}
5257
if (obj instanceof SimpleGrantedAuthority sga) {
53-
return this.role.equals(sga.getAuthority());
58+
return this.authority.equals(sga.getAuthority());
5459
}
5560
return false;
5661
}
5762

5863
@Override
5964
public int hashCode() {
60-
return this.role.hashCode();
65+
return this.authority.hashCode();
6166
}
6267

6368
@Override
6469
public String toString() {
65-
return this.role;
70+
return this.authority;
6671
}
6772

6873
}

0 commit comments

Comments
 (0)