pub trait AuthenticationStrategy: Send + Sync {
// Required method
fn authenticate<'a>(
&'a self,
context: &'a dyn AuthenticationContext,
) -> AuthenticationFuture<'a>;
}Required Methods§
Sourcefn authenticate<'a>(
&'a self,
context: &'a dyn AuthenticationContext,
) -> AuthenticationFuture<'a>
fn authenticate<'a>( &'a self, context: &'a dyn AuthenticationContext, ) -> AuthenticationFuture<'a>
Authenticates a request based on the provided authentication context.
This method performs authentication using credentials, metadata, and other
information contained in the AuthenticationContext. Successful authentication
returns Ok(()), while failures return an AuthServiceError.
§Arguments
context- The authentication context containing credentials, request metadata, and any other information required for authentication.
§Returns
Ok(())- Authentication succeededErr(AuthServiceError)- Authentication failed with a specific error
§Error Semantics
crate::AuthFailureKind provides the closed failure classification.
§Thread Safety
This method must be safe to call concurrently from multiple threads. Implementations should either be stateless or use appropriate synchronization.
§Performance Considerations
- Minimize heap allocations in hot paths
- Consider caching authenticated sessions (see
StatefulAuthenticationStrategy) - Use constant-time comparison for security-critical operations
§Examples
ⓘ
use rocketmq_auth::AuthenticationStrategy;
use rocketmq_auth::DefaultAuthenticationContext;
use rocketmq_auth::AuthServiceResult;
fn authenticate_request(
strategy: &dyn AuthenticationStrategy,
context: &dyn AuthenticationContext,
) -> AuthServiceResult<()> {
strategy.authenticate(context)?;
println!("Authentication succeeded");
Ok(())
}Trait Implementations§
Source§impl AuthenticationStrategy for Box<dyn AuthenticationStrategy>
impl AuthenticationStrategy for Box<dyn AuthenticationStrategy>
Source§fn authenticate<'a>(
&'a self,
context: &'a dyn AuthenticationContext,
) -> AuthenticationFuture<'a>
fn authenticate<'a>( &'a self, context: &'a dyn AuthenticationContext, ) -> AuthenticationFuture<'a>
Authenticates a request based on the provided authentication context. Read more
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".