ics/ssi-bundle

Bundle security extention

0.2.7 2022-04-08 09:12 UTC

README

Symfony bundle for extend security and logging

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

composer require ics/ssi-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require ics/ssi-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    ICS\SsiBundle\SsiBundle::class => ['all' => true],
];

Step 3: Adding bundle routing

Add routes in applications config/routes.yaml

# config/routes.yaml

# ...
ssi_bundle:
    resource: '@SsiBundle/config/routes.yaml'
    prefix: /ssi
# ...

Step 4: Install Database

For install database :

# Installer la base de données

php bin/console doctrine:schema:create

For update database :

# Mise a jour la base de données

php bin/console doctrine:schema:update -f

Adding bundle to EasyAdmin

Step 1: Add entities to dashboard

Add this MenuItems in your dashboard Controller/Admin/DashboardController.php

    // Controller/Admin/DashboardController.php
    use ICS\SsiBundle\Entity\Account;
    use ICS\SsiBundle\Entity\Log;

    class DashboardController extends AbstractDashboardController
    {
        public function configureMenuItems(): iterable
        {
            // ...
            yield MenuItem::section('Security', 'fa fa-shield');
            yield MenuItem::linkToCrud('Accounts', 'fa fa-user-circle', Account::class);
            yield MenuItem::linkToCrud('Logs', 'fa fa-newspaper', Log::class);
            // ...
        }
    }

Step 2: Add twig widgets to dashboard

    {# templates/admin/dashboard.html.twig #}

    {% extends "@EasyAdmin/page/content.html.twig" %}

    {% block page_content %}

        {% include "@Ssi/admin/logs.html.twig" %}

    {% endblock %}

Install bundle fixtures

# Every data in database will destruct

php bin/console doctrine:fixture:load

The Passwords for created users are :

  • admin : adminPassword
  • user[1~10] : userPassword

Log Entity

For log an entity just add @Log Annotation on entity declaration you must define the actions and property properties

value for actions can :

  • "add" On add entity in database
  • "update" On update entity in database
  • "delete" On delete entity in database
  • "all" On all action of entity in database

for property make a property than return the log message you want

    use Doctrine\ORM\Mapping as ORM;
    use ICS\SsiBundle\Annotation\Log;
    /**
     * @ORM\Entity()
     * @ORM\Table()
     * @Log(actions={"all"},property="logMessage")
     */
    class Account implements UserInterface
    {
        /**
         * @ORM\Column(type="string", length=180, unique=true)
         */
        private $username;

        public function getLogMessage()
        {
            return $this->username.' (#'.$this->getId().')';
        }

    }

Configure keycloak authentification

For enabled a keycloak authentification add this lines in .env file :

    #Keycloak configuration

    KEYCLOAK_URL="<url of keycloak server>"
    KEYCLOAK_REALM="<realm for keycloak>"
    KEYCLOAK_CLIENT_ID="<client_id of keycloak server>"
    KEYCLOAK_CLIENT_SECRET="<secret of client_id"

you can enabled keycloak user auto creation :

# config/packages/ssi.yaml

ssi:
  keycloak:
    auto_create_user: true

by default unknow user as ignored.

Configure Active Directory authentification

For enabled a Active Directory authentification add this lines in .env file :

    #Keycloak configuration

    ACTIVE_DIRECTORY_HOST="<Active Directory domain controller IP or DNS name>"
    ACTIVE_DIRECTORY_BASEDN="<User base DN (dc=example,dc=com)>"
    ACTIVE_DIRECTORY_DOMAIN="<Active Directory short domain name>"

you can enabled Active Directory user auto creation :

# config/packages/ssi.yaml

ssi:
  active_directory:
    auto_create_user: true

by default unknow user as ignored.