|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo18-JMS/1%5D-Installation)</h6></th>
|
|
|
<th colspan="4" width="600px"><h1 align="center">19 - Spring - Security - P1</h1></th>
|
|
|
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo19-Security-P2/1%5D-Code-Java)</h6></th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
<tr>
|
|
|
<td> </td>
|
|
|
<td align="center">:white_check_mark:<br/>Code Java</td>
|
|
|
<td align="center">[:two:](/Exo19-Security-P1/2%5D-XML)<br/>XML</td>
|
|
|
<td align="center">[:three:](/Exo19-Security-P1/3%5D-Configuration)<br/>Configuration</td>
|
|
|
<td align="center">[:four:](/Exo19-Security-P1/4%5D-Spring-Boot)<br/>Spring Boot</td>
|
|
|
<td> </td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
|
|
|
<tfoot>
|
|
|
<tr align="right">
|
|
|
<td colspan="6">
|
|
|
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</tfoot>
|
|
|
</table>
|
|
|
|
|
|
***
|
|
|
|
|
|
# Importation du projet dans Eclipse
|
|
|
Dans le menu Eclipse, sélectionnez `File/Import` puis `Existing Maven Projects`
|
|
|
|
|
|

|
|
|
|
|
|
Pointez vers le dossier existant `formation.spring\exercices\enonces\Exo19-Spring Security`.
|
|
|
|
|
|
Le projet est en Maven et contient toutes les dépendances nécessaires au projet (y compris celles du Spring).
|
|
|
Attendez que toutes les dépendances soient téléchargées d'Internet avant de modifier le projet.
|
|
|
|
|
|

|
|
|
|
|
|
Vérifiez que tout fonctionne (pas de rouge sur le projet). **Le cas échéant**, vérifiez que vous avez un accès Internet puis faites un clic droit sur le projet puis `Maven - Update Project ...` et cochez `Force Update of Snapshots/Releases`.
|
|
|
|
|
|

|
|
|
|
|
|
Nous sommes en projet Web JEE.
|
|
|
|
|
|
# Dépendance Maven
|
|
|
Nous allons faire usage du Spring Security qui est un module à part du Spring.
|
|
|
|
|
|
Les dépendances dans Maven s'expriment selon votre type de configuration Spring.
|
|
|
|
|
|
* En configuration XML et @Configuration (attention à votre version du Spring) :
|
|
|
|
|
|
```xml
|
|
|
...
|
|
|
<dependencies>
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.security</groupId>
|
|
|
<artifactId>spring-security-core</artifactId>
|
|
|
</dependency>
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.security</groupId>
|
|
|
<artifactId>spring-security-web</artifactId>
|
|
|
</dependency>
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.security</groupId>
|
|
|
<artifactId>spring-security-config</artifactId>
|
|
|
</dependency>
|
|
|
<!-- Si l'on veut faire usage de la taglib -->
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.security</groupId>
|
|
|
<artifactId>spring-security-taglibs</artifactId>
|
|
|
</dependency>
|
|
|
...
|
|
|
</dependencies>
|
|
|
```
|
|
|
|
|
|
* En Spring Boot
|
|
|
|
|
|
```xml
|
|
|
...
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.boot</groupId>
|
|
|
<artifactId>spring-boot-starter-security</artifactId>
|
|
|
</dependency>
|
|
|
<!-- Si l'on veut faire usage de la taglib -->
|
|
|
<dependency>
|
|
|
<groupId>org.springframework.security</groupId>
|
|
|
<artifactId>spring-security-taglibs</artifactId>
|
|
|
</dependency>
|
|
|
...
|
|
|
```
|
|
|
|
|
|
# Présentation du projet
|
|
|
Notre projet a comme code Java
|
|
|
* Un service métier `src\main\java\com\banque\service\MonService.java` représenté par son interface
|
|
|
* Un contrôleur de type WS Rest `src\main\java\com\banque\web\MonControleurRest.java`. Il possède deux méthodes en *GET* disponibles sur */rest/admin* et */rest/user*
|
|
|
|
|
|
C'est un site Web en JSP composé de plusieurs pages.
|
|
|
* La page `src\main\webapp\user\pageA.jsp` qui ne devrait être accessible qu'aux utilisateurs ayant le rôle **USER**
|
|
|
* La page `src\main\webapp\adm\pageB.jsp` qui ne devrait être accessible qu'aux utilisateurs ayant le rôle **ADMIN**
|
|
|
* La page `src\main\webapp\login.jsp` qui devrait être accessible à tous les utilisateurs
|
|
|
* La page `src\main\webapp\logoutok.jsp` qui devrait être accessible à tous les utilisateurs
|
|
|
* La page `src\main\webapp\mauvaisrole.jsp` qui ne devrait être accessible qu'aux utilisateurs authentifiés
|
|
|
* La page `src\main\webapp\menu.jsp` qui dans un premier temps sera accessible à tous, puis ne devrait être accessible qu'aux utilisateurs authentifiés
|
|
|
|
|
|
Dans cette première partie :
|
|
|
* on ne s'occupera que des trois pages *menu*, *pageA* et *pageB* ainsi que l'URL racine */*.
|
|
|
* nous ne ferons usage que de l'authentification/habilitation simple fournit par Spring Security (donc pas de bases de données).
|
|
|
|
|
|
***
|
|
|
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo18-JMS/1%5D-Installation)</h6></th>
|
|
|
<th colspan="4" width="600px"><h1 align="center">19 - Spring - Security - P1</h1></th>
|
|
|
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo19-Security-P2/1%5D-Code-Java)</h6></th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
<tr>
|
|
|
<td> </td>
|
|
|
<td align="center">:white_check_mark:<br/>Code Java</td>
|
|
|
<td align="center">[:two:](/Exo19-Security-P1/2%5D-XML)<br/>XML</td>
|
|
|
<td align="center">[:three:](/Exo19-Security-P1/3%5D-Configuration)<br/>Configuration</td>
|
|
|
<td align="center">[:four:](/Exo19-Security-P1/4%5D-Spring-Boot)<br/>Spring Boot</td>
|
|
|
<td> </td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
|
|
|
<tfoot>
|
|
|
<tr align="right">
|
|
|
<td colspan="6">
|
|
|
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</tfoot>
|
|
|
</table> |