2
2
3
3
import java .util .Collection ;
4
4
5
+ /**
6
+ * Represents an authenticated entity in the system, typically service identity or end user. This
7
+ * interface provides methods to check roles and permissions for authorization purposes.
8
+ */
5
9
public interface Principal {
6
10
11
+ /**
12
+ * A constant representing a "null" principal, which signifies an unauthenticated entity. This
13
+ * principal does not have any roles or permissions.
14
+ */
7
15
Principal NULL_PRINCIPAL =
8
16
new Principal () {
9
17
@ Override
@@ -12,18 +20,40 @@ public String toString() {
12
20
}
13
21
};
14
22
23
+ /**
24
+ * Returns the role associated with this principal.
25
+ *
26
+ * @return the role name, or {@code null} if no role is assigned
27
+ */
15
28
default String role () {
16
29
return null ;
17
30
}
18
31
32
+ /**
33
+ * Checks if this principal has the specified role.
34
+ *
35
+ * @param role the role to check
36
+ * @return {@code true} if the principal has the specified role, {@code false} otherwise
37
+ */
19
38
default boolean hasRole (String role ) {
20
39
return false ;
21
40
}
22
41
42
+ /**
43
+ * Returns the collection of permissions assigned to this principal.
44
+ *
45
+ * @return permissions, or {@code null} if no permissions are assigned
46
+ */
23
47
default Collection <String > permissions () {
24
48
return null ;
25
49
}
26
50
51
+ /**
52
+ * Checks if this principal has the specified permission.
53
+ *
54
+ * @param permission the permission to check
55
+ * @return {@code true} if the principal has the specified permission, {@code false} otherwise
56
+ */
27
57
default boolean hasPermission (String permission ) {
28
58
return false ;
29
59
}
0 commit comments