Skip to content

Commit b450b40

Browse files
committed
Add copyright header.
1 parent 6b5cecd commit b450b40

6 files changed

+90
-16
lines changed

BasicAuthorizer.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2-
// Use of this source code is governed by a MIT style
3-
// license that can be found in the LICENSE file.
1+
// Copyright 2018 The Casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
415
// BasicAuthorizer class stores the casbin handler
516
class BasicAuthorizer {
617
constructor (ctx, enforcer) {
@@ -26,4 +37,5 @@ class BasicAuthorizer {
2637
return enforcer.enforce(user, path, method)
2738
}
2839
}
40+
2941
module.exports = BasicAuthorizer

authz.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2-
// Use of this source code is governed by a MIT style
3-
// license that can be found in the LICENSE file.
1+
// Copyright 2018 The Casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
414

515
const { Enforcer } = require('casbin')
616
const BasicAuthorizer = require('./BasicAuthorizer')
17+
718
// authz returns the authorizer, uses a Casbin enforcer as input
819
module.exports = function authz (options) {
920
return async (ctx, next) => {

test/customize.test.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
/**
2-
* @author Balalals
3-
* @date 2018-08-29
4-
* @Description:
5-
*/
1+
// Copyright 2018 The Casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
615
const app = require('./customizeServer')
716
const request = require('supertest')(app)
17+
818
afterAll(() => {
919
app.close()
1020
})
21+
1122
it('customize authorizer tests', async () => {
1223
const response = await request
1324
.get('/dataset1/name')

test/customizeServer.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
/**
2-
* @author Balalals
3-
* @date 2018-08-29
4-
* @Description:
5-
*/
1+
// Copyright 2018 The Casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
615
const Koa = require('koa')
716
const { Enforcer } = require('casbin')
817
const authz = require('../authz')
918
const app = new Koa()
1019
const BasicAuthorizer = require('../BasicAuthorizer')
20+
1121
// set userinfo
1222
app.use(async (ctx, next) => {
1323
try {
@@ -19,6 +29,7 @@ app.use(async (ctx, next) => {
1929
ctx.status = 503
2030
}
2131
})
32+
2233
// use CustomizeAuthorizer
2334
class CustomizeAuthorizer extends BasicAuthorizer {
2435
// override function
@@ -33,6 +44,7 @@ class CustomizeAuthorizer extends BasicAuthorizer {
3344
// return enforcer.enforce(user, path, method)
3445
// }
3546
}
47+
3648
app.use(authz({
3749
newEnforcer: async () => {
3850
// load the casbin model and policy from files, database is also supported.

test/server.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2018 The Casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
const Koa = require('koa')
216
const { Enforcer } = require('casbin')
317
const authz = require('../authz')

test/test.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2018 The Casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
const app = require('./server')
216
const request = require('supertest')(app)
317

0 commit comments

Comments
 (0)