blob: d0df7b57ed9c6484a1e28d0445ee8344e01dbfe4 [file]
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import { Component, OnInit } from '@angular/core';
import { newEnforcer, StringAdapter, Enforcer, newModelFromString } from 'casbin';
@Component({
selector: 'app-enforcer',
templateUrl: './enforcer.component.html',
styleUrls: ['./enforcer.component.css'],
})
export class EnforcerComponent implements OnInit {
model = newModelFromString(`
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
`);
adapter = new StringAdapter(`
p, alice, data1, read
p, bob, data2, write
`);
enforcer!: Enforcer;
title = 'Casbin';
sub!: string;
obj!: string;
act!: string;
result: boolean = false;
constructor() {
this.sub = 'alice';
this.obj = 'data1';
this.act = 'read';
newEnforcer(this.model, this.adapter).then((e) => {
this.enforcer = e;
this.enforcer.enforce(this.sub, this.obj, this.act).then((res) => {
this.result = res;
});
});
}
ngOnInit(): void {}
}