pub struct SaTokenConfigBuilder { /* private fields */ }Expand description
配置构建器
Implementations§
Source§impl SaTokenConfigBuilder
impl SaTokenConfigBuilder
pub fn token_name(self, name: impl Into<String>) -> Self
pub fn timeout(self, timeout: i64) -> Self
pub fn active_timeout(self, timeout: i64) -> Self
Sourcepub fn auto_renew(self, enabled: bool) -> Self
pub fn auto_renew(self, enabled: bool) -> Self
设置是否开启自动续签
pub fn is_concurrent(self, concurrent: bool) -> Self
pub fn token_style(self, style: TokenStyle) -> Self
pub fn token_prefix(self, prefix: impl Into<String>) -> Self
pub fn jwt_secret_key(self, key: impl Into<String>) -> Self
Sourcepub fn jwt_algorithm(self, algorithm: impl Into<String>) -> Self
pub fn jwt_algorithm(self, algorithm: impl Into<String>) -> Self
设置 JWT 算法
Sourcepub fn jwt_issuer(self, issuer: impl Into<String>) -> Self
pub fn jwt_issuer(self, issuer: impl Into<String>) -> Self
设置 JWT 签发者
Sourcepub fn jwt_audience(self, audience: impl Into<String>) -> Self
pub fn jwt_audience(self, audience: impl Into<String>) -> Self
设置 JWT 受众
Sourcepub fn enable_nonce(self, enable: bool) -> Self
pub fn enable_nonce(self, enable: bool) -> Self
启用防重放攻击(nonce 机制)
Sourcepub fn nonce_timeout(self, timeout: i64) -> Self
pub fn nonce_timeout(self, timeout: i64) -> Self
设置 Nonce 有效期(秒)
Sourcepub fn enable_refresh_token(self, enable: bool) -> Self
pub fn enable_refresh_token(self, enable: bool) -> Self
启用 Refresh Token
Sourcepub fn refresh_token_timeout(self, timeout: i64) -> Self
pub fn refresh_token_timeout(self, timeout: i64) -> Self
设置 Refresh Token 有效期(秒)
Sourcepub fn register_listener(self, listener: Arc<dyn SaTokenListener>) -> Self
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();Sourcepub fn build(self) -> SaTokenManager
pub fn build(self) -> SaTokenManager
构建 SaTokenManager(需要先设置 storage)
自动完成以下操作:
- 创建 SaTokenManager
- 注册所有事件监听器
- 初始化 StpUtil
Auto-complete the following operations:
- Create SaTokenManager
- Register all event listeners
- 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!Sourcepub fn build_config(self) -> SaTokenConfig
pub fn build_config(self) -> SaTokenConfig
仅构建配置(不创建 Manager)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SaTokenConfigBuilder
impl !RefUnwindSafe for SaTokenConfigBuilder
impl Send for SaTokenConfigBuilder
impl Sync for SaTokenConfigBuilder
impl Unpin for SaTokenConfigBuilder
impl !UnwindSafe for SaTokenConfigBuilder
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more