SsoServer

Struct SsoServer 

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

SSO 服务端 | SSO Server

中央认证服务,负责票据生成、验证和会话管理 Central authentication service responsible for ticket generation, validation, and session management

Implementations§

Source§

impl SsoServer

Source

pub fn new(manager: Arc<SaTokenManager>) -> Self

创建新的 SSO 服务端 | Create a new SSO Server

§参数 | Parameters
  • manager - SaTokenManager 实例 | SaTokenManager instance
Source

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

设置票据超时时间 | Set ticket timeout

§参数 | Parameters
  • timeout - 超时时间(秒)| Timeout in seconds
Source

pub async fn is_logged_in(&self, login_id: &str) -> bool

检查用户是否已登录 | Check if user is logged in

通过检查 SSO 会话是否存在来判断 Determined by checking if SSO session exists

Source

pub async fn create_ticket( &self, login_id: String, service: String, ) -> SaTokenResult<SsoTicket>

创建票据 | Create ticket

为已登录用户创建访问特定服务的票据 Creates a ticket for logged-in user to access specific service

§参数 | Parameters
  • login_id - 用户登录 ID | User login ID
  • service - 目标服务 URL | Target service URL
§返回 | Returns

新创建的票据 | Newly created ticket

Source

pub async fn validate_ticket( &self, ticket_id: &str, service: &str, ) -> SaTokenResult<String>

验证票据 | Validate ticket

验证票据的有效性并将其标记为已使用(一次性使用) Validates ticket and marks it as used (one-time use)

§参数 | Parameters
  • ticket_id - 票据 ID | Ticket ID
  • service - 请求的服务 URL | Requested service URL
§返回 | Returns

用户登录 ID | User login ID

§错误 | Errors
  • InvalidTicket - 票据不存在 | Ticket not found
  • TicketExpired - 票据已过期或已使用 | Ticket expired or used
  • ServiceMismatch - 服务 URL 不匹配 | Service URL mismatch
Source

pub async fn login( &self, login_id: String, service: String, ) -> SaTokenResult<SsoTicket>

用户登录 | User login

完整的登录流程:创建 Token、会话和票据 Complete login flow: create Token, session, and ticket

§参数 | Parameters
  • login_id - 用户登录 ID | User login ID
  • service - 目标服务 URL | Target service URL
§返回 | Returns

生成的票据 | Generated ticket

Source

pub async fn logout(&self, login_id: &str) -> SaTokenResult<Vec<String>>

统一登出 | Unified logout

从 SSO 服务端登出,并返回需要通知的客户端列表 Logout from SSO Server and return list of clients to notify

§参数 | Parameters
  • login_id - 用户登录 ID | User login ID
§返回 | Returns

需要清除会话的客户端 URL 列表 | List of client URLs to clear sessions

Source

pub async fn get_session(&self, login_id: &str) -> Option<SsoSession>

获取 SSO 会话 | Get SSO session

§参数 | Parameters
  • login_id - 用户登录 ID | User login ID
§返回 | Returns

SSO 会话信息(如果存在)| SSO session info (if exists)

Source

pub async fn check_session(&self, login_id: &str) -> bool

检查会话是否存在 | Check if session exists

§参数 | Parameters
  • login_id - 用户登录 ID | User login ID
§返回 | Returns

会话是否存在 | Whether session exists

Source

pub async fn cleanup_expired_tickets(&self)

清理过期票据 | Cleanup expired tickets

删除所有过期或已使用的票据 Removes all expired or used tickets

Source

pub async fn get_active_clients(&self, login_id: &str) -> Vec<String>

获取活跃客户端列表 | Get active clients list

§参数 | Parameters
  • login_id - 用户登录 ID | User login ID
§返回 | Returns

客户端 URL 列表 | List of client URLs

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