Skip to content

Commit

Permalink
abac bismillah
Browse files Browse the repository at this point in the history
  • Loading branch information
emreakay committed Oct 26, 2022
1 parent 6fe18f3 commit fa5c25b
Show file tree
Hide file tree
Showing 37 changed files with 239 additions and 200 deletions.
1 change: 1 addition & 0 deletions README-abac.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ backlog

- config e aranacak model klasörü eklenecek ?? AStart a mı eklemek lazım?
- abac rule'u eloquent'a - dönüştüren builder ?? şimdilik scope içinden yapıldı
- model'in rule'larını alan servis veya util ?

-----

Expand Down
52 changes: 38 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/aurorawebsoftware/aauth/Check%20&%20fix%20styling?label=code%20style)](https://github.com/aurorawebsoftware/aauth/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/aurorawebsoftware/aauth.svg?style=flat-square)](https://packagist.org/packages/aurora/aauth)

Hierarchical Rol-Permission Based **Laravel Auth Package** with Limitless Hierarchical Level of Organizations
Organization Based (OrBAC) , Attibute Based (ABAC) , Rol-Permission (RBAC) Based Authentication Methods Combined **Laravel Auth Package** with Limitless Hierarchical Level of Organizations and Limitless Attribute Conditions

# Features

- Organization Based Access Controllable (OrBAC) Eloquent Models
- Attribute Based Access Controllable (ABAC) Eloquent Models
- Role Based Access Control (RoBAC)
- Permissions Based Access Control
- Lean & Non-Complex Architecture
- PolyMorphic Relationships of Model & Organization Node
- DB Row Level Filtering for the Role with ABAC
- Built-in Blade Directives for permission control inside **Blade** files
- Mysql, MariaDB, Postgres Support
- Community Driven and Open Source Forever

---


[<img src="https://banners.beyondco.de/AAuth%20for%20Laravel.png?theme=light&packageManager=composer+require&packageName=aurorawebsoftware%2Faauth&pattern=jigsaw&style=style_1&description=Hierarchical+Role-Permission+Based+Laravel+Auth+Package+with+Limitless+Hierarchical+Level+of+Organizations&md=1&showWatermark=0&fontSize=175px&images=shield-check&widths=auto" />](https://github.com/AuroraWebSoftware/AAuth)
[<img src="https://banners.beyondco.de/AAuth%20for%20Laravel.png?theme=light&packageManager=composer+require&packageName=aurorawebsoftware%2Faauth&pattern=jigsaw&style=style_1&description=OrBAC, ABAC, RBAC Combined Laravel Auth Package&md=1&showWatermark=0&fontSize=175px&images=shield-check&widths=auto" />](https://github.com/AuroraWebSoftware/AAuth)

# Installation

Expand Down Expand Up @@ -88,7 +90,7 @@ return [
];
```

# Main Philosophy
# Main Philosophy of AAuth OrBAC

In computer system security, there are several approaches to restrict system access to authorized users.

Expand Down Expand Up @@ -139,6 +141,12 @@ Principal dynamically *without writing one line of code?*
- Canada
- .....

# Main Philosophy of AAuth ABAC

// todo coming soon ....


---
**AAuth may be your first class assistant package.**

---
Expand Down Expand Up @@ -187,6 +195,9 @@ file's permission['system'] array.
an Organization Role.
Organization Permissions should be added inside `aauth.php` config file's permission['organization'] array.

## ABAC
// todo coming soon

## Role

Roles are assigned to users. Each User can have multiple roles.
Expand Down Expand Up @@ -226,6 +237,10 @@ be an organization node and can be access controllable.
It means that; Only Authorized User Role can be access the relating model, or in other words, Each role only can access
the models which is on Authenticated Sub-Organization Tree of User's Role.

### Model - ABAC rules
// todo coming soon


# Usage

Before using this, please make sure that you published the config files.
Expand Down Expand Up @@ -283,10 +298,10 @@ $organizationService->createOrganizationScope($data);
```

### Updating an Organization Scope
the contributors' space
// todo help wanted

### Deleting an Organization Scope
the contributors' space
// todo help wanted


### Creating an Organization Node without Model Relationship
Expand All @@ -304,10 +319,10 @@ $organizationService->createOrganizationNode($data);
```

### Updating an Organization Node
the contributors' space
// todo help wanted

### Deleting an Organization Node
the contributors' space
// todo help wanted

## Role Permission Service

Expand Down Expand Up @@ -341,10 +356,10 @@ $createdRole = $rolePermissionService->createRole($data);
```

### Updating a Role
...
// todo help wanted

### Deleting a Role
....
// todo help wanted

### Attaching a Role to a User
```php
Expand Down Expand Up @@ -389,7 +404,7 @@ $rolePermissionService->attachOrganizationRoleToUser($organizationNode->id, $cre
```

### Creating a System Role and Attaching to a User
....
// todo help wanted


## Using AAuth Interface and Trait with Eloquent Models
Expand All @@ -411,7 +426,11 @@ class ExampleModel extends Model implements AAuthOrganizationNodeInterface
}
```

## Using ABAC Interface and Trait with Eloquent Models
// todo

## AAuth Service and Facade Methods
// todo

### Current Roles All Permissions
current user's selected roles permissions with **AAuth Facade**
Expand Down Expand Up @@ -444,8 +463,7 @@ $organizationNodes = AAuth::organizationNodes();
```

### Get one specified organization node
.....

// todo help wanted

### Descendant nodes can be checked
with this method you can check is a organization node is descendant of another organization node.
Expand All @@ -469,16 +487,22 @@ $exampleModel = ExampleModel::find(1);
$relatedOrganizationModel = $exampleModel->relatedAAuthOrganizationNode()
```

## Getting allowed Organization Nodes Only.
## Getting authorized Models only. (OrBAC)

after adding `AAuthOrganizationNode` trait to your model, you are adding a global scope which filters the permitted data.

Thus you can simply use any eloquent model method without adding anything
Thus, you can simply use any eloquent model method without adding anything

```php
ExampleModel::all();
```

## Creating Role - ABAC Rules
// todo

## Getting authorized Models only. (ABAC)
// todo

## Getting All Model Collection without any access control
```php
ExampleModel::withoutGlobalScopes()->all()
Expand Down
12 changes: 7 additions & 5 deletions Readme-todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
- Facade yerine sadece service provide kullanılabilir mi? aliass?
- singleton içinde facade yerine service class olabilir
- phpStan problemleri
- pint
- pint, github actions
- can fonkisyonlarında yetki 1 kez çekilebilir
- Readme contribution

- ABAC


## Done
Expand Down Expand Up @@ -35,17 +35,19 @@
- role perm. service validation ve excepiton unit testleri, validation excepitonarlını testti
- org. service validation ve excepiton unit testleri, validation excepitonarlını testti
- test with coverage
- ABAC
- translations
- request's ve validations
- github pages ?
- test'lerin publish edilmesi ve namespacelerin replace edilmesi
- postgress testleri için github actions
- laravel gates register policy


## Dökümantasyon

- config'ler
- migr. ve seeder'ların çalıştırılması
- github pages docs
- ABAC docs


## backlog
- github pages ?
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require": {
"php": "^8.1",
"illuminate/contracts": "^9.0",
"laravel/pint": "^1.2",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
Expand Down
23 changes: 12 additions & 11 deletions config/aauth.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

// config for AuroraWebSoftware/AAuth
return [
'permissions' => [
'system' => [
// example system permission
// key => translation
'edit_something_for_system' => 'aauth/system.edit_something_for_system',
'create_something_for_system' => 'aauth/system.create_something_for_system',
],
'organization' => [
// example organization permission
'edit_something_for_organization' => 'aauth/organization.edit_something_for_organization',
'create_something_for_organization' => 'aauth/organization.create_something_for_organization',
],
'system' => [
// example system permission
// key => translation
'edit_something_for_system' => 'aauth/system.edit_something_for_system',
'create_something_for_system' => 'aauth/system.create_something_for_system',
],
'organization' => [
// example organization permission
'edit_something_for_organization' => 'aauth/organization.edit_something_for_organization',
'create_something_for_organization' => 'aauth/organization.create_something_for_organization',
],
],
];
13 changes: 4 additions & 9 deletions database/migrations/2021_10_18_142336_seed_initial_data.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
<?php


use AuroraWebSoftware\AAuth\Models\OrganizationNode;
use AuroraWebSoftware\AAuth\Models\OrganizationScope;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class SeedInitialData extends Migration
{

/**
* Run the migrations.
*
* @return void
*/

public function up()
{
$organizationScope = new OrganizationScope();
$organizationScope->id = 1;
$organizationScope->name = "Root Scope";
$organizationScope->name = 'Root Scope';
$organizationScope->level = 1;
$organizationScope->status = "active";
$organizationScope->status = 'active';
$organizationScope->save();


if (config('database.default') == 'pgsql') {
DB::select("
SELECT setval(pg_get_serial_sequence('organization_scopes', 'id'), coalesce(max(id)+1, 1), false)
Expand All @@ -35,8 +31,8 @@ public function up()
$on = new OrganizationNode();
$on->id = 1;
$on->organization_scope_id = 1;
$on->name = "Root Node";
$on->path = "1";
$on->name = 'Root Node';
$on->path = '1';
$on->save();

if (config('database.default') == 'pgsql') {
Expand All @@ -52,7 +48,6 @@ public function up()
*
* @return void
*/

public function down()
{
OrganizationScope::whereId(1)->delete();
Expand Down
11 changes: 4 additions & 7 deletions database/seeders/SampleDataSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function run()
'parent_id' => $organizationNode1->id,
]
);
$organizationNode2->path = $organizationNode1->id . '/' . $organizationNode2->id;
$organizationNode2->path = $organizationNode1->id.'/'.$organizationNode2->id;
$organizationNode2->save();

$organizationNode3 = OrganizationNode::create(
Expand All @@ -82,7 +82,7 @@ public function run()
'parent_id' => $organizationNode1->id,
]
);
$organizationNode3->path = $organizationNode1->id . '/' . $organizationNode3->id;
$organizationNode3->path = $organizationNode1->id.'/'.$organizationNode3->id;
$organizationNode3->save();

$organizationNode4 = OrganizationNode::create(
Expand All @@ -95,10 +95,9 @@ public function run()
'parent_id' => $organizationNode2->id,
]
);
$organizationNode4->path = $organizationNode2->path . '/' . $organizationNode4->id;
$organizationNode4->path = $organizationNode2->path.'/'.$organizationNode4->id;
$organizationNode4->save();


$role1 = Role::create([
'type' => 'system',
'name' => 'System Role 1',
Expand Down Expand Up @@ -174,7 +173,6 @@ public function run()
'organization_node_id' => $organizationNode4->id,
]);


$systemPermissions = config('aauth.permissions.system');

foreach ($systemPermissions as $key => $val) {
Expand Down Expand Up @@ -236,14 +234,13 @@ public function run()

//loop through the tables
foreach ($tables as $table) {

// if the table is not to be ignored then:
if (! in_array($table->table_name, $ignores)) {
//Get the max id from that table and add 1 to it
$seq = DB::table($table->table_name)->max('id') + 1;

// alter the sequence to now RESTART WITH the new sequence index from above
DB::select('ALTER SEQUENCE ' . $table->table_name . '_id_seq RESTART WITH ' . $seq);
DB::select('ALTER SEQUENCE '.$table->table_name.'_id_seq RESTART WITH '.$seq);
}
}
}
Expand Down
Loading

0 comments on commit fa5c25b

Please sign in to comment.