casbin-rs / actix-casbin-auth Goto Github PK
View Code? Open in Web Editor NEWCasbin Actix-web access control middleware
Home Page: https://github.com/casbin/casbin-rs
Casbin Actix-web access control middleware
Home Page: https://github.com/casbin/casbin-rs
Hello,
I'm having trouble simply adding this crate to my project. The cfg conditional featured-based use statements
do not seem to be taken into account. Here are the errors:
error[E0252]: the name `IoError` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/adapter/file_adapter.rs:20:10
|
13 | io::{BufReader, Error as IoError, ErrorKind},
| ---------------- previous import of the type `IoError` here
...
20 | io::{Error as IoError, ErrorKind},
| ^^^^^^^^^^^^^^^^--
| |
| `IoError` reimported here
| help: remove unnecessary import
|
= note: `IoError` must be defined only once in the type namespace of this module
error[E0252]: the name `ErrorKind` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/adapter/file_adapter.rs:20:28
|
13 | io::{BufReader, Error as IoError, ErrorKind},
| --------- previous import of the type `ErrorKind` here
...
20 | io::{Error as IoError, ErrorKind},
| ^^^^^^^^^ `ErrorKind` reimported here
|
= note: `ErrorKind` must be defined only once in the type namespace of this module
error[E0252]: the name `Path` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/adapter/file_adapter.rs:21:5
|
14 | path::Path,
| ---------- previous import of the type `Path` here
...
21 | path::Path,
| ^^^^^^^^^^ `Path` reimported here
|
= note: `Path` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
21 | path::Path as OtherPath,
| ^^^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `File` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/adapter/file_adapter.rs:25:5
|
11 | fs::File,
| -------- previous import of the type `File` here
...
25 | fs::File,
| ^^^^^^^^ `File` reimported here
|
= note: `File` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
25 | fs::File as OtherFile,
| ^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `BufReader` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/adapter/file_adapter.rs:26:42
|
13 | io::{BufReader, Error as IoError, ErrorKind},
| --------- previous import of the type `BufReader` here
...
26 | io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
| ^^^^^^^^^ `BufReader` reimported here
|
= note: `BufReader` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
26 | io::{AsyncBufReadExt, AsyncWriteExt, BufReader as OtherBufReader},
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `Cursor` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/config.rs:13:11
|
6 | io::{BufReader, Cursor, Error as IoError, ErrorKind},
| ------ previous import of the type `Cursor` here
...
13 | use std::{io::Cursor, path::Path};
| ^^^^^^^^^^ `Cursor` reimported here
|
= note: `Cursor` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
13 | use std::{io::Cursor as OtherCursor, path::Path};
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `Path` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/config.rs:13:23
|
10 | use async_std::{fs::File, path::Path};
| ---------- previous import of the type `Path` here
...
13 | use std::{io::Cursor, path::Path};
| ^^^^^^^^^^ `Path` reimported here
|
= note: `Path` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
13 | use std::{io::Cursor, path::Path as OtherPath};
| ^^^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `BufReader` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/config.rs:16:36
|
6 | io::{BufReader, Cursor, Error as IoError, ErrorKind},
| --------- previous import of the type `BufReader` here
...
16 | AsyncBufReadExt, AsyncReadExt, BufReader, Error as IoError, ErrorKind,
| ^^^^^^^^^ `BufReader` reimported here
|
= note: `BufReader` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
16 | AsyncBufReadExt, AsyncReadExt, BufReader as OtherBufReader, Error as IoError, ErrorKind,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `IoError` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/config.rs:16:47
|
6 | io::{BufReader, Cursor, Error as IoError, ErrorKind},
| ---------------- previous import of the type `IoError` here
...
16 | AsyncBufReadExt, AsyncReadExt, BufReader, Error as IoError, ErrorKind,
| ^^^^^^^^^^^^^^^^--
| |
| `IoError` reimported here
| help: remove unnecessary import
|
= note: `IoError` must be defined only once in the type namespace of this module
error[E0252]: the name `ErrorKind` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/config.rs:16:65
|
6 | io::{BufReader, Cursor, Error as IoError, ErrorKind},
| --------- previous import of the type `ErrorKind` here
...
16 | AsyncBufReadExt, AsyncReadExt, BufReader, Error as IoError, ErrorKind,
| ^^^^^^^^^-
| |
| `ErrorKind` reimported here
| help: remove unnecessary import
|
= note: `ErrorKind` must be defined only once in the type namespace of this module
error[E0252]: the name `File` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/config.rs:20:5
|
10 | use async_std::{fs::File, path::Path};
| -------- previous import of the type `File` here
...
20 | use tokio::fs::File;
| ^^^^^^^^^^^^^^^ `File` reimported here
|
= note: `File` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
20 | use tokio::fs::File as OtherFile;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0252]: the name `Path` is defined multiple times
--> /home/arnaud/.cargo/registry/src/github.com-1ecc6299db9ec823/casbin-2.0.5/src/model/default_model.rs:19:5
|
16 | use async_std::path::Path;
| --------------------- previous import of the type `Path` here
...
19 | use std::path::Path;
| ^^^^^^^^^^^^^^^ `Path` reimported here
|
= note: `Path` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
19 | use std::path::Path as OtherPath;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors
These errors appear whether or not I add the features = ["runtime-tokio"]
to my Cargo.toml. I'm working with rustc 1.49.0 (e1884a8e3 2020-12-29)
and here is the list of dependencies from my Cargo.toml
:
[dependencies]
actix-casbin-auth = { version = "0.4.4", features = ["runtime-tokio"] }
actix-files = "0.5.0"
actix-redis = "0.9.1"
actix-session = "0.4.0"
actix-web = { version = "3", default-features = false }
chrono = { version = "0.4.19", features = ["serde"]}
diesel = { version = "^1.4.4", features = ["postgres","r2d2","chrono"] }
diesel-adapter = { version = "0.8.3", features = ["postgres"] }
diesel-derive-enum = { version = "1.1.0", features = ["postgres"] }
dotenv = "0.15"
env_logger = "0.7"
failure = "0.1.8"
futures = "0.3.8"
lazy_static = "1.4.0"
lettre = "0.10.0-alpha.4"
log = "0.4.13"
regex = "1.4.3"
sailfish = "0.3.0"
sailfish-macros = "0.3.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sodiumoxide = "0.2.6"
strum_macros = "0.20.1"
uuid = { version = "0.8", features = ["serde", "v4"] }
walkdir = "2.3.1"
Any help would be appreciated.
remove the following unwrap
actix-casbin-auth/src/middleware.rs
Line 38 in 31e6808
change to sync function, async will has at least 100ns's overhead
actix-casbin-auth/src/middleware.rs
Line 44 in 31e6808
change to sync function
actix-casbin-auth/src/middleware.rs
Line 48 in 31e6808
An enforcer is put in an Arc<RwLock<>>
and is write-locked before use. But enforce()
method takes an immutable reference, it doesn't need to be locked. Maybe enforce_mut should be used? https://github.com/casbin/casbin-rs/blob/c88f13cb59a428b05a4f9b03e83f3f5bea36dd78/src/cached_enforcer.rs#L233
Hi.
Could you please publish the actual master branch?
The published version is outdated.
It should be refreshed.
Thank you.
for now the middleware use original error page built in actix-web,like
Ok(req.into_response(HttpResponse::Forbidden().finish().into_body()));
Ok(req.into_response(HttpResponse::BadGateway().finish().into_body()));
Ok(req.into_response(HttpResponse::Unauthorized().finish().into_body()));
but for some cases, we wanna keep the error message having the same structured response like other error type.
so maybe add some fields in CasbinService
to config the response of error payload?
The newest casbin crate appears to be version 2.2.0. Can you please update that (and maybe other deps) in this package?
If/when the actix-web dependency is updated to v3, the dependency in Cargo.toml should ideally be:
- actix-web = "3.0.2"
+ actix-web = { version = "3.0.2", default-features = false }
As well as support of tokio 1.0
Can you create an example for Casbin Middlewaze with Model and Policy get from Postgres (Diesel) and self Auth please ?
enforcer: Arc<RwLock> why use lock,When I test the performance, the performance drops dramatically under using Rwlock
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.