Principal class abstract interface

The identity of whoever makes a request: a user, a client application or another service, reduced to a name.

It exists so the web layer and the security packages can share one type without depending on each other: an authentication filter (the security starter's) stores a principal on the request, and a controller or WebSocket handler parameter of type Principal receives it. An application receives it; it rarely implements it (Spring Security's Authentication is one).

@RestController()
class MeController {
  // Null while nobody is authenticated.
  @GetMapping('/me')
  String me(Principal? principal) => principal?.name ?? 'anonymous';
}

Spring (Java): java.security.Principal.

@GetMapping("/me")
String me(Principal principal) { return principal.getName(); }

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
The name that identifies the user or client, such as a user name or a client id.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited