Server migration authored by Ferret Renaud's avatar Ferret Renaud
<table>
<thead>
<tr>
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo19-Security-P4/1%5D-Code-Java)</h6></th>
<th colspan="3" width="600px"><h1 align="center">19 - Spring - Security - P5</h1></th>
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo19-Security-P6/1%5D1]-Installation)</h6></th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td align="center">[:one:](/Exo19-Security-P5/1%5D-Code-Java)<br/>Code Java</td>
<td align="center">:white_check_mark:<br/>XML</td>
<td align="center">[:three:](/Exo19-Security-P5/3%5D-Configuration-et-spring-boot)<br/>Configuration et Spring Boot</td>
<td>&nbsp;</td>
</tr>
</tbody>
<tfoot>
<tr align="right">
<td colspan="5">
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
</td>
</tr>
</tfoot>
</table>
***
# Via fichier XML
Ajustez votre fichier `src\main\resources\spring\security-context.xml`
Ajoutez l'information qui permet de faire usage des informations dans son code métier :
```xml
...
<!-- Afin de faire usage des annotations dans son code Java -->
<global-method-security secured-annotations="enabled" pre-post-annotations="enabled" />
```
Dans le code Java de votre service métier, faites usage des annotations pour indiquer que la méthode
* *faireAdmin* n'est utilisable que par ceux qui ont un rôle admin
* *faireUser* n'est utilisable que par ceux qui ont un rôle user
Remarque : les annotations de code pour la sécurité sont à destination des services métiers (@Service), en placer dans des DAO (@Repository) ou contrôleurs (@Controller) est maladroit.
# Ajustement HTML / JSP
Utilisez la tab-lib du Spring Security pour montrer ou cacher les options qui sont dans la page *menu.jsp*
```html
...
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec"%>
```
On cible les liens vers :
* la pageA.jsp, accessible uniquement pour ceux qui ont un rôle admin
* la pageB.jsp, accessible uniquement pour ceux qui ont un rôle user
* l'action logout, accessible uniquement pour ceux qui sont authentifiés
# Lancement de l'application
Lancez votre application pour vérifier le bon fonctionnement de Spring Security.
***
<table>
<thead>
<tr>
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo19-Security-P4/1%5D-Code-Java)</h6></th>
<th colspan="3" width="600px"><h1 align="center">19 - Spring - Security - P5</h1></th>
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo19-Security-P6/1%5D1]-Installation)</h6></th>
</tr>
</thead>
<tbody>
<tr>
<td>&nbsp;</td>
<td align="center">[:one:](/Exo19-Security-P5/1%5D-Code-Java)<br/>Code Java</td>
<td align="center">:white_check_mark:<br/>XML</td>
<td align="center">[:three:](/Exo19-Security-P5/3%5D-Configuration-et-spring-boot)<br/>Configuration et Spring Boot</td>
<td>&nbsp;</td>
</tr>
</tbody>
<tfoot>
<tr align="right">
<td colspan="5">
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
</td>
</tr>
</tfoot>
</table>