Restriction des pages en JSF
Bonjour,
J'ai une page d'authentification qui se redirige vers une page d'accueil si l'objet administrateur existe dans la base.
voila mon code de connexion :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public String seConnecter() throws NoSuchAlgorithmException{
int count = 0;
try{
count = adminBuss.authentificationn(administrateur.getEmailAdmin(), getMD5Hash(administrateur.getMotDePasse()));
System.out.println(count);
if(count == 1){
administrateur = adminBuss.retournerAdminMail(administrateur.getEmailAdmin());
count = 0;
return "tableaudebord.xhtml?faces-redirect=true";
}else{
afficherMessageError("Vérifier vos coordonnées");
return "fail";
}
}catch(DataAccessException e){
e.printStackTrace();
return "fail";
}
} |
L'authentification marche très bien mais maintenant lorsque j'exécute la page authentification et je change url de la page vers tableaudebord.xhtml je me redirige directement sans faire de connexion.
J'ai regardé un peu sur le net et j'ai trouvé qu'il faut appliquer les restrictions filters, j'ai implémenté ce code mais ça marche toujours pas :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package com.resotrekk.filters;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class RestrictionFilter implements Filter {
public static final String ACCES_CONNEXION = "/backOffice/adminzone.xhtml";
public static final String ATT_SESSION_USER = "sessionUtilisateur";
public void init( FilterConfig config ) throws ServletException {
}
public void doFilter( ServletRequest req, ServletResponse res, FilterChain chain ) throws IOException,
ServletException {
/* Cast des objets request et response */
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
/* Récupération de la session depuis la requête */
HttpSession session = request.getSession();
/**
* Si l'objet utilisateur n'existe pas dans la session en cours, alors
* l'utilisateur n'est pas connecté.
*/
if ( session.getAttribute( ATT_SESSION_USER ) == null ) {
/* Redirection vers la page publique */
request.getRequestDispatcher( ACCES_CONNEXION ).forward( request, response );
} else {
/* Affichage de la page restreinte */
chain.doFilter( request, response );
}
}
public void destroy() {
}
} |
et mon web.xml est le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>frontoffice</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ApplicationContextSecurity.xml, /WEB-INF/ApplicationContext.xml</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bootstrap</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- le chargeur de contexte de Spring dans le web.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>1048576</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter>
<filter-name>RestrictionFilter</filter-name>
<filter-class>com.resotrekk.filters.RestrictionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestrictionFilter</filter-name>
<url-pattern>/backOffice/tableaudebord.jsf</url-pattern>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/404.xhtml</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/404.xhtml</location>
</error-page>
<welcome-file-list>
<welcome-file>accueil.xhtml</welcome-file>
</welcome-file-list>
</web-app> |
Est-ce-qu'il y a une solution s'il vous plait?
Merci.