René's URL Explorer Experiment


Title: 用基于接口的可扩展枚举提供更多权限支持 · Issue #286 · APIJSON/APIJSON · GitHub

Open Graph Title: 用基于接口的可扩展枚举提供更多权限支持 · Issue #286 · APIJSON/APIJSON

X Title: 用基于接口的可扩展枚举提供更多权限支持 · Issue #286 · APIJSON/APIJSON

Description: APIJSON 本身的权限定义在枚举 RequestRole 中,且与框架本身的耦合度较高,如果想要在此基础上定义新的权限级别不是很方便。虽然可以通过重载 AbstractVerifier.verifyAccess 方法来自定义鉴权,但是用起来还是相对比较复杂,如(这个 issue https://github.com/Tencent/APIJSON/issues/228)。 为了尝试解决这一问题,我定义了一个新的接口 IRequestRole,令 RequestRol...

Open Graph Description: APIJSON 本身的权限定义在枚举 RequestRole 中,且与框架本身的耦合度较高,如果想要在此基础上定义新的权限级别不是很方便。虽然可以通过重载 AbstractVerifier.verifyAccess 方法来自定义鉴权,但是用起来还是相对比较复杂,如(这个 issue https://github.com/Tencent/APIJSON/issues/228)。 为了尝试解决这...

X Description: APIJSON 本身的权限定义在枚举 RequestRole 中,且与框架本身的耦合度较高,如果想要在此基础上定义新的权限级别不是很方便。虽然可以通过重载 AbstractVerifier.verifyAccess 方法来自定义鉴权,但是用起来还是相对比较复杂,如(这个 issue https://github.com/Tencent/APIJSON/issues/228)。 为了尝试解决这...

Opengraph URL: https://github.com/APIJSON/APIJSON/issues/286

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"用基于接口的可扩展枚举提供更多权限支持","articleBody":"APIJSON 本身的权限定义在枚举 RequestRole 中,且与框架本身的耦合度较高,如果想要在此基础上定义新的权限级别不是很方便。虽然可以通过重载 AbstractVerifier.verifyAccess 方法来自定义鉴权,但是用起来还是相对比较复杂,如(这个 issue https://github.com/Tencent/APIJSON/issues/228)。\r\n\r\n为了尝试解决这一问题,我定义了一个新的接口 IRequestRole,令 RequestRole 实现这个接口,再依次修改框架中其他相关联的位置。通过 IRequestRole.register 方法,用户可以注册自己的权限枚举。通过 IRequestRole.get 方法,可以从权限字符串转换回对应的权限枚举。\r\n\r\n根据我在自己的示例项目上的测试,基本可以满足需要。但是因为包含一些破坏性变更(`MethodAccess` 注解返回 `String[]`),我希望先了解下各位的意见和建议。\r\n\r\n可以从这里获取修改后的代码(含 APIJSON ORM 和 Framework)及示例项目: \r\nhttps://github.com/jerrylususu/apijson_role_extend \r\n\r\n具体的使用方法如下:\r\n\r\n1. 首先定义自己的权限枚举类(可参照 `apijson.demo.config.MyRole`)\r\n\r\n   ```java\r\n   public enum MyRole implements IRequestRole {\r\n       STUDENT,\r\n       TEACHER,\r\n       PRINCIPAL;\r\n   }\r\n   ```\r\n\r\n2. 在 `DemoApplication` 的 static 块中注册自己的权限枚举类\r\n\r\n   ```java\r\n   static {\r\n       IRequestRole.register(MyRole.class);\r\n       APIJSONApplication.DEFAULT_APIJSON_CREATOR = // ...\r\n   }\r\n   ```\r\n\r\n3. 在自己的用户类(`model.User`)中添加 `List\u003cString> role` 属性,并添加对应的 getter, setter 方法 \r\n\r\n4. 重载 `AbstractVerifier.verifyAccess`,补全一部分框架中未完成的鉴权逻辑(判断用户请求中声明的权限,是否的确存在于用户的权限列表中)\r\n\r\n   > 此部分与用户自己的用户类的类名相关,因此没有在框架中实现(可能可以用 `Visitor` 接口实现?)\r\n\r\n   ```java\r\n   // 自定义的权限,需要检查是否存在于列表中\r\n   if ( !(config.getRole() instanceof RequestRole) ) {\r\n       List\u003cString> visitorRoleList = new ArrayList\u003c>();\r\n       // 处理数据库中 role 列为 NULL\r\n       if (((User) this.visitor).getRole() != null) {\r\n           visitorRoleList = ((User) this.visitor).getRole();\r\n       }\r\n   \r\n       if (!visitorRoleList.contains(config.getRole().toString())){\r\n           // 用户声明的权限不在自己的 role 列表中(伪造权限)\r\n           throw new IllegalAccessException(\"当前用户没有声明的权限!\");\r\n       }\r\n   \r\n   }\r\n   ```\r\n\r\n5. 在数据库 `Access` 表中完成对应配置\r\n\r\n  * GET/GETS/HEAD/HEADS:[\"STUDENT\", \"TEACHER\",\"PRINCIPAL\"]\r\n  * POST/DELETE:[\"TEACHER\"]\r\n  * PUT:[\"OWNER\",\"PRINCIPAL\"]\r\n\r\n\r\n6. 在调用时先登录,然后用 `@role` 声明对应的权限\r\n\r\n   ```json\r\n   // POST /get\r\n   {\r\n       \"[]\": {\r\n           \"Course\": {\r\n               \"@role\": \"TEACHER\"\r\n           }\r\n       }\r\n   }\r\n   ```\r\n","author":{"url":"https://github.com/jerrylususu","@type":"Person","name":"jerrylususu"},"datePublished":"2021-08-01T08:27:20Z","url":"https://github.com/APIJSON/APIJSON/issues/286"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:433741fa-6d81-6970-3ab6-744701bb44cc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA82E:3339EE:34665B:47B61C:6AFCAF33
html-safe-nonce0f08cb71179063a5ec20005c8507ebe96a46e782fcdc8637b1b45b3e2f4159aa
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODJFOjMzMzlFRTozNDY2NUI6NDdCNjFDOjZBRkNBRjMzIiwidmlzaXRvcl9pZCI6IjQ1MjI0NTgzMjgwNTEwMDMxODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacdc439034f294a50b392ef0089e84c5e3006bcad85f2e962afd0fff8b21f7713e
hovercard-subject-tagissue:957429990
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/APIJSON/APIJSON/286/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f83322c37dc9ee5f7badfe894148c83f009582504f4dbb97e00b3550132324a5/APIJSON/APIJSON/issues/286
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f83322c37dc9ee5f7badfe894148c83f009582504f4dbb97e00b3550132324a5/APIJSON/APIJSON/issues/286
og:image:altAPIJSON 本身的权限定义在枚举 RequestRole 中,且与框架本身的耦合度较高,如果想要在此基础上定义新的权限级别不是很方便。虽然可以通过重载 AbstractVerifier.verifyAccess 方法来自定义鉴权,但是用起来还是相对比较复杂,如(这个 issue https://github.com/Tencent/APIJSON/issues/228)。 为了尝试解决这...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejerrylususu
hostnamegithub.com
expected-hostnamegithub.com
Nonee3084aead77cbcb4f4904fba53851fa1a0546b0dec3619bd250815e72588dc6d
turbo-cache-controlno-preview
go-importgithub.com/APIJSON/APIJSON git https://github.com/APIJSON/APIJSON.git
octolytics-dimension-user_id41146037
octolytics-dimension-user_loginAPIJSON
octolytics-dimension-repository_id74359442
octolytics-dimension-repository_nwoAPIJSON/APIJSON
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id74359442
octolytics-dimension-repository_network_root_nwoAPIJSON/APIJSON
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5410e4bebd3e45b138c853ecef3992279d86d5af
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/APIJSON/APIJSON/issues/286#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAPIJSON%2FAPIJSON%2Fissues%2F286
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAPIJSON%2FAPIJSON%2Fissues%2F286
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=APIJSON%2FAPIJSON
Reloadhttps://github.com/APIJSON/APIJSON/issues/286
Reloadhttps://github.com/APIJSON/APIJSON/issues/286
Reloadhttps://github.com/APIJSON/APIJSON/issues/286
APIJSONhttps://github.com/APIJSON
APIJSONhttps://github.com/APIJSON/APIJSON
Codehttps://github.com/APIJSON/APIJSON
Issues237 (237)https://github.com/APIJSON/APIJSON/issues
Pull requestshttps://github.com/APIJSON/APIJSON/pulls
Actionshttps://github.com/APIJSON/APIJSON/actions
Wikihttps://github.com/APIJSON/APIJSON/wiki
Security and qualityhttps://github.com/APIJSON/APIJSON/security
Insightshttps://github.com/APIJSON/APIJSON/insights
https://github.com/APIJSON/APIJSON
New issuehttps://github.com/login?return_to=https://github.com/APIJSON/APIJSON/issues/286
New issuehttps://github.com/login?return_to=https://github.com/APIJSON/APIJSON/issues/286
用基于接口的可扩展枚举提供更多权限支持https://github.com/APIJSON/APIJSON/issues/286#top
Access 权限https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Access%20%E6%9D%83%E9%99%90%22
Ecosystem 周边生态完善生态(Go语言版、更多Demo、周边工具等)https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Ecosystem%20%E5%91%A8%E8%BE%B9%E7%94%9F%E6%80%81%22
Enhancement 增强增强功能、提高性能等https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Enhancement%20%E5%A2%9E%E5%BC%BA%22
https://github.com/jerrylususu
jerrylususuhttps://github.com/jerrylususu
on Aug 1, 2021https://github.com/APIJSON/APIJSON/issues/286#issue-957429990
https://github.com/Tencent/APIJSON/issues/228)。https://github.com/Tencent/APIJSON/issues/228%EF%BC%89%E3%80%82
https://github.com/jerrylususu/apijson_role_extendhttps://github.com/jerrylususu/apijson_role_extend
https://github.com/TommyLemon
TommyLemonhttps://github.com/TommyLemon
on Aug 1, 2021https://github.com/APIJSON/APIJSON/issues/286#issuecomment-890568052
https://github.com/Tencent/APIJSON/blob/c663fb21e598873e3395c66192bcfadb04babf60/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.javahttps://github.com/Tencent/APIJSON/blob/c663fb21e598873e3395c66192bcfadb04babf60/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java
TommyLemonhttps://github.com/TommyLemon
Access 权限https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Access%20%E6%9D%83%E9%99%90%22
Ecosystem 周边生态完善生态(Go语言版、更多Demo、周边工具等)https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Ecosystem%20%E5%91%A8%E8%BE%B9%E7%94%9F%E6%80%81%22
Enhancement 增强增强功能、提高性能等https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Enhancement%20%E5%A2%9E%E5%BC%BA%22
on Aug 5, 2021https://github.com/APIJSON/APIJSON/issues/286#event-5114969482
Sign up for freehttps://github.com/signup?return_to=https://github.com/APIJSON/APIJSON/issues/286
Sign in to commenthttps://github.com/login?return_to=https://github.com/APIJSON/APIJSON/issues/286
Access 权限https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Access%20%E6%9D%83%E9%99%90%22
Ecosystem 周边生态完善生态(Go语言版、更多Demo、周边工具等)https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Ecosystem%20%E5%91%A8%E8%BE%B9%E7%94%9F%E6%80%81%22
Enhancement 增强增强功能、提高性能等https://github.com/APIJSON/APIJSON/issues?q=state%3Aopen%20label%3A%22Enhancement%20%E5%A2%9E%E5%BC%BA%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.