Sureness need dataSource to authenticate and authorize, eg: role data, user data etc.
The dataSource can load from txt, dataBase, no dataBase or annotation etc.
We provide interfaces SurenessAccountProvider
, PathTreeProvider
for user implement to load data from the dataSource where they want.
SurenessAccountProvider
- Account datasource provider interface.
PathTreeProvider
- Resource uri-role datasource provider interface.
The way of sureness
to implement the annotation dataSource is not to judge the aop before calling the method,
but to scan the data in the annotation as the auth dataSource when startup,
which facilitates the unification of the process and the independence of the framework.
Here is an introduction to show how to use annotation config auth data.
@Bean
TreePathRoleMatcher pathRoleMatcher() {
// Instantiate the resource permission path matcher, which will match the required role information
// according to the requested path and existing resource permission data.
DefaultPathRoleMatcher pathRoleMatcher = new DefaultPathRoleMatcher();
// Instantiate the resource permission data loader - `AnnotationLoader`,
// which implements the PathTreeProvider interface.
AnnotationPathTreeProvider pathTreeProvider = new AnnotationPathTreeProvider();
// Set the package path to be scanned by AnnotationLoader, which will scan the
// @RequiresRoles, @WithoutAuth annotations on all class methods under the package path to obtain data.
pathTreeProvider.setScanPackages(Arrays.asList("com.usthe.sureness.sample.tom.controller"));
// Set the AnnotationLoader dataSource as the sureness auth dataSource.
pathRoleMatcher.addPathTreeProvider(pathTreeProvider);
pathRoleMatcher.buildTree();
return pathRoleMatcher;
}
@RequiresRoles(roles = {"role1", "role2"}, mapping = "/resource", method = "post")
Means that the resource /resource===post requires role role1 or role2 to access
@WithoutAuth(mapping = "/resource/*", method = "put")
Means that the resource /resource/*===put can be accessed by any request
sureness
provides the function of loading multiple data sources at the same time, that is,
we can simultaneously use the annotation dataSource and database auth dataSource in the sureness configuration.此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。