Comments (4)
Please show your code.
from sequelize-adapter.
This is my schema model:
[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 && (regEqJollyMatch(r.act, p.act) || actionGroupMatch(r.obj, r.act, p.act))
This is the ACL Manager:
const casbin = require('casbin');
const { SequelizeAdapter } = require('casbin-sequelize-adapter');
const { conf } = require('shared/config');
const { acls } = conf;
const { stream: dbConfig } = conf.db;
const fs = require('fs');
const { resolve, join } = require('path');
const { loadMatchers } = require('./aclMatchers');
const loadAclEnforcer = async function loadAclEnforcer(ctx) {
let caspinEnforcer;
try {
const sequelizeAdapter = await SequelizeAdapter.newAdapter({
username: dbConfig.user,
host: dbConfig.host,
port: dbConfig.port,
password: dbConfig.pw,
database: dbConfig.name,
schema: dbConfig.schema,
dialect: 'postgres',
logging: conf.logQuery
});
const confPath = resolve(process.cwd(), acls.confPath);
const policiesDir = resolve(process.cwd(), acls.policiesDir);
caspinEnforcer = await casbin.newEnforcer(
confPath,
sequelizeAdapter
);
loadMatchers(ctx, caspinEnforcer);
let policiesNeedsRefresh = false;
fs.readdirSync(policiesDir).forEach(filePath => {
if (!filePath.match(/^(.*)\.acl\.json$/gi)) {
return;
}
const policyPath = join(policiesDir, filePath);
const policiesGroup = require(policyPath);
if (policiesGroup && policiesGroup.length > 0) {
policiesGroup.forEach(async (policy) => {
let added;
if (policy[0] === 'g') {
added = await caspinEnforcer.addNamedGroupingPolicy(...policy);
} else if (policy[0] === 'p') {
added = await caspinEnforcer.addNamedPolicy(...policy);
}
policiesNeedsRefresh = policiesNeedsRefresh || added;
});
}
});
// here Casbin duplicates the policies
await caspinEnforcer.savePolicy();
} catch (error) {
ctx.logger.error('An error occurred loading the ACLs.');
throw error;
}
return caspinEnforcer;
};
module.exports = { loadAclEnforcer };
from sequelize-adapter.
Remove the await caspinEnforcer.savePolicy();
from sequelize-adapter.
Casbin can automatically save policies.
from sequelize-adapter.
Related Issues (20)
- Leveraging connection pool instead of creating connection every time in adapter for each REST API HOT 4
- Bug in table schema HOT 20
- TypeError: Cannot read property 'getQueryInterface' of undefined HOT 4
- Sequelize adapter not recognising ssl option when using postgres uri HOT 2
- how long to start support v6 HOT 22
- package.json repo url is wrong HOT 2
- Remove or ignore the 'id' column HOT 11
- Unable to verify policy HOT 8
- Add support for custom table name HOT 2
- removeFilteredNamedPolicy does not respect ptype HOT 3
- Switch from travis-ci.org to GitHub Actions CI and setup semantic-release HOT 3
- Add semantic-bot HOT 6
- Switch badge from travis-ci.org to GitHub Actions CI HOT 2
- Fix CI error HOT 5
- CI error: error TS2307: Cannot find module 'sequelize/types/hooks' or its corresponding type declarations. HOT 4
- CI bug: semantic-release failed to release on PR merge HOT 9
- Fix CI errors HOT 6
- Vulnerability: Sequalize version < v6.19.1 HOT 1
- Multiple adapter instance based on postgre schema? HOT 7
- Multiple adapter instance based on postgres schema(already opened before) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sequelize-adapter.