Struct aliri_oauth2::ScopePolicy[][src]

pub struct ScopePolicy { /* fields omitted */ }
Expand description

An access policy based on OAuth2 scopes

This access policy takes the form of alternatives around required scopes. This policy will allow access if any of the alternatives would allow access. If the policy contains no alternatives, the default effect is to deny access.

Examples

Deny all requests

use aliri_traits::Policy;
use aliri_oauth2::{Scope, ScopePolicy};

let policy = ScopePolicy::deny_all();

let request = Scope::single("admin".parse()?);
assert!(policy.evaluate(&request).is_err());

Allow all requests

use aliri_traits::Policy;
use aliri_oauth2::{Scope, ScopePolicy};

let policy = ScopePolicy::allow_all();

let request = Scope::empty();
assert!(policy.evaluate(&request).is_ok());

Allow requests with a single scope

use aliri_traits::Policy;
use aliri_oauth2::{Scope, ScopePolicy};

let policy = ScopePolicy::allow_one(
    Scope::single("admin".parse()?)
);

let request = Scope::from_scope_tokens(vec![
    "admin".parse()?,
    "user".parse()?,
]);
assert!(policy.evaluate(&request).is_ok());

let user_request = Scope::from_scope_tokens(vec![
    "user".parse()?,
]);
assert!(policy.evaluate(&user_request).is_err());

Allow requests with multiple potential sets of scopes

use aliri_traits::Policy;
use aliri_oauth2::{Scope, ScopePolicy};

let mut policy = ScopePolicy::deny_all();
policy.allow(Scope::single("admin".parse()?));
policy.allow(Scope::from_scope_tokens(vec![
    "special".parse()?,
    "user".parse()?,
]));

let admin_request = Scope::from_scope_tokens(vec![
    "admin".parse()?,
]);
assert!(policy.evaluate(&admin_request).is_ok());

let user_request = Scope::from_scope_tokens(vec![
    "user".parse()?,
]);
assert!(policy.evaluate(&user_request).is_err());

let special_user_request = Scope::from_scope_tokens(vec![
    "special".parse()?,
    "user".parse()?,
]);
assert!(policy.evaluate(&special_user_request).is_ok());

Implementations

impl ScopePolicy[src]

pub fn deny_all() -> Self[src]

Constructs a policy that has no permissible alternatives

By default, this policy will deny all requests

pub fn allow_all() -> Self[src]

Constructs a policy that does not require any scopes (allow)

pub fn allow_one(scopes: Scope) -> Self[src]

Constructs a policy that requires this set of scopes

pub fn or_allow(self, scopes: Scope) -> Self[src]

Add an alternate set of required scopes

pub fn allow(&mut self, scopes: Scope)[src]

Add an alternative set of required scopes

Trait Implementations

impl Clone for ScopePolicy[src]

fn clone(&self) -> ScopePolicy[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for ScopePolicy[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Default for ScopePolicy[src]

fn default() -> ScopePolicy[src]

Returns the “default value” for a type. Read more

impl Extend<Scope> for ScopePolicy[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = Scope>, 
[src]

Extends a collection with the contents of an iterator. Read more

fn extend_one(&mut self, item: A)[src]

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

fn extend_reserve(&mut self, additional: usize)[src]

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

impl FromIterator<Scope> for ScopePolicy[src]

fn from_iter<I>(iter: I) -> Self where
    I: IntoIterator<Item = Scope>, 
[src]

Creates a value from an iterator. Read more

impl IntoIterator for ScopePolicy[src]

type Item = Scope

The type of the elements being iterated over.

type IntoIter = <Vec<Scope> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<'a> IntoIterator for &'a ScopePolicy[src]

type Item = &'a Scope

The type of the elements being iterated over.

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl PartialEq<ScopePolicy> for ScopePolicy[src]

fn eq(&self, other: &ScopePolicy) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &ScopePolicy) -> bool[src]

This method tests for !=.

impl Policy for ScopePolicy[src]

type Request = Scope

The request type evaluated by this policy

type Denial = InsufficientScope

The error returned when this policy denies a request

fn evaluate(&self, held: &Self::Request) -> Result<(), Self::Denial>[src]

Evaluates the request, producing an effect

impl Eq for ScopePolicy[src]

impl StructuralEq for ScopePolicy[src]

impl StructuralPartialEq for ScopePolicy[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<D> OwoColorize for D

fn fg<C>(&'a self) -> FgColorDisplay<'a, C, Self> where
    C: Color, 

Set the foreground color generically Read more

fn bg<C>(&'a self) -> BgColorDisplay<'a, C, Self> where
    C: Color, 

Set the background color generically. Read more

fn black(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black

fn on_black(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the foreground color to black

fn red(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red

fn on_red(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the foreground color to red

fn green(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green

fn on_green(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the foreground color to green

fn yellow(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow

fn on_yellow(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow

fn blue(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue

fn on_blue(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the foreground color to blue

fn magenta(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta

fn on_magenta(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta

fn purple(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple

fn on_purple(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple

fn cyan(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan

fn on_cyan(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan

fn white(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white

fn on_white(&'a self) -> BgColorDisplay<'a, White, Self>

Change the foreground color to white

fn bright_black(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black

fn on_bright_black(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black

fn bright_red(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red

fn on_bright_red(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red

fn bright_green(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green

fn on_bright_green(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green

fn bright_yellow(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow

fn on_bright_yellow(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow

fn bright_blue(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue

fn on_bright_blue(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue

fn bright_magenta(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta

fn on_bright_magenta(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta

fn bright_purple(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple

fn on_bright_purple(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple

fn bright_cyan(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan

fn on_bright_cyan(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan

fn bright_white(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white

fn on_bright_white(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white

fn bold(&'a self) -> BoldDisplay<'a, Self>

Make the text bold

fn dimmed(&'a self) -> DimDisplay<'a, Self>

Make the text dim

fn italic(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized

fn underline(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized

Make the text blink

Make the text blink (but fast!)

fn reversed(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors

fn hidden(&'a self) -> HiddenDisplay<'a, Self>

Hide the text

fn strikethrough(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text

fn color<Color>(&'a self, color: Color) -> FgDynColorDisplay<'a, Color, Self> where
    Color: DynColor, 

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more

fn on_color<Color>(&'a self, color: Color) -> BgDynColorDisplay<'a, Color, Self> where
    Color: DynColor, 

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more

fn truecolor(&'a self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'a, Rgb, Self>

Sets the foreground color to an RGB value.

fn on_truecolor(
    &'a self,
    r: u8,
    g: u8,
    b: u8
) -> BgDynColorDisplay<'a, Rgb, Self>

Sets the background color to an RGB value.

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.