-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add actix-casbin-auth to Actix official middleware list #92
Comments
I'll consider making a good actix middleware |
I had a thought on this. The first thing we need is an actix casbin actor. struct CasbinActor {
enforcer: Option<Enforcer>
} we use use casbin::{TryIntoAdapter, TryIntoModel};
use actix::{Addr, Supervisor};
impl CasbinActor {
pub async fn new<M: TryIntoModel, A: TryIntoAdapter>(m: M, a: A)
-> Result<Addr<Enforcer>> {
let enforcer: Enforcer = Enforcer::new(m, a).await?;
Supervisor::start(|_| CasbinActor {
enforcer: Some(enforcer)
})
}
} |
Then we define our message: use casbin::Result;
use actix::Message;
pub enum CasbinCmd {
Enforce(Vec<String>),
AddPolicy(Vec<String>),
AddPolicies(Vec<Vec<String>>),
RemovePolicy(Vec<String>),
RemovePolicies(Vec<Vec<String>>)
...
}
impl Message for CasbinActor {
type Result = Result<bool>;
} |
At last we should implement: impl Actor for CasbinActor {
...
}
impl Supervised for CasbinActor {
fn restarting(&mut self, _: &mut Self::Context) {
self.enforcer.take();
}
}
impl Handler<CasbinCmd> for CasbinActor {
type Result = ResponseActFuture<Self, Result<bool>>;
fn handle(&mut self, msg: CasbinCmd, _: &mut Self::Context) -> Self::Result {
...
}
} |
Users can then register In our middleware we access casbin enforcer by: if let Some(state) = req.app_data::<Enforcer>() {
// use casbin for access control
} else {
// deny the request
} |
The main problem of this idea is Users need to register casbin enforcer on app_data. How can we register an app data while creating a middleware? |
See also: actix/actix-web#1444 |
The actor is finished. see casbin-rs/actix-casbin#3. |
I was interested to work on this middleware Casbin posted (casbin/Casbin.NET#24) however working on a good actix middleware also seems interesting. Is there already a teambase working on this I can connect with? |
Have we put our product here? https://actix.rs/docs/middleware/ We can find the source code of that website and make a PR for it to add. |
@hsluoyz As far as I know, the only repo of Actix example is https://github.com/actix/examples/tree/master/casbin . I have finished the actor while the middleware is still work-in-progress. When the middleware is done, I will send a PR to https://github.com/actix/examples/tree/master/casbin. The previous version submitted by @PsiACE seems not using Actix middleware. |
@hackerchai You can provide a separate example with middleware. In addition, the example also needs to be added to casbin-rs/examples. |
I'm talking about how to advertise Casbin-RS better on Actix website: https://github.com/actix/actix-website https://github.com/actix/actix-website/blob/master/content/docs/middleware.md is the source code of https://actix.rs/docs/middleware/ Can anyone make a PR to add Casbin to their website? |
@hsluoyz The link you gave is about official middleware, but we are a third party, so it may not be suitable. |
@PsiACE BTW, there is a mistake in the middleware page of the casbin official website. The |
#82 Middleware has been implemented. |
@hackerchai thanks. Waiting for Actix guys' decision: actix/actix-website#170 |
@hsluoyz Thanks for your work. I will track that issue and implement an actix example using actix-casbin-middleware as soon as possible. |
We should modify this page: https://github.com/actix/actix-website/blob/master/content/docs/middleware.md to add Casbin into it as an authorization middleware. |
Made a PR: actix/actix-website#205 |
We have very active development for Casbin-RS now. However, our popularity is still under my estimation (129 stars). I hope we can do more advertisement in future to let people know and use our project.
The first thing we should do is to add Casbin middleware: https://github.com/actix/examples/tree/master/casbin to Actix official middleware list: https://actix.rs/docs/middleware/ . So Actix website visitors will also come to our GitHub page.
Can anyone work on this?
The text was updated successfully, but these errors were encountered: