-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add access control migration app #4571
Merged
+3,820
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
npm-debug.log | ||
/dist | ||
# Cache used by TypeScript's incremental build | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/example-access-control-migration | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
module.exports = { | ||
extends: ['@loopback/eslint-config'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Exclude *.tsbuildinfo - cache for tsc incremental builds | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"bracketSpacing": false, | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/index.js" | ||
} | ||
] | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"editor.rulers": [80], | ||
"editor.tabCompletion": "on", | ||
"editor.tabSize": 2, | ||
"editor.trimAutoWhitespace": true, | ||
"editor.formatOnSave": true, | ||
|
||
"files.exclude": { | ||
"**/.DS_Store": true, | ||
"**/.git": true, | ||
"**/.hg": true, | ||
"**/.svn": true, | ||
"**/CVS": true, | ||
"dist": true, | ||
}, | ||
"files.insertFinalNewline": true, | ||
"files.trimTrailingWhitespace": true, | ||
|
||
"typescript.tsdk": "./node_modules/typescript/lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Watch and Compile Project", | ||
"type": "shell", | ||
"command": "npm", | ||
"args": ["--silent", "run", "build:watch"], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"problemMatcher": "$tsc-watch" | ||
}, | ||
{ | ||
"label": "Build, Test and Lint", | ||
"type": "shell", | ||
"command": "npm", | ||
"args": ["--silent", "run", "test:dev"], | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
}, | ||
"problemMatcher": ["$tsc", "$eslint-stylish", "$eslint-compact"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Check out https://hub.docker.com/_/node to select a new base image | ||
FROM node:10-slim | ||
|
||
# Set to a non-root built-in user `node` | ||
USER node | ||
|
||
# Create app directory (with user `node`) | ||
RUN mkdir -p /home/node/app | ||
|
||
WORKDIR /home/node/app | ||
|
||
# Install app dependencies | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
# where available (npm@5+) | ||
COPY --chown=node package*.json ./ | ||
|
||
RUN npm install | ||
|
||
# Bundle app source code | ||
COPY --chown=node . . | ||
|
||
RUN npm run build | ||
|
||
# Bind to all network interfaces so that it can be mapped to the host OS | ||
ENV HOST=0.0.0.0 PORT=3000 | ||
|
||
EXPOSE ${PORT} | ||
CMD [ "node", "." ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) IBM Corp. 2020. All Rights Reserved. | ||
Node module: @loopback/example-access-control-migration | ||
This project is licensed under the MIT License, full text below. | ||
|
||
-------- | ||
|
||
MIT license | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# @loopback/example-access-control-migration | ||
|
||
This example is migrated from | ||
[loopback-example-access-control](https://github.com/strongloop/loopback-example-access-control), | ||
and uses the authentication and authorization system in LoopBack 4 to implement | ||
the access control. | ||
|
||
## Overview | ||
|
||
This tutorial demonstrates how to implement a RBAC(Role Based Access Control) | ||
system and provides 5 endpoints to test different role's permissions. The | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
tutorial of building it from a dummy application documented in | ||
![auth-example-migration-tutorial](https://github.com/strongloop/loopback-next/blob/auth-migration/docs/site/migration/auth/example.md) | ||
|
||
## Setup | ||
|
||
First, you'll need to install a supported version of Node: | ||
|
||
- [Node.js](https://nodejs.org/en/) at v10 or greater | ||
|
||
Additionally, this tutorial assumes that you are comfortable with certain | ||
technologies, languages and concepts. | ||
|
||
- JavaScript (ES6) | ||
- [REST](http://www.restapitutorial.com/lessons/whatisrest.html) | ||
|
||
Lastly, you'll need to install the LoopBack 4 CLI toolkit: | ||
|
||
```sh | ||
npm i -g @loopback/cli | ||
``` | ||
|
||
## Try it out | ||
|
||
If you'd like to see the final results of this tutorial as an example | ||
application, follow these steps: | ||
|
||
```sh | ||
$ npm start | ||
|
||
Server is running at http://127.0.0.1:3000 | ||
``` | ||
|
||
Then try different roles' permissions by following the | ||
[try it out section](https://github.com/strongloop/loopback-next/blob/auth-migration/docs/site/migration/auth/example.md#try-it-out) | ||
|
||
### Need help? | ||
|
||
Check out our [Gitter channel](https://gitter.im/strongloop/loopback) and ask | ||
for help with this tutorial. | ||
|
||
### Bugs/Feedback | ||
|
||
Open an issue in [loopback-next](https://github.com/strongloop/loopback-next) | ||
and we'll take a look. | ||
|
||
## Contributions | ||
|
||
- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md) | ||
- [Join the team](https://github.com/strongloop/loopback-next/issues/110) | ||
|
||
## Tests | ||
|
||
Run `npm test` from the root folder. | ||
|
||
## Contributors | ||
|
||
See | ||
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors). | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"ids": { | ||
"Project": 3, | ||
"Team": 3, | ||
"User": 4, | ||
"UserCredentials": 4 | ||
}, | ||
"models": { | ||
"Project": { | ||
"1": "{\"id\":1,\"name\":\"project1\",\"balance\":90,\"ownerId\":1}", | ||
"2": "{\"id\":2,\"name\":\"project2\",\"balance\":0,\"ownerId\":2}" | ||
}, | ||
"Team": { | ||
"1": "{\"id\":1,\"ownerId\":1,\"memberIds\":[1,2]}", | ||
"2": "{\"id\":2,\"ownerId\":2,\"memberIds\":[2]}" | ||
}, | ||
"User": { | ||
"1": "{\"id\":1,\"username\":\"John\",\"email\":\"[email protected]\"}", | ||
"2": "{\"id\":2,\"username\":\"Jane\",\"email\":\"[email protected]\"}", | ||
"3": "{\"id\":3,\"username\":\"Bob\",\"email\":\"[email protected]\"}" | ||
}, | ||
"UserCredentials": { | ||
"1": "{\"password\":\"$2a$10$Yn1/fMOjW6A.CdH7Yxb7weVFYmkcQJQBaYaiRScS6sw7ty3aL4lHu\",\"userId\":1,\"id\":1}", | ||
"2": "{\"password\":\"$2a$10$Yn1/fMOjW6A.CdH7Yxb7weVFYmkcQJQBaYaiRScS6sw7ty3aL4lHu\",\"userId\":2,\"id\":2}", | ||
"3": "{\"password\":\"$2a$10$Yn1/fMOjW6A.CdH7Yxb7weVFYmkcQJQBaYaiRScS6sw7ty3aL4lHu\",\"userId\":3,\"id\":3}" | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/access-control-migration/fixtures/casbin/rbac_model.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[request_definition] | ||
r = sub, obj, act | ||
|
||
[policy_definition] | ||
p = sub, obj, act | ||
|
||
[role_definition] | ||
g = _, _ | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) | ||
|
||
[matchers] | ||
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act |
4 changes: 4 additions & 0 deletions
4
examples/access-control-migration/fixtures/casbin/rbac_policy.admin.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p, admin, project*, view-all | ||
p, admin, project1, donate | ||
p, admin, project2, donate | ||
g, u3, admin |
8 changes: 8 additions & 0 deletions
8
examples/access-control-migration/fixtures/casbin/rbac_policy.owner.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
p, p1_owner, project1, show-balance | ||
p, p1_owner, project1, donate | ||
p, p1_owner, project1, withdraw | ||
g, u1, p1_owner | ||
p, p2_owner, project2, show-balance | ||
p, p2_owner, project2, donate | ||
p, p2_owner, project2, withdraw | ||
g, u2, p2_owner |
7 changes: 7 additions & 0 deletions
7
examples/access-control-migration/fixtures/casbin/rbac_policy.team_member.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
p, p1_team, project1, show-balance | ||
p, p1_team, project1, donate | ||
g, u1, p1_team | ||
g, u2, p1_team | ||
p, p2_team, project2, show-balance | ||
p, p2_team, project2, donate | ||
g, u2, p2_team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/example-access-control-migration | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export * from './dist'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/example-access-control-migration | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
const application = require('./dist'); | ||
|
||
module.exports = application; | ||
|
||
if (require.main === module) { | ||
// Run the application | ||
const config = { | ||
rest: { | ||
port: +process.env.PORT || 3000, | ||
host: process.env.HOST || 'localhost', | ||
openApiSpec: { | ||
// useful when used with OpenAPI-to-GraphQL to locate your application | ||
setServersFromRequest: true, | ||
}, | ||
}, | ||
}; | ||
application.main(config).catch(err => { | ||
console.error('Cannot start the application.', err); | ||
process.exit(1); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/example-access-control-migration | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
// DO NOT EDIT THIS FILE | ||
// Add any additional (re)exports to src/index.ts instead. | ||
export * from './src'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know if it matters. It's missing a new line.