pub trait ChimesAuthService<T>{
type Future: Future<Output = Option<T>>;
// Required methods
fn permit(
&self,
ust: &Option<T>,
req_method: &String,
url_pattern: &String,
) -> Self::Future;
fn authenticate(&self, token: &String) -> Self::Future;
fn nojwt_authenticate(&self, token: &String) -> Self::Future;
}Required Associated Types§
Required Methods§
Sourcefn permit(
&self,
ust: &Option<T>,
req_method: &String,
url_pattern: &String,
) -> Self::Future
fn permit( &self, ust: &Option<T>, req_method: &String, url_pattern: &String, ) -> Self::Future
检查用户是否能够通过指定的URL 根据系统的配置来确定是否能够通过这个URL请求
- ust为None值 此时根据req_method和url_pattern查询到该url为bypass=anonymous的模式,则返回Some(Default) 此时根据req_method和url_pattern查询到该url为bypass=user的模式,则返回None 此时根据req_method和url_pattern查询到该url为bypass=permit的模式,则返回None
- ust为Some值 此时根据req_method和url_pattern查询到该url为bypass=anonymous的模式,则返回true 此时根据req_method和url_pattern查询到该url为bypass=user的模式,则返回true 此时根据req_method和url_pattern查询到该url为bypass=permit的模式,则: a. 用户拥有可以访问该权限的角色:返回Some(T) b. 用户拥有可以访问该权限的资源: 返回Some(T) c. 用户不满足a和b,则返回None
Sourcefn authenticate(&self, token: &String) -> Self::Future
fn authenticate(&self, token: &String) -> Self::Future
检查Authentication信息是否为有效的用户信息 可以做如下处理
- token是一个唯一的字符串信息,通过以该token为key,从存储(数据库或Redis或内存)中查询到该Key所代表的用户信息;
- token是一个JWT Token,则解析该Token以获得登录的用户名等信息
- 再通过用户信息去查询用户详细信息
- 返回None表示该token已失效,返回Some表示该Token有效,且可以找到对应的帐户信息
Sourcefn nojwt_authenticate(&self, token: &String) -> Self::Future
fn nojwt_authenticate(&self, token: &String) -> Self::Future
检查Non-JWT Header信息是否为有效的用户信息 在使用特定的Header作为API请求时,可以使用该Header 可以做如下处理
- token是一个唯一的字符串信息,通过以该token为key,从存储(数据库或Redis或内存)中查询到该Key所代表的用户信息;
- token是一个NON-JWT Token,则解析该Token以获得登录的用户名等信息
- 再通过用户信息去查询用户详细信息
- 返回None表示该token已失效,返回Some表示该Token有效,且可以找到对应的帐户信息