From b55c28cf25815e443c20bd0a1618506573e3a768 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Tue, 9 Sep 2025 16:42:38 +0800 Subject: [PATCH] Polish SimpleGrantedAuthority 1. Add Javadoc to state that role is prefixed. 2. Rename constructor argument from `role` to `authority` for better readability. Signed-off-by: Yanming Zhou --- .../core/authority/SimpleGrantedAuthority.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java b/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java index 72efecaf4c..96fd186f93 100644 --- a/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java +++ b/core/src/main/java/org/springframework/security/core/authority/SimpleGrantedAuthority.java @@ -27,16 +27,22 @@ import org.springframework.util.Assert; * {@link org.springframework.security.core.Authentication Authentication} object. * * @author Luke Taylor + * @author Yanming Zhou */ public final class SimpleGrantedAuthority implements GrantedAuthority { private static final long serialVersionUID = 620L; + // CAUTION renaming to authority will break serialization compatibility private final String role; - public SimpleGrantedAuthority(String role) { - Assert.hasText(role, "A granted authority textual representation is required"); - this.role = role; + /** + * Constructs a {@code SimpleGrantedAuthority} using the provided authority. + * @param authority The provided authority such as prefixed role + */ + public SimpleGrantedAuthority(String authority) { + Assert.hasText(authority, "A granted authority textual representation is required"); + this.role = authority; } @Override