pub struct RequestMatcherAuthorizer { /* private fields */ }Expand description
URL pattern-based authorization.
§Spring Security Equivalent
RequestMatcher + AuthorizationManager
§Example
ⓘ
use actix_security_core::http::security::authorizer::{RequestMatcherAuthorizer, Access};
let authorizer = RequestMatcherAuthorizer::new()
.login_url("/login")
.http_basic()
.add_matcher("/admin/.*", Access::new().roles(vec!["ADMIN"]))
.add_matcher("/api/.*", Access::new().authorities(vec!["api:read"]));Implementations§
Source§impl RequestMatcherAuthorizer
impl RequestMatcherAuthorizer
Sourcepub fn new() -> RequestMatcherAuthorizer
pub fn new() -> RequestMatcherAuthorizer
Creates a new authorizer with default settings.
Sourcepub fn add_matcher(
self,
url_regex: &'static str,
access: Access,
) -> RequestMatcherAuthorizer
pub fn add_matcher( self, url_regex: &'static str, access: Access, ) -> RequestMatcherAuthorizer
Adds a URL pattern with access requirements.
§Arguments
url_regex- A regex pattern to match URLsaccess- The access requirements for matching URLs
Sourcepub fn login_url(self, url: &'static str) -> RequestMatcherAuthorizer
pub fn login_url(self, url: &'static str) -> RequestMatcherAuthorizer
Sets the login URL (default: “/login”).
Unauthenticated users will be redirected to this URL unless HTTP Basic auth is enabled.
Sourcepub fn http_basic(self) -> RequestMatcherAuthorizer
pub fn http_basic(self) -> RequestMatcherAuthorizer
Enables HTTP Basic authentication.
§Spring Security Equivalent
HttpSecurity.httpBasic()
When enabled, unauthenticated requests will receive a
401 Unauthorized response with WWW-Authenticate: Basic realm="..."
header instead of being redirected to the login page.
Sourcepub fn http_basic_with_config(
self,
config: HttpBasicConfig,
) -> RequestMatcherAuthorizer
pub fn http_basic_with_config( self, config: HttpBasicConfig, ) -> RequestMatcherAuthorizer
Enables HTTP Basic authentication with custom configuration.
Trait Implementations§
Source§impl<B> Authorizer<B> for RequestMatcherAuthorizerwhere
B: 'static,
impl<B> Authorizer<B> for RequestMatcherAuthorizerwhere
B: 'static,
Source§fn process(
&self,
req: ServiceRequest,
user: Option<&User>,
next: impl FnOnce(ServiceRequest) -> Pin<Box<dyn Future<Output = Result<ServiceResponse<B>, Error>>>> + 'static,
) -> Pin<Box<dyn Future<Output = Result<ServiceResponse<EitherBody<B>>, Error>>>>
fn process( &self, req: ServiceRequest, user: Option<&User>, next: impl FnOnce(ServiceRequest) -> Pin<Box<dyn Future<Output = Result<ServiceResponse<B>, Error>>>> + 'static, ) -> Pin<Box<dyn Future<Output = Result<ServiceResponse<EitherBody<B>>, Error>>>>
Processes the authorization decision. Read more
Source§impl Default for RequestMatcherAuthorizer
impl Default for RequestMatcherAuthorizer
Source§fn default() -> RequestMatcherAuthorizer
fn default() -> RequestMatcherAuthorizer
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RequestMatcherAuthorizer
impl RefUnwindSafe for RequestMatcherAuthorizer
impl Send for RequestMatcherAuthorizer
impl Sync for RequestMatcherAuthorizer
impl Unpin for RequestMatcherAuthorizer
impl UnwindSafe for RequestMatcherAuthorizer
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
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> 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>
Converts
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>
Converts
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 more