-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [#702] allow overwriting casbin configuration
This is an unsatble feature. You can overwrite casbin configuration to change permissions for roles: guest, registered and admin. You can do it by adding this toml file config section: ```toml [unstable.auth.casbin] model = """ [request_definition] r = role, action [policy_definition] p = role, action [policy_effect] e = some(where (p.eft == allow)) [matchers] m = r.role == p.role && r.action == p.action """ policy = """ admin, GetAboutPage admin, GetLicensePage admin, AddCategory admin, DeleteCategory admin, GetCategories admin, GetImageByUrl admin, GetSettings admin, GetSettingsSecret admin, GetPublicSettings admin, AddTag admin, DeleteTag admin, GetTags admin, AddTorrent admin, GetTorrent admin, DeleteTorrent admin, GetTorrentInfo admin, GenerateTorrentInfoListing admin, GetCanonicalInfoHash admin, ChangePassword admin, BanUser registered, GetAboutPage registered, GetLicensePage registered, GetCategories registered, GetImageByUrl registered, GetPublicSettings registered, GetTags registered, AddTorrent registered, GetTorrent registered, GetTorrentInfo registered, GenerateTorrentInfoListing registered, GetCanonicalInfoHash registered, ChangePassword guest, GetAboutPage guest, GetLicensePage guest, GetCategories guest, GetPublicSettings guest, GetTags guest, GetTorrent guest, GetTorrentInfo guest, GenerateTorrentInfoListing guest, GetCanonicalInfoHash """ ``` For example, if you wnat to force users to login to see the torrent list you can remove the following line from the policy: ``` guest, GenerateTorrentInfoListing ``` NOTICE: This is an unstable feature. It will panic with wrong casbin configuration, invalid roles, etcetera.
- Loading branch information
1 parent
a39ad21
commit c1a5c25
Showing
5 changed files
with
145 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Unstable configuration options. | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub struct Unstable { | ||
/// The casbin configuration used for authorization. | ||
#[serde(default = "Unstable::default_auth")] | ||
pub auth: Option<Auth>, | ||
} | ||
|
||
impl Default for Unstable { | ||
fn default() -> Self { | ||
Self { | ||
auth: Self::default_auth(), | ||
} | ||
} | ||
} | ||
|
||
impl Unstable { | ||
fn default_auth() -> Option<Auth> { | ||
None | ||
} | ||
} | ||
|
||
/// Unstable auth configuration options. | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub struct Auth { | ||
/// The casbin configuration used for authorization. | ||
#[serde(default = "Auth::default_casbin")] | ||
pub casbin: Option<Casbin>, | ||
} | ||
|
||
impl Default for Auth { | ||
fn default() -> Self { | ||
Self { | ||
casbin: Self::default_casbin(), | ||
} | ||
} | ||
} | ||
|
||
impl Auth { | ||
fn default_casbin() -> Option<Casbin> { | ||
None | ||
} | ||
} | ||
|
||
/// Authentication options. | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub struct Casbin { | ||
/// The model. See <https://casbin.org>. | ||
pub model: String, | ||
|
||
/// The policy. See <https://casbin.org>. | ||
pub policy: 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