diff --git a/docs/authorization.md b/docs/authorization.md new file mode 100644 index 0000000000000000000000000000000000000000..a826bfaa3f1383e18eaff16cbbbfc85c11225015 --- /dev/null +++ b/docs/authorization.md @@ -0,0 +1,55 @@ +# Authorization + +## Introduction + +Some anis-server routes require authorization. +We will explain here how anis-server handles authorizations. + +## JWT + +Anis-server uses a web standard to manage authorizations. +The name of this standard is JWT and you can find more information +about this into the official website: [https://jwt.io](https://jwt.io). + +JWT is an authentication token that allows a user to prove their identity and access rights. +The token is a string encoded in base64. + +The user must send a JWT token for anis-server routes that require authorization to prove identity. + + + +The token consists of three encoded parts separated by a dot : + + - In red you can see the header + - In purple you can see the payload + - In blue you can see the signature + +### JWT Header + +The header is base64 encoded but can be decoded. +The decoded header is a JSON which contains information about the token such as the algorithm +used to digitally sign it. + +### JWT Payload + +The second part can also be decoded to reveal a JSON. +This JSON is the payload, which contains the claims. +Claims are statements about an entity (typically, the user) and additional data. +It can also contain the user's roles. + +### JWT signature + +The last part contains the digital signature made by a trusted third party with a secret key. +It ensures the authenticity of the token. + +## Keycloak + +Keycloak is a software that allows the management of user authentication. +For more information you can visite the official website: [https://www.keycloak.org/](https://www.keycloak.org/). + +Anis-server includes by default a keycloak installation for development. +You can find the keycloak container description in the `docker-compose.yml` file at the root of the anis-server project. + +Anis-server therefore uses this software as a trusted third party to generate the authorisation tokens. +Keycloak will first verify the identity of the user and send him an `access_token` in JWT format. +This `access_token` should be passed to anis-server API requests that require authorization. \ No newline at end of file diff --git a/docs/configuration_api.md b/docs/configuration_api.md deleted file mode 100644 index a862e1197be2cebe38fb84367892d12c23003721..0000000000000000000000000000000000000000 --- a/docs/configuration_api.md +++ /dev/null @@ -1,81 +0,0 @@ -# Configuration API - -## Introduction - -Anis server provides an API to drive the configuration database. -Here we will list the different endpoints. - -## Endpoints - -You can find the list of all endpoints in the `app/routes.php` file. -Each entrypoint refers to a class action and when the endpoint is called -it is the `__invoke` function that is executed. - -## Actions - -You can find the action files in the `src/Action` folder. -You can modify one or more actions to change the behavior of an endpoint. -You can also add an action file to add an entry point. - -## Root - -Used to ensure that the service is up. - -**URL** : `/` - -**Method** : `GET` - -**URL Params** : None - -**Query Params** : None - -**Auth required** : No - -Success Response : - -**Code** : `200 OK` - -**Content example** - -```json -{ - "message": "it works!" -} -``` - -## Database List - -Used to retrieve business database list. - -**URL** : `/database` - -**Method** : `GET` - -**URL Params** : None - -**Query Params** : None - -**Auth required** : Yes - -Success Response : - -**Code** : `200 OK` - -**Content example** - -```json -[ - { - "id": 1, - "label": "Test", - "dbname": "anis_test", - "dbtype": "pdo_pgsql", - "dbhost": "db", - "dbport": 5432, - "dblogin": "anis", - "dbpassword": "anis" - } -] -``` - -## Add a new database \ No newline at end of file diff --git a/docs/configuration_database.md b/docs/configuration_database.md index ea9d4576df3aabd49a72c822fde7e00b0e4f2948..c0d731b0a6337b434e10c73a57fabda6ca1f6210 100644 --- a/docs/configuration_database.md +++ b/docs/configuration_database.md @@ -16,7 +16,7 @@ Anis-server needs a database to store all the configuration : - The available business database(s) that should contain the shared datasets. - The different scientific projects. - The shared datasets and their attributes. - - The Access rights on datasets (users and roles). + - The access rights on datasets (groups_datasets). ## Schema @@ -24,7 +24,7 @@ Anis-server needs a database to store all the configuration : ## Settings -By default anis-server is configured to connect to a postgres database created during the first launch of docker-compose. +By default anis-server is configured to connect to a PostgreSQL database created during the first launch of docker-compose. The docker compose integrates a PostgreSQL database server named `db`. You can find the `docker-compose.yml` file at the root of the anis-server project. @@ -35,7 +35,7 @@ The database settings connection are given in the environment variables of the p Here is the list of options concerning the configuration database : - `DATABASE_DEV_MODE`: Default to `1` in development mode and to `0` in production mode -- `DATABASE_CO_DRIVER`: PDO driver used to connect to the database +- `DATABASE_CO_DRIVER`: Doctrine pdo driver used to connect to the database - `DATABASE_CO_HOST`: Database server host - `DATABASE_CO_PORT`: Database server listening port - `DATABASE_CO_DBNAME`: Name of the anis-server configuration database @@ -59,7 +59,7 @@ But be careful for each change you will have to re-generate the database and the ## Doctrine command-line tool You can use the doctrine command-line tool to perform most of the operations. -To run the tool you must have launched anis-server with the docker-compose file (see installation). +To run the tool you must have launched anis-server with the `docker-compose.yml` file (see installation). You must be at the root of the anis-server directory. And you can then enter into the anis-server container by typing the following command: diff --git a/docs/extra.css b/docs/extra.css index ae79377e8ac3f30c22cc287b3233d623cebaa0fc..ffc4b7a52a93de02d52843c2d67694852c1e1e81 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -7,4 +7,49 @@ img[src*='#right'] { img[src*='#center'] { display: block; margin: auto; +} + +h3 { + text-decoration: underline; +} + +.success_response { + color: #28a745; + font-weight: bold; +} + +.error_response { + color: #dc3545; + font-weight: bold; +} + +table { + border-collapse: collapse; + margin: 25px 0; + font-size: 0.9em; + font-family: sans-serif; + min-width: 400px; + box-shadow: 0 0 20px rgba(0, 0, 0, 0.15); +} + +thead tr { + background-color: #2980B9; + color: #ffffff; + text-align: left; +} + +th, td { + padding: 12px 15px; +} + +tbody tr { + border-bottom: 1px solid #dddddd; +} + +tbody tr:nth-of-type(even) { + background-color: #f3f3f3; +} + +tbody tr:last-of-type { + border-bottom: 2px solid #009879; } \ No newline at end of file diff --git a/docs/img/anis_server_root.png b/docs/img/anis_server_root.png new file mode 100755 index 0000000000000000000000000000000000000000..eb90ba735a2790e8316b51bc8aba0481d2644a4a Binary files /dev/null and b/docs/img/anis_server_root.png differ diff --git a/docs/img/cesamsi_logo.png b/docs/img/cesamsi_logo.png new file mode 100755 index 0000000000000000000000000000000000000000..4b0554dc3f662c8f768574c1dd2109bea5e8add1 Binary files /dev/null and b/docs/img/cesamsi_logo.png differ diff --git a/docs/img/encoded-jwt3.png b/docs/img/encoded-jwt3.png new file mode 100755 index 0000000000000000000000000000000000000000..0f5ed18fa646c90b2d36e278b6387237ef4f9f5c Binary files /dev/null and b/docs/img/encoded-jwt3.png differ diff --git a/docs/img/lam_logo.jpg b/docs/img/lam_logo.jpg new file mode 100755 index 0000000000000000000000000000000000000000..e69f340a05f98b89bb2005586e8acad95b0bc1f3 Binary files /dev/null and b/docs/img/lam_logo.jpg differ diff --git a/docs/index.md b/docs/index.md index 13f5f7917b174fe8a6479193a6ae59822c567298..6fbd76e937f6740920ba9e8ceca722f26930cb38 100644 --- a/docs/index.md +++ b/docs/index.md @@ -33,12 +33,14 @@ To install the local version you need requirements : ANIS has been developed by `Laboratoire d'Astrophysique de Marseille` to meet the needs of the various scientific missions in which it is engaged. + + ## Licence AstroNomical Information System is governed by the CeCILL license (Version 2.1 dated 2013-06-21) under French law and abiding by the rules of distribution of free software. -You can use, modify and/ or redistribute the software under the terms of the CeCILL +You can use, modify and/or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL [https://cecill.info](https://cecill.info/index.en.html). diff --git a/docs/installation.md b/docs/installation.md index 665d6913a4795f49e43a0ab490650c675e79453a..de34fb8a229d74c819620df068d3042d9a68a917 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -82,6 +82,8 @@ $ make create-db * The server is available at the following address: `http://localhost:8080` + + Few examples: * To list all datasets available in the default instance: `http://localhost:8080/dataset` @@ -105,7 +107,7 @@ $ cd anis-client ### Makefile -Anis client contains a `Makefile` that helps the developer to install and start the application. +Anis-client contains a `Makefile` that helps the developer to install and start the application. Just for information, to list all operations availables just type `make` in your terminal. ### Dependancies @@ -148,7 +150,7 @@ $ cd anis-admin ### Makefile -Anis admin contains a `Makefile` that helps the developer to install and start the application. +Anis-admin contains a `Makefile` that helps the developer to install and start the application. Just for information, to list all operations availables just type `make` in your terminal. ### Dependancies diff --git a/docs/server_api.md b/docs/server_api.md new file mode 100644 index 0000000000000000000000000000000000000000..78222e7b06e2cd5c7bf30308f9ee8c8a7314bfc4 --- /dev/null +++ b/docs/server_api.md @@ -0,0 +1,528 @@ +# Server API + +## Introduction + +Anis server provides a REST API to perform actions. +In this section we will list the different endpoints. + +You can find the list of all endpoints in the `app/routes.php` file. +Each route refers to a class `Action` and when the endpoint is called +it is the `__invoke` function that is executed. + +## Actions + +You can find the `Action` files in the `src/Action` folder. +You can modify one or more actions to change the behavior of an endpoint. +You can also add an action file to add an entrypoint. + +If you want to add an new action, you need to declare a new route into the +`app/routes.php` file and you need to instantiate your new `Action` into the +`app/dependencies.php` file. + +## Endpoints + +### Root + +Used to ensure that the service is up. + +**URL** : `/` + +**Method** : `GET` + +**URL Params** : None + +**Query Params** : None + +**Auth required** : No + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 OK` + +**Content example** + +```json +{ + "message": "it works!" +} +``` + +### Retrieve database list + +Used to retrieve business database list. + +**URL** : `/database` + +**Method** : `GET` + +**URL Params** : + +**Query Params** : None + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 OK` + +**Content example** + +```json +[ + { + "id": 1, + "label": "Test", + "dbname": "anis_test", + "dbtype": "pdo_pgsql", + "dbhost": "db", + "dbport": 5432, + "dblogin": "anis", + "dbpassword": "anis" + } +] +``` + +### Add a new database + +Used to add a new business database. + +**URL** : `/database` + +**Method** : `POST` + +**URL Params** : None + +**Query Params** : None + +**Body** : + +| Name | Description | Type | Available | +|------------|-------------------------------------------------------------|--------|:---------:| +| label | It is the label of the new entry | string | X | +| dbname | Name of the new database | string | X | +| dbtype | Doctrine driver of the database (pdo_pgsql, pdo_mysql, ...) | string | X | +| dbhost | Database server hostname | string | X | +| dbport | Database server listening port | int | X | +| dblogin | User name for connection to the database | string | X | +| dbpassword | Password for connection to the database | string | X | + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `201 Created` + +**Content example** + +```json +[ + { + "id": 1, + "label": "Test", + "dbname": "anis_test", + "dbtype": "pdo_pgsql", + "dbhost": "db", + "dbport": 5432, + "dblogin": "anis", + "dbpassword": "anis" + } +] +``` + +<p class='error_response' markdown='1'>Error Response : </p> + +**Code** : `400 Bad Request` + +**Content example** + +```json +{ + "message": "400 Bad Request", + "exception": [ + { + "type": "Slim\\Exception\\HttpBadRequestException", + "code": 400, + "message": "Param dbpassword needed to add a new database", + "file": "/project/src/Action/DatabaseListAction.php", + "line": 50 + } + ] +} +``` + +### Retrieve a database by ID + +Used to retrieve one database by ID. + +**URL** : `/database/{id}` + +**Method** : `GET` + +**URL Params** : + +| Name | Description | Type | Available | +|------------|----------------------|--------|:---------:| +| id | ID of the database | int | X | + +**Query Params** : None + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 OK` + +**Content example** + +```json +{ + "id": 1, + "label": "Test", + "dbname": "anis_test", + "dbtype": "pdo_pgsql", + "dbhost": "db", + "dbport": 5432, + "dblogin": "anis", + "dbpassword": "anis" +} +``` + +<p class='error_response' markdown='1'>Error Response : </p> + +**Code** : `404 Not Found` + +**Content example** + +```json +{ + "message": "404 Not Found", + "exception": [ + { + "type": "Slim\\Exception\\HttpNotFoundException", + "code": 404, + "message": "Database with id 2 is not found", + "file": "/project/src/Action/DatabaseAction.php", + "line": 45 + } + ] +} +``` + +### Edit a database + +Used to edit a business database. + +**URL** : `/database/{id}` + +**Method** : `PUT` + +**URL Params** : + +| Name | Description | Type | Available | +|------------|----------------------|--------|:---------:| +| id | ID of the database | int | X | + +**Query Params** : None + +**Body** : + +| Name | Description | Type | Available | +|------------|-------------------------------------------------------------|--------|:---------:| +| label | It is the new label of the entry | string | X | +| dbname | New name of the database | string | X | +| dbtype | Doctrine driver of the database (pdo_pgsql, pdo_mysql, ...) | string | X | +| dbhost | Database server hostname | string | X | +| dbport | Database server listening port | int | X | +| dblogin | User name for connection to the database | string | X | +| dbpassword | Password for connection to the database | string | X | + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 Ok` + +**Content example** + +```json +{ + "id": 1, + "label": "New label", + "dbname": "anis_test", + "dbtype": "pdo_pgsql", + "dbhost": "db", + "dbport": 5432, + "dblogin": "anis", + "dbpassword": "anis" +} +``` + +<p class='error_response' markdown='1'>Error Response : </p> + +**Code** : `404 Not Found` + +**Content example** + +```json +{ + "message": "404 Not Found", + "exception": [ + { + "type": "Slim\\Exception\\HttpNotFoundException", + "code": 404, + "message": "Database with id 2 is not found", + "file": "/project/src/Action/DatabaseAction.php", + "line": 45 + } + ] +} +``` + +**Code** : `400 Bad Request` + +**Content example** + +```json +{ + "message": "400 Bad Request", + "exception": [ + { + "type": "Slim\\Exception\\HttpBadRequestException", + "code": 400, + "message": "Param dbpassword needed to edit the database", + "file": "/project/src/Action/DatabaseAction.php", + "line": 61 + } + ] +} +``` + +### Delete a database by ID + +Used to delete one database by ID. + +**URL** : `/database/{id}` + +**Method** : `DELETE` + +**URL Params** : + +| Name | Description | Type | Available | +|------------|----------------------|--------|:---------:| +| id | ID of the database | int | X | + +**Query Params** : None + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 OK` + +**Content example** + +```json +{ + "message": "Database with id 2 is removed!", +} +``` + +<p class='error_response' markdown='1'>Error Response : </p> + +**Code** : `404 Not Found` + +**Content example** + +```json +{ + "message": "404 Not Found", + "exception": [ + { + "type": "Slim\\Exception\\HttpNotFoundException", + "code": 404, + "message": "Database with id 2 is not found", + "file": "/project/src/Action/DatabaseAction.php", + "line": 45 + } + ] +} +``` + +### Retrieve table list from a database + +**URL** : `/database/{id}/table` + +**Method** : `GET` + +**URL Params** : + +| Name | Description | Type | Available | +|------------|----------------------|--------|:---------:| +| id | ID of the database | int | X | + +**Query Params** : None + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 OK` + +**Content example** + +```json +[ + "obs_cat", + "aspic_vipers_dr2_w1", + "observations_info", + "aspic_gama_g02", + "hk", + "observations", + "rawproducts", + "products", + "sp_cards", + "sp_cards_bak", + "vhf", + "ancillary_files", + "calibpack", + "obspack", + "observation", + "public.v_products", + "public.v_rawproducts", + "public.anis_observation", + "public.v_obspack" +] +``` + +<p class='error_response' markdown='1'>Error Response : </p> + +**Code** : `404 Not Found` + +**Content example** + +```json +{ + "message": "404 Not Found", + "exception": [ + { + "type": "Slim\\Exception\\HttpNotFoundException", + "code": 404, + "message": "Database with id 2 is not found", + "file": "/project/src/Action/TableListAction.php", + "line": 58 + } + ] +} +``` + +### Retrieve project list + +Used to retrieve project list. + +**URL** : `/project` + +**Method** : `GET` + +**URL Params** : + +**Query Params** : None + +**Auth required** : No + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `200 OK` + +**Content example** + +```json +[ + { + "name": "anis_project", + "label": "Anis Project Test", + "description": "Project used for testing", + "link": "http://project.com", + "manager": "M. Durand", + "id_database": 1 + }, + { + "name": "svom", + "label": "Svom Project Test", + "description": "Project used for testing", + "link": "http://svom.com", + "manager": "S. Basa", + "id_database": 1 + }, + { + "name": "colibri", + "label": "Colibri Project Test", + "description": "Project used for testing", + "link": "http://colibri.com", + "manager": "S. Basa", + "id_database": 1 + } +] +``` + +### Add a new project + +Used to add a new project. + +**URL** : `/project` + +**Method** : `POST` + +**URL Params** : None + +**Query Params** : None + +**Body** : + +| Name | Description | Type | Available | +|-------------|----------------------------------------------|--------|:---------:| +| name | Identifier name for the project | string | X | +| label | Label of the new project entry | string | X | +| description | Description of the project | string | X | +| link | Link to the project website | string | X | +| manager | Project manager | string | X | +| id_database | ID of the database associated to the project | string | X | + +**Auth required** : Yes + +<p class='success_response' markdown='1'>Success Response : </p> + +**Code** : `201 Created` + +**Content example** + +```json +{ + "name": "new_project", + "label": "New project label", + "description": "Project used for testing", + "link": "http://project.com", + "manager": "S. Dupont", + "id_database": 1 +} +``` + +<p class='error_response' markdown='1'>Error Response : </p> + +**Code** : `400 Bad Request` + +**Content example** + +```json +{ + "message": "400 Bad Request", + "exception": [ + { + "type": "Slim\\Exception\\HttpBadRequestException", + "code": 400, + "message": "Param id_database needed to add a new project", + "file": "/project/src/Action/ProjectListAction.php", + "line": 50 + } + ] +} +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index f3b9e2bb9e71f7f9226c02a7004bbe6b016af42a..a47f1bcfa7e35223aa80eddee533838da6428499 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -6,5 +6,7 @@ nav: - Overview: index.md - Installation: installation.md - Configuration database: configuration_database.md - - Configuration API: configuration_api.md - - Search API: search.md \ No newline at end of file + - Authorization: authorization.md + - Server API: server_api.md + - Web admin: web_admin.md + - Web client: web_client.md \ No newline at end of file