Skip to content

abstract class Athena::Security::Authentication::Token::AbstractToken
inherits Reference #

Provides the common implementation of tokens.

The role names of a token are set when it is created, and are not updated when the user is changed, as they describe the authentication rather than the roles the user has.

Included modules

Athena::Security::Authentication::Token::Interface

Direct known subclasses

Athena::Security::Authentication::Token::UsernamePassword

Constructors#

.new(role_names : Array(String) = [] of String)#

View source

Methods#

#attribute(name : String, type : T.class) : T forall T#

Returns the value of the attribute with the provided name, deserialized as the provided type.

Raises an ASEC::Exception::InvalidArgument if this token has no attribute with that name.

View source

#attribute?(name : String, type : T.class) : T | Nil forall T#

Returns the value of the attribute with the provided name, deserialized as the provided type, or nil if this token has no attribute with that name.

View source

#attributes : Hash(String, String)#

Returns the attributes of this token, with their values serialized as JSON.

View source

#attributes=(attributes : Hash(String, String))#

Replaces the attributes of this token with the provided attributes, whose values are serialized as JSON.

View source

#has_attribute?(name : String) : Bool#

Returns true if this token has an attribute with the provided name, otherwise false.

View source

#role_names : Array(String)#

Returns the roles granted to the user by this token.

View source

#set_attribute(name : String, value : _) : Nil#

Sets the attribute with the provided name to the provided value.

View source

#to_s(io : IO) : Nil#

Writes a representation of this token to the provided io, for debugging purposes.

View source

#user : ASEC::User::Interface | ::Nil#

Returns the authenticated user, if any.

View source

#user=(user : ASEC::User::Interface)#

Sets the authenticated user.

View source

#user_identifier : String#

Returns the identifier of the user, e.g. its username or email address, or an empty string if there is no user.

View source