pub struct SaTokenConfig {Show 30 fields
pub token_name: String,
pub timeout: i64,
pub active_timeout: i64,
pub dynamic_active_timeout: bool,
pub auto_renew: bool,
pub is_concurrent: bool,
pub is_share: bool,
pub token_style: TokenStyle,
pub is_log: bool,
pub is_read_cookie: bool,
pub is_read_header: bool,
pub is_read_body: bool,
pub jwt_secret_key: Option<String>,
pub jwt_algorithm: Option<String>,
pub jwt_issuer: Option<String>,
pub jwt_audience: Option<String>,
pub jwt_fallback_on_error: bool,
pub enable_nonce: bool,
pub nonce_timeout: i64,
pub enable_refresh_token: bool,
pub refresh_token_timeout: i64,
pub storage_key_prefix: String,
pub max_login_count: i64,
pub overflow_logout_mode: LogoutMode,
pub replaced_login_exit_mode: ReplacedLoginExitMode,
pub replaced_range: ReplacedRange,
pub right_now_create_token_session: bool,
pub token_session_check_login: bool,
pub logout_range: LogoutRange,
pub is_logout_keep_token_session: bool,
}Expand description
sa-token 配置
Fields§
§token_name: StringToken 名称(例如在 header 或 cookie 中的键名)
timeout: i64Token 有效期(秒),-1 表示永久有效
active_timeout: i64Token 最低活跃频率(秒),-1 表示不限制
超过该间隔未活跃则 token 冻结(TokenInactive);配合 auto_renew 时亦用于续签时长。
dynamic_active_timeout: bool是否启用 per-token 动态 active_timeout(对齐 Java dynamicActiveTimeout,Phase2 完善)
auto_renew: bool是否开启自动续签(默认 true,对齐 Java SaTokenConfig)
如果设置为 true,在以下场景会自动续签 token:
- 调用 get_token_info() 时
- 中间件验证 token 时
- 调用无参数的 StpUtil 方法时
续签时长由 active_timeout 决定:
- 如果 active_timeout > 0,则续签 active_timeout 秒
- 如果 active_timeout <= 0,则续签 timeout 秒
is_concurrent: bool是否允许同一账号并发登录
在多人登录同一账号时,是否共享一个 token(默认 false,对齐 Java)
token_style: TokenStyleToken 风格(uuid、simple-uuid、random-32、random-64、random-128)
is_log: bool是否输出操作日志
是否从 cookie 中读取 token
is_read_header: bool是否从 header 中读取 token
is_read_body: bool是否从请求体中读取 token
jwt_secret_key: Option<String>JWT 密钥(如果使用 JWT)
jwt_algorithm: Option<String>JWT 算法(默认 HS256)
jwt_issuer: Option<String>JWT 签发者
jwt_audience: Option<String>JWT 受众
jwt_fallback_on_error: boolJWT 生成失败时是否回退为 UUID(默认 true);失败时始终 tracing::warn
enable_nonce: bool是否启用防重放攻击(nonce 机制)
nonce_timeout: i64Nonce 有效期(秒),-1 表示使用 token timeout
enable_refresh_token: bool是否启用 Refresh Token
refresh_token_timeout: i64Refresh Token 有效期(秒),默认 7 天
storage_key_prefix: String存储键前缀(用于 Redis/数据库等存储后端的键命名) 默认 “sa:”,所有存储键将以此为前缀,如 “sa:token:”、“sa:session:” 等 注意:此字段与 token_prefix(HTTP header 中的 Bearer 前缀)不同
max_login_count: i64同一账号最大登录数量,-1 表示不限制
overflow_logout_mode: LogoutMode超出 max_login_count 时的下线模式
replaced_login_exit_mode: ReplacedLoginExitMode非并发顶号时:踢旧设备还是拒绝新登录
replaced_range: ReplacedRange顶号范围:当前设备类型或全部设备
right_now_create_token_session: bool登录时是否立即创建 Token-Session
token_session_check_login: bool获取 Token-Session 时是否校验 token 登录态
logout_range: LogoutRange默认 logout 范围(预留)
is_logout_keep_token_session: boollogout 时是否保留 Token-Session
Implementations§
Source§impl SaTokenConfig
impl SaTokenConfig
pub fn builder() -> SaTokenConfigBuilder
pub fn timeout_duration(&self) -> Option<Duration>
Sourcepub fn make_key(&self, suffix: &str, id: &str) -> String
pub fn make_key(&self, suffix: &str, id: &str) -> String
构造存储键:拼接 storage_key_prefix 与后缀 例如:make_key(“token:”, “abc123”) → “sa:token:abc123”
Sourcepub fn key_prefix(&self) -> &str
pub fn key_prefix(&self) -> &str
获取存储键前缀
Trait Implementations§
Source§impl Clone for SaTokenConfig
impl Clone for SaTokenConfig
Source§fn clone(&self) -> SaTokenConfig
fn clone(&self) -> SaTokenConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SaTokenConfig
impl Debug for SaTokenConfig
Source§impl Default for SaTokenConfig
impl Default for SaTokenConfig
Source§fn default() -> SaTokenConfig
fn default() -> SaTokenConfig
Source§impl<'de> Deserialize<'de> for SaTokenConfig
impl<'de> Deserialize<'de> for SaTokenConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SaTokenConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SaTokenConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for SaTokenConfig
impl Serialize for SaTokenConfig
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for SaTokenConfig
impl RefUnwindSafe for SaTokenConfig
impl Send for SaTokenConfig
impl Sync for SaTokenConfig
impl Unpin for SaTokenConfig
impl UnsafeUnpin for SaTokenConfig
impl UnwindSafe for SaTokenConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);