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 dynamic_active_timeout(self, enabled: bool) -> Self
pub fn dynamic_active_timeout(self, enabled: bool) -> Self
设置是否启用 per-token 动态 active_timeout
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
Sourcepub fn storage_key_prefix(self, prefix: impl Into<String>) -> Self
pub fn storage_key_prefix(self, prefix: impl Into<String>) -> Self
设置存储键前缀(默认 “sa:”)
注意:此字段与 token_prefix(HTTP header 中的 Bearer 前缀)不同 此前缀用于 Redis/数据库等存储后端的键命名
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 受众
pub fn jwt_fallback_on_error(self, fallback: bool) -> Self
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 有效期(秒)
pub fn max_login_count(self, count: i64) -> Self
pub fn overflow_logout_mode(self, mode: LogoutMode) -> Self
pub fn replaced_login_exit_mode(self, mode: ReplacedLoginExitMode) -> Self
pub fn replaced_range(self, range: ReplacedRange) -> Self
pub fn right_now_create_token_session(self, enabled: bool) -> Self
pub fn token_session_check_login(self, enabled: bool) -> Self
pub fn logout_range(self, range: LogoutRange) -> Self
pub fn is_logout_keep_token_session(self, keep: bool) -> Self
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§
Source§impl Default for SaTokenConfigBuilder
impl Default for SaTokenConfigBuilder
Source§fn default() -> SaTokenConfigBuilder
fn default() -> SaTokenConfigBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for SaTokenConfigBuilder
impl !UnwindSafe for SaTokenConfigBuilder
impl Freeze for SaTokenConfigBuilder
impl Send for SaTokenConfigBuilder
impl Sync for SaTokenConfigBuilder
impl Unpin for SaTokenConfigBuilder
impl UnsafeUnpin for SaTokenConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more