说明:本篇文章部分内容参考了网上的文章(在下文已给出原文链接),由于本人能力有限,如果有书写错误的地方,欢迎各位大佬批评指正!我们互相交流,学习,共同进步!
该项目的地址:https://github.com/xiaoheng1/nacos_read
关于安全如何设计:
@Retention(RetentionPolicy.RUNTIME)
public @interface Secured {
/**
* The action type of the request.
*
* @return action type, default READ
*/
ActionTypes action() default ActionTypes.READ;
/**
* The name of resource related to the request.
*
* @return resource name
*/
String resource() default StringUtils.EMPTY;
/**
* Resource name parser. Should have lower priority than resource().
*
* @return class type of resource parser
*/
Class<? extends ResourceParser> parser() default DefaultResourceParser.class;
}
关于权限使用:com.alibaba.nacos.core.auth.AuthFilter#doFilter
权限模块比较简单,依托于 Spring,定义 Secured 注解,然后在 Filter 中解析 Secured,完成权限