TestingAuthenticationToken class
An already authenticated token with the authorities you name, for tests and for code that runs as a fixed identity.
No password is checked: whatever you pass is trusted. Never build one
from input a client sent. In tests, withMockUser from
package:spring_security_core/testing.dart is often shorter.
// A test of an admin-only service method.
await SecurityContextHolder.runWithContext(
() => orders.cancel(order),
SecurityContextImpl(
TestingAuthenticationToken('ada', null, ['ROLE_ADMIN']),
),
);
Spring (Java): new TestingAuthenticationToken("ada", null, "ROLE_ADMIN").
- Inheritance
-
- Object
- AbstractAuthenticationToken
- TestingAuthenticationToken
Constructors
-
TestingAuthenticationToken(Object? principal, Object? credentials, [List<
String> authorities = const []]) -
An authenticated token for
principalwithcredentialsand the authorities named inauthorities(used as given: writeROLE_ADMIN, notADMIN).
Properties
-
The permissions of the user, such as
ROLE_ADMINorSCOPE_read.finalinherited - credentials → Object?
-
The secret that proves the identity, usually the typed password.
final
- details ↔ Object?
-
Extra facts about the login, such as the client's address and
session id;
nullwhen nobody set them.getter/setter pairinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- isAuthenticated ↔ bool
-
Whether this object can be trusted as a checked identity.
getter/setter pairinherited
- name → String
-
The user's name, taken from the principal: the username of a
UserDetails, the name of an Authentication or a Principal,
otherwise the principal's
toString();''when the principal isnull.no setterinherited - principal → Object?
-
The identity: the typed username in a login request; after the login,
usually the UserDetails of the user (a
Jwtfor a bearer token).final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
eraseCredentials(
) → void -
Sets the secret to
null; the object stays usable otherwise.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A description for logs: the name, the authorities and the flags, with
the credentials replaced by
[PROTECTED].inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited