-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make auth extractor extendable (refactored), better redirect for OIDC…
…, add link to swagger UI for utoipa, update utoipa dependency version, fix path normalization for swagger docs
- Loading branch information
Showing
13 changed files
with
135 additions
and
144 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::collections::HashSet; | ||
|
||
use crate::auth::{Permission, ID}; | ||
|
||
#[derive(Debug, Clone)] | ||
/// roles and permissions available to a User | ||
/// | ||
/// use to control what users are and are not allowed to do | ||
pub struct Auth { | ||
pub user_id: ID, | ||
pub roles: HashSet<String>, | ||
pub permissions: HashSet<Permission>, | ||
} | ||
|
||
impl Auth { | ||
/// does the user with the id [`self.user_id`](`ID`) have the given `permission` | ||
pub fn has_permission(&self, permission: String) -> bool { | ||
self.permissions.contains(&Permission { | ||
permission, | ||
from_role: String::new(), | ||
}) | ||
} | ||
|
||
/// does the user with the id [`self.user_id`](`ID`) have all of the given `perms` | ||
pub fn has_all_permissions(&self, perms: Vec<String>) -> bool { | ||
perms.iter().all(|p| self.has_permission(p.to_string())) | ||
} | ||
|
||
/// does the user with the id [`self.user_id`](`ID`) have any of the given `perms` | ||
pub fn has_any_permission(&self, perms: Vec<String>) -> bool { | ||
perms.iter().any(|p| self.has_permission(p.to_string())) | ||
} | ||
|
||
/// does the user with the id [`self.user_id`](`ID`) have the given `role` | ||
pub fn has_role(&self, role: String) -> bool { | ||
self.roles.contains(&role) | ||
} | ||
|
||
/// does the user with the id [`self.user_id`](`ID`) have all of the given `roles` | ||
pub fn has_all_roles(&self, roles: Vec<String>) -> bool { | ||
roles.iter().all(|r| self.has_role(r.to_string())) | ||
} | ||
|
||
/// does the user with the id [`self.user_id`](`ID`) have any of the given `roles` | ||
pub fn has_any_roles(&self, roles: Vec<String>) -> bool { | ||
roles.iter().any(|r| self.has_role(r.to_string())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
mod auth; | ||
pub use auth::Auth; | ||
|
||
#[cfg(feature = "backend_actix-web")] | ||
mod auth_actixweb; | ||
#[cfg(feature = "backend_actix-web")] | ||
pub use auth_actixweb::Auth; | ||
pub use auth_actixweb::AuthError; | ||
|
||
#[cfg(feature = "backend_poem")] | ||
mod auth_poem; | ||
#[cfg(feature = "backend_poem")] | ||
pub use auth_poem::Auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.