Commit 1d9e7078 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Version avec une bdd postgres dans un service docker

parent d2e8f398
Pipeline #5273 failed with stage
in 12 seconds
###########################################################################################
#
# Image pour le dev.
#
###########################################################################################
ARG PHP_VERSION ARG PHP_VERSION
FROM unicaen-dev-php${PHP_VERSION}-apache FROM unicaen-dev-php${PHP_VERSION}-apache
...@@ -18,11 +12,7 @@ ENV APACHE_CONF_DIR=/etc/apache2 \ ...@@ -18,11 +12,7 @@ ENV APACHE_CONF_DIR=/etc/apache2 \
## Installation de packages requis. ## Installation de packages requis.
RUN apt-get update -qq && \ RUN apt-get update -qq && \
apt-get install -y \ apt-get install -y \
sqlite3 \ php${PHP_VERSION}-pgsql
php${PHP_VERSION}-pdo-sqlite
RUN pecl install ast && \
echo "extension=ast.so" > ${PHP_CONF_DIR}/cli/conf.d/ast.ini
# Nettoyage # Nettoyage
RUN apt-get autoremove -y && apt-get clean && rm -rf /tmp/* /var/tmp/* RUN apt-get autoremove -y && apt-get clean && rm -rf /tmp/* /var/tmp/*
......
...@@ -11,20 +11,20 @@ ...@@ -11,20 +11,20 @@
## Module Demo ## Module Demo
Le module démo fournit une base de données de démonstration permettant d'avoir une authentification locale Le squelette d'application possède un module "démo" qui utilise une base de données PostgreSQL de démonstration
qui fonctionne. permettant d'avoir une authentification locale qui fonctionne.
Jetez un oeil à la base de données de démo présente dans le module 'Demo' : Cette base de données est fournie par le service `db` (fichier de config `docker-compose.yml`).
Il y a également un service `adminer` fournissant de quoi explorer la base de données avec l'outil
$ docker-compose run skeleton-application sqlite3 module/Demo/data/db/demo.sqlite ".schema" ["Adminer"](https://www.adminer.org) en vous rendant à l'adresse `localhost:8432` et en utilisant les informations
de connexion à la bdd présentes dans le `docker-compose.yml`.
Interrogez la table `user` pour vérifier la présence de l'utilisateur local `demo`, exemple :
$ docker-compose run skeleton-application sqlite3 module/Demo/data/db/demo.sqlite "select * from user;"
## Configuration du projet ## Configuration du projet
- Renommez `config/autoload/local.php.dist` en `local.php`. - Renommez `config/autoload/local.php.dist` en `local.php` :
```bash
mv config/autoload/local.php.dist config/autoload/local.php
```
- Copiez dans votre dossier `config/autoload` les fichiers de configuration locaux et globaux `.dist` - Copiez dans votre dossier `config/autoload` les fichiers de configuration locaux et globaux `.dist`
des bibliothèques utilisées sans leur extension `.dist` : des bibliothèques utilisées sans leur extension `.dist` :
...@@ -35,7 +35,8 @@ cp vendor/unicaen/auth/config/unicaen-auth.global.php.dist config/autoload/unica ...@@ -35,7 +35,8 @@ cp vendor/unicaen/auth/config/unicaen-auth.global.php.dist config/autoload/unica
cp vendor/unicaen/auth/config/unicaen-auth.local.php.dist config/autoload/unicaen-auth.local.php cp vendor/unicaen/auth/config/unicaen-auth.local.php.dist config/autoload/unicaen-auth.local.php
``` ```
- Le cas échéant, reportez-vous aux docs des modules concernés pour adapter ces fichiers de configuration à vos besoins : - Le cas échéant, reportez-vous aux docs des modules concernés pour adapter ces fichiers de configuration
à vos besoins :
- [unicaen/app](https://git.unicaen.fr/lib/unicaen/app) - [unicaen/app](https://git.unicaen.fr/lib/unicaen/app)
- [unicaen/auth](https://git.unicaen.fr/lib/unicaen/auth) - [unicaen/auth](https://git.unicaen.fr/lib/unicaen/auth)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "472fe5bd83d98e8ce14043b863c18ace", "content-hash": "a868570eddc575aa0674ec170b0b473f",
"packages": [ "packages": [
{ {
"name": "beberlei/assert", "name": "beberlei/assert",
...@@ -2176,11 +2176,11 @@ ...@@ -2176,11 +2176,11 @@
}, },
{ {
"name": "unicaen/app", "name": "unicaen/app",
"version": "dev-zf-3.x", "version": "3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/app.git", "url": "https://git.unicaen.fr/lib/unicaen/app.git",
"reference": "f18f3a9ae51144c0bf5dc07b6139fba07314fc6a" "reference": "fe92dcafbefbfdcdea019ef0c963b8b5efca4037"
}, },
"require": { "require": {
"beberlei/assert": "^2.9", "beberlei/assert": "^2.9",
...@@ -2236,22 +2236,22 @@ ...@@ -2236,22 +2236,22 @@
] ]
}, },
"description": "Module de base des applications unicaen", "description": "Module de base des applications unicaen",
"time": "2019-09-16T09:49:44+00:00" "time": "2019-09-16T13:15:55+00:00"
}, },
{ {
"name": "unicaen/auth", "name": "unicaen/auth",
"version": "dev-zf-3.x", "version": "3.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/auth.git", "url": "https://git.unicaen.fr/lib/unicaen/auth.git",
"reference": "12c05066041f8c305c1c95ac933ed95eb128401a" "reference": "433bbe5a7d3f5089cfc390ea5cbef90b9a56186e"
}, },
"require": { "require": {
"beberlei/assert": "^2.9",
"jasig/phpcas": "^1.3", "jasig/phpcas": "^1.3",
"php": "7.3.*",
"ramsey/uuid": "^3.7", "ramsey/uuid": "^3.7",
"unicaen/app": "dev-zf-3.x", "unicaen/app": "^3.0",
"unicaen/bjy-authorize": "dev-zf-3.x" "unicaen/bjy-authorize": "^3.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.6" "phpunit/phpunit": "^5.6"
...@@ -2267,19 +2267,19 @@ ...@@ -2267,19 +2267,19 @@
] ]
}, },
"description": "Module d'authentification pour les applications Unicaen", "description": "Module d'authentification pour les applications Unicaen",
"time": "2019-09-11T09:05:45+00:00" "time": "2019-09-18T12:02:04+00:00"
}, },
{ {
"name": "unicaen/bjy-authorize", "name": "unicaen/bjy-authorize",
"version": "dev-zf-3.x", "version": "3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/bjy-authorize.git", "url": "https://git.unicaen.fr/lib/unicaen/bjy-authorize.git",
"reference": "790c5fddb1a3a89ed904faa633722c57c5c472f5" "reference": "9480124324d8b1c6de56cdf27ab687fea2216c84"
}, },
"require": { "require": {
"doctrine/common": "^2.7", "doctrine/common": "^2.7",
"php": ">=5.6 || >=7.0", "php": "7.3.*",
"zendframework/zend-cache": "^2.8", "zendframework/zend-cache": "^2.8",
"zendframework/zend-eventmanager": "^3.2", "zendframework/zend-eventmanager": "^3.2",
"zendframework/zend-http": "^2.10", "zendframework/zend-http": "^2.10",
...@@ -2328,24 +2328,23 @@ ...@@ -2328,24 +2328,23 @@
"zf2", "zf2",
"zfc-user" "zfc-user"
], ],
"time": "2019-03-21T09:05:22+00:00" "time": "2019-09-18T07:15:38+00:00"
}, },
{ {
"name": "unicaen/faq", "name": "unicaen/faq",
"version": "dev-zf-3.x", "version": "3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/faq.git", "url": "https://git.unicaen.fr/lib/unicaen/faq.git",
"reference": "c6f03783941b0dd0c553a0e01cd84519959550e2" "reference": "1caeeb64aa47aeaba737e06e221d1b82b380dd46"
}, },
"require": { "require": {
"unicaen/app": "dev-zf-3.x" "unicaen/app": "^3.0"
}, },
"require-dev": { "require-dev": {
"phpspec/prophecy": "^1.6", "phpspec/prophecy": "^1.6",
"phpunit/phpunit": "^5.6", "phpunit/phpunit": "^5.6",
"snapshotpl/zf-snap-event-debugger": "1.*", "zendframework/zend-test": "^3.0"
"zendframework/zend-test": "^2.4 || ^3.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
...@@ -2357,18 +2356,18 @@ ...@@ -2357,18 +2356,18 @@
] ]
}, },
"description": "Module de foire aux questions", "description": "Module de foire aux questions",
"time": "2019-03-20T15:37:21+00:00" "time": "2019-09-18T08:11:53+00:00"
}, },
{ {
"name": "unicaen/ldap", "name": "unicaen/ldap",
"version": "dev-zf-3.x", "version": "3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.unicaen.fr/lib/unicaen/ldap.git", "url": "https://git.unicaen.fr/lib/unicaen/ldap.git",
"reference": "2dca4963d882e9e9ea590a34ed22de3b6d922941" "reference": "26bcaef4f761087a975139b2d1e54e935869b78c"
}, },
"require": { "require": {
"php": "^5.6 || ^7.0", "php": "7.3.*",
"zendframework/zend-config": "^3.2", "zendframework/zend-config": "^3.2",
"zendframework/zend-i18n": "^2.9", "zendframework/zend-i18n": "^2.9",
"zendframework/zend-ldap": "^2.10", "zendframework/zend-ldap": "^2.10",
...@@ -2380,7 +2379,7 @@ ...@@ -2380,7 +2379,7 @@
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": ">=3.7", "phpunit/phpunit": ">=3.7",
"zendframework/zend-test": ">=2.2" "zendframework/zend-test": "^3.2"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
...@@ -2394,7 +2393,7 @@ ...@@ -2394,7 +2393,7 @@
] ]
}, },
"description": "Module Ldap des applications Unicaen", "description": "Module Ldap des applications Unicaen",
"time": "2019-05-23T13:04:14+00:00" "time": "2019-09-18T09:15:50+00:00"
}, },
{ {
"name": "zendframework/zend-authentication", "name": "zendframework/zend-authentication",
...@@ -5452,16 +5451,16 @@ ...@@ -5452,16 +5451,16 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "7.0.7", "version": "7.0.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800" "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f",
"reference": "7743bbcfff2a907e9ee4a25be13d0f8ec5e73800", "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -5470,7 +5469,7 @@ ...@@ -5470,7 +5469,7 @@
"php": "^7.2", "php": "^7.2",
"phpunit/php-file-iterator": "^2.0.2", "phpunit/php-file-iterator": "^2.0.2",
"phpunit/php-text-template": "^1.2.1", "phpunit/php-text-template": "^1.2.1",
"phpunit/php-token-stream": "^3.1.0", "phpunit/php-token-stream": "^3.1.1",
"sebastian/code-unit-reverse-lookup": "^1.0.1", "sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^4.2.2", "sebastian/environment": "^4.2.2",
"sebastian/version": "^2.0.1", "sebastian/version": "^2.0.1",
...@@ -5511,7 +5510,7 @@ ...@@ -5511,7 +5510,7 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2019-07-25T05:31:54+00:00" "time": "2019-09-17T06:24:36+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
...@@ -5655,16 +5654,16 @@ ...@@ -5655,16 +5654,16 @@
}, },
{ {
"name": "phpunit/php-token-stream", "name": "phpunit/php-token-stream",
"version": "3.1.0", "version": "3.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git", "url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff",
"reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -5700,7 +5699,7 @@ ...@@ -5700,7 +5699,7 @@
"keywords": [ "keywords": [
"tokenizer" "tokenizer"
], ],
"time": "2019-07-25T05:29:42+00:00" "time": "2019-09-17T06:23:10+00:00"
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
...@@ -6735,13 +6734,7 @@ ...@@ -6735,13 +6734,7 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": [],
"unicaen/app": 20,
"unicaen/auth": 20,
"unicaen/bjy-authorize": 20,
"unicaen/faq": 20,
"unicaen/ldap": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],
......
<?php <?php
return array( return [
'translator' => array( 'translator' => [
'locale' => 'fr_FR', 'locale' => 'fr_FR',
), ],
); ];
DoctrineORMModule/ DoctrineORMModule/
db/
\ No newline at end of file
...@@ -14,3 +14,22 @@ services: ...@@ -14,3 +14,22 @@ services:
volumes: volumes:
- .:/app - .:/app
working_dir: /app working_dir: /app
db:
image: postgres
restart: always
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: demo
ports:
- 8432:5432
volumes:
- ./data/db:/var/lib/postgresql/data
- ./docker/db/:/docker-entrypoint-initdb.d/
adminer:
image: adminer
restart: always
ports:
- 9080:8080
CREATE TABLE "user" (
id BIGSERIAL PRIMARY KEY,
username VARCHAR(255) DEFAULT NULL,
email VARCHAR(255) DEFAULT NULL,
display_name VARCHAR(64) DEFAULT NULL,
password VARCHAR(128) NOT NULL,
state SMALLINT default 1
) ;
CREATE UNIQUE INDEX user_username_unique ON "user" (username);
alter table "user" add PASSWORD_RESET_TOKEN varchar(256) default null;
create unique index USER_PASSWORD_RESET_TOKEN_UN on "user" (PASSWORD_RESET_TOKEN);
CREATE TABLE user_role (
id BIGSERIAL PRIMARY KEY,
role_id VARCHAR(64) NOT NULL,
is_default SMALLINT NOT NULL DEFAULT 0,
parent_id BIGINT DEFAULT NULL,
ldap_filter varchar(255) DEFAULT NULL,
FOREIGN KEY (parent_id) REFERENCES user_role (id) ON DELETE SET NULL
);
CREATE UNIQUE INDEX user_role_roleid_unique ON user_role (role_id);
CREATE TABLE user_role_linker (
user_id BIGINT NOT NULL,
role_id BIGINT NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE,
FOREIGN KEY (role_id) REFERENCES user_role (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX user_role_linker_unique ON user_role_linker (user_id, role_id);
CREATE TABLE IF NOT EXISTS categorie_privilege (
id BIGSERIAL PRIMARY KEY,
code VARCHAR(150) NOT NULL,
libelle VARCHAR(200) NOT NULL,
ordre INT
);
CREATE UNIQUE INDEX categorie_privilege_unique ON categorie_privilege (code);
CREATE TABLE IF NOT EXISTS privilege (
id BIGSERIAL PRIMARY KEY,
categorie_id BIGINT NOT NULL,
code VARCHAR(150) NOT NULL,
libelle VARCHAR(200) NOT NULL,
ordre INT,
FOREIGN KEY (categorie_id) REFERENCES categorie_privilege (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX privilege_unique ON privilege (code);
CREATE TABLE IF NOT EXISTS role_privilege (
role_id BIGINT NOT NULL,
privilege_id BIGINT NOT NULL,
PRIMARY KEY (role_id, privilege_id),
FOREIGN KEY (role_id) REFERENCES user_role (id) ON DELETE CASCADE,
FOREIGN KEY (privilege_id) REFERENCES privilege (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX role_privilege_unique ON role_privilege (role_id, privilege_id);
-- Données
INSERT INTO user_role (id, role_id, is_default, parent_id) VALUES
(1, 'Standard', 1, NULL),
(2, 'Gestionnaire', 0, 1),
(3, 'Super-gestionnaire', 0, 2),
(4, 'Administrateur', 0, 3);
INSERT INTO categorie_privilege (id, code, libelle, ordre) VALUES
(1, 'droit', 'Gestion des droits', 1);
INSERT INTO privilege (id, categorie_id, code, libelle, ordre) VALUES
(1, 1, 'role-visualisation', 'Rôles - Visualisation', 1),
(2, 1, 'role-edition', 'Rôles - Édition', 2),
(3, 1, 'privilege-visualisation', 'Privilèges - Visualisation', 3),
(4, 1, 'privilege-edition', 'Privilèges - Édition', 4);
INSERT INTO role_privilege (role_id, privilege_id) VALUES
(4, 1),
(4, 2),
(4, 3),
(4, 4);
INSERT INTO "user" (username, email, display_name, password, state) VALUES
-- utilisateur demo/azerty
('demo', 'demo@mail.fr', 'Demo Crite', '$2y$10$PxXnVLYnGEzEnfqPqRKJSe9AabocES2H4bBK5VzzJlzuj1rVt7Lwu', 1);
INSERT INTO user_role_linker(user_id, role_id)
SELECT u.id, r.id FROM "user" u, user_role r WHERE u.username = 'demo' and r.role_id = 'Standard';
#!/usr/bin/env bash
DIR=$(cd `dirname $0` && pwd)
DBPATH=${DIR}/../data/db/demo.sqlite
sqlite3 ${DBPATH} < ${DIR}/../data/demo.sqlite.sql && \
chmod 777 ${DBPATH} && \
chmod 777 `dirname ${DBPATH}`
...@@ -3,16 +3,26 @@ ...@@ -3,16 +3,26 @@
namespace Demo; namespace Demo;
return [ return [
//
// ATTENTION: config Doctrine à déplacer dans `APP/config/autoload/`.
//
'doctrine' => [ 'doctrine' => [
'connection' => [ 'connection' => [
'orm_default' => [ 'orm_default' => [
'driverClass' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', 'driverClass' => \Doctrine\DBAL\Driver\PDOPgSql\Driver::class,
'params' => [ 'params' => [
'path' => __DIR__ . '/../data/db/demo.sqlite', 'host' => 'db', //
'user' => 'admin', // cf. docker-compose.yml
'password' => 'admin', //
'dbname' => 'demo', //
'port' => '5432',
'charset' => 'utf8',
'driverOptions' => [1002 => 'SET NAMES utf8']
], ],
], ],
], ],
], ],
'bjyauthorize' => [ 'bjyauthorize' => [
'guards' => [ 'guards' => [
'BjyAuthorize\Guard\Controller' => [ 'BjyAuthorize\Guard\Controller' => [
......
CREATE TABLE IF NOT EXISTS user
(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,