{"id":37028946,"url":"https://github.com/wangzihaogithub/security-filter","last_synced_at":"2026-01-14T03:28:01.921Z","repository":{"id":57723985,"uuid":"463392938","full_name":"wangzihaogithub/security-filter","owner":"wangzihaogithub","description":"不需要复杂配置的登录用户拦截器","archived":false,"fork":false,"pushed_at":"2024-02-21T09:07:38.000Z","size":200,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-19T16:42:08.981Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wangzihaogithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-02-25T04:11:05.000Z","updated_at":"2024-10-15T09:30:40.000Z","dependencies_parsed_at":"2023-11-29T14:28:22.157Z","dependency_job_id":"55e3fdff-7f7f-4c2b-81e5-019af72634bf","html_url":"https://github.com/wangzihaogithub/security-filter","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/wangzihaogithub/security-filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangzihaogithub%2Fsecurity-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangzihaogithub%2Fsecurity-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangzihaogithub%2Fsecurity-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangzihaogithub%2Fsecurity-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wangzihaogithub","download_url":"https://codeload.github.com/wangzihaogithub/security-filter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangzihaogithub%2Fsecurity-filter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T03:28:01.203Z","updated_at":"2026-01-14T03:28:01.910Z","avatar_url":"https://github.com/wangzihaogithub.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# security-filter\n\n#### 介绍\n不需要复杂配置的用户登录拦截器.解决了dubbo-filter中嵌套调用dubbo查询问题\n\n\n#### 软件架构\n软件架构说明\n\n\n#### 安装教程\n\n1.  添加maven依赖, 在pom.xml中加入 [![Maven Central](https://img.shields.io/maven-central/v/com.github.wangzihaogithub/security-filter.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:com.github.wangzihaogithub%20AND%20a:security-filter)\n\n\n        \u003c!-- 登录access_token拦截器 --\u003e\n        \u003c!-- https://mvnrepository.com/artifact/com.github.wangzihaogithub/security-filter --\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.wangzihaogithub\u003c/groupId\u003e\n            \u003cartifactId\u003esecurity-filter\u003c/artifactId\u003e\n            \u003cversion\u003e1.1.14\u003c/version\u003e\n        \u003c/dependency\u003e\n        \n2.  实现业务逻辑\n\n\n        @Component\n        @Slf4j\n        public class HrSecurityAccessFilter extends WebSecurityAccessFilter\u003cInteger, HrAccessUser\u003e {\n            private final LocalCacheService cacheService = new LocalCacheService();\n            @Autowired\n            private CustomerLoginTokenService customerLoginTokenService;\n            @Autowired\n            private CustomerUserService customerUserService;\n        \n            public HrSecurityAccessFilter() {\n                super(Collections.singletonList(\"access_token\"));\n            }\n        \n            @Override\n            protected boolean isAccessSuccess(HrAccessUser user) {\n                return Objects.equals(user.getStatus(), CustomerUserStatusEnum.NORMAL.getKey())\n                        \u0026\u0026 Optional.ofNullable(user.getCustomer()).map(Customer::getEnableFlag).orElse(true);\n            }\n        \n            @Override\n            protected Integer selectUserId(HttpServletRequest request, String accessToken) {\n                CustomerLoginToken po = customerLoginTokenService.queryCustomerLoginTokenByToken(accessToken, CustomerLoginTokenScopeEnum.HR.getKey());\n                if (po == null) {\n                    return null;\n                }\n                return po.getCustomerUserId();\n            }\n        \n            @Override\n            protected HrAccessUser selectUser(HttpServletRequest request, Integer userId, String accessToken) {\n                CustomerUserDetailResp resp = cacheService.getIfSet(\"U\" + userId, () -\u003e {\n                    return customerUserService.queryDetailById(userId);\n                }, 20);\n                if (resp == null) {\n                    return null;\n                }\n                return HrAccessUser.convert(request, accessToken, resp);\n            }\n        \n        }\n        \n        \n3.  注册Filter路由\n\n\n        /**\n         * 只能是customer_user表的用户访问口。 {@link com.ig.hr.common.HrAccessUser}\n         */\n        @Bean\n        public FilterRegistrationBean hrSecurityFilter(HrSecurityAccessFilter filter) {\n            FilterRegistrationBean\u003cHrSecurityAccessFilter\u003e registration = new FilterRegistrationBean\u003c\u003e();\n            registration.setFilter(filter);\n            registration.addUrlPatterns(\"/api/*\", \"/statistics/*\");\n            return registration;\n        }\n\n\n#### 使用说明\n\n    // 操作当前用户\n    T : AccessUserUtil.getAccessUser()\n    Object : AccessUserUtil.getAccessUserValue(attrName)\n    boolean :AccessUserUtil.existAccessUser()\n    AccessUserUtil.setCurrentThreadAccessUser(accessUser);\n    AccessUserUtil.removeCurrentThreadAccessUser();\n    AccessUserUtil.runOnAccessUser(accessUser, runnable)\n    \n    // 异步传递\n    CompletableFuture\u003cResumeApiResponseData\u003cString\u003e\u003e future = new AccessUserCompletableFuture\u003c\u003e(RpcContext.getContext().getCompletableFuture());\n\n    // 自带dubbo拦截器，支持dubbo传递当前用户，使用者可以自行注册到dubbo的/META-INF/services里\n    // implements org.apache.dubbo.rpc.Filter \n    com.github.securityfilter.DubboAccessUserFilter \n\n    // 自带servlet拦截器，使用者可以实现并自行注册到tomcat里\n    // implements javax.servlet.Filter\n    com.github.securityfilter.WebSecurityAccessFilter","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangzihaogithub%2Fsecurity-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwangzihaogithub%2Fsecurity-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangzihaogithub%2Fsecurity-filter/lists"}