Skip to content

Commit d15c3de

Browse files
committed
Added javadoc for Principal
1 parent 61ec356 commit d15c3de

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

services-api/src/main/java/io/scalecube/services/auth/Principal.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
import java.util.Collection;
44

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+
*/
59
public interface Principal {
610

11+
/**
12+
* A constant representing a "null" principal, which signifies an unauthenticated entity. This
13+
* principal does not have any roles or permissions.
14+
*/
715
Principal NULL_PRINCIPAL =
816
new Principal() {
917
@Override
@@ -12,18 +20,40 @@ public String toString() {
1220
}
1321
};
1422

23+
/**
24+
* Returns the role associated with this principal.
25+
*
26+
* @return the role name, or {@code null} if no role is assigned
27+
*/
1528
default String role() {
1629
return null;
1730
}
1831

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+
*/
1938
default boolean hasRole(String role) {
2039
return false;
2140
}
2241

42+
/**
43+
* Returns the collection of permissions assigned to this principal.
44+
*
45+
* @return permissions, or {@code null} if no permissions are assigned
46+
*/
2347
default Collection<String> permissions() {
2448
return null;
2549
}
2650

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+
*/
2757
default boolean hasPermission(String permission) {
2858
return false;
2959
}

0 commit comments

Comments
 (0)