SaTokenConfigBuilder

Struct SaTokenConfigBuilder 

Source
pub struct SaTokenConfigBuilder { /* private fields */ }
Expand description

配置构建器

Implementations§

Source§

impl SaTokenConfigBuilder

Source

pub fn token_name(self, name: impl Into<String>) -> Self

Source

pub fn timeout(self, timeout: i64) -> Self

Source

pub fn active_timeout(self, timeout: i64) -> Self

Source

pub fn auto_renew(self, enabled: bool) -> Self

设置是否开启自动续签

Source

pub fn is_concurrent(self, concurrent: bool) -> Self

Source

pub fn is_share(self, share: bool) -> Self

Source

pub fn token_style(self, style: TokenStyle) -> Self

Source

pub fn token_prefix(self, prefix: impl Into<String>) -> Self

Source

pub fn jwt_secret_key(self, key: impl Into<String>) -> Self

Source

pub fn jwt_algorithm(self, algorithm: impl Into<String>) -> Self

设置 JWT 算法

Source

pub fn jwt_issuer(self, issuer: impl Into<String>) -> Self

设置 JWT 签发者

Source

pub fn jwt_audience(self, audience: impl Into<String>) -> Self

设置 JWT 受众

Source

pub fn enable_nonce(self, enable: bool) -> Self

启用防重放攻击(nonce 机制)

Source

pub fn nonce_timeout(self, timeout: i64) -> Self

设置 Nonce 有效期(秒)

Source

pub fn enable_refresh_token(self, enable: bool) -> Self

启用 Refresh Token

Source

pub fn refresh_token_timeout(self, timeout: i64) -> Self

设置 Refresh Token 有效期(秒)

Source

pub fn storage(self, storage: Arc<dyn SaStorage>) -> Self

设置存储方式

Source

pub fn register_listener(self, listener: Arc<dyn SaTokenListener>) -> Self

注册事件监听器

可以多次调用以注册多个监听器

§示例
use std::sync::Arc;
use sa_token_core::{SaTokenConfig, SaTokenListener};
 
struct MyListener;
impl SaTokenListener for MyListener { /* ... */ }
 
let manager = SaTokenConfig::builder()
    .storage(Arc::new(MemoryStorage::new()))
    .register_listener(Arc::new(MyListener))
    .build();
Source

pub fn build(self) -> SaTokenManager

构建 SaTokenManager(需要先设置 storage)

自动完成以下操作:

  1. 创建 SaTokenManager
  2. 注册所有事件监听器
  3. 初始化 StpUtil

Auto-complete the following operations:

  1. Create SaTokenManager
  2. Register all event listeners
  3. Initialize StpUtil
§Panics

如果未设置 storage,会 panic

§示例
use std::sync::Arc;
use sa_token_core::SaTokenConfig;
use sa_token_storage_memory::MemoryStorage;
 
// 一行代码完成所有初始化!
// Complete all initialization in one line!
SaTokenConfig::builder()
    .storage(Arc::new(MemoryStorage::new()))
    .timeout(7200)
    .register_listener(Arc::new(MyListener))
    .build();  // 自动初始化 StpUtil!
Source

pub fn build_config(self) -> SaTokenConfig

仅构建配置(不创建 Manager)

Trait Implementations§

Source§

impl Default for SaTokenConfigBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more