Interdir l'accès direct aux pages JSF
Bonsoir à tous
ce sujet a été repris beaucoup mais je n'arrive pas à trouver une solution
voici mon fichier web.xml
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
|
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>classic</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20m</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app> |
j'ai ma page index pour authentification
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
|
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@page import="java.util.Locale"%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Gestion </title>
<meta http-equiv="refresh" content="100">
<script language="JavaScript" src="calendar_us.js"></script>
<link rel="stylesheet" href="calendar.css">
<script type="" language = "Javascript">
</script>
</head>
<body link="#0000FF" ALINK="#ff8000" >
<h:form id="auth">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; position:absolute; left:440; top:68" bordercolor="#FFCC66" width="428" height="230" align="left" bgcolor="#FFCC66">
<tr>
<td width="101%" colspan="2" height="48" bordercolor="#FF9900" bgcolor="#FF9900">
<p align="center"><font face="Calibri" size="5" color="#FFFFFF"><b></b></font></td>
</tr>
<tr>
<td align="right"width="101%" height="23" colspan="2" bordercolor="#008000" bgcolor="#FF9900" style="border-style: solid; border-width: 1">
<p align="center"><font color="#FFFFFF"><b><font face="Calibri" size="3">
</font><span style="line-height: 115%; font-family: Calibri">
<font size="4" >Authentification</font></span></b></font></td>
</tr>
<tr>
<td width="43%" height="32"><font face="Calibri"> </font>
<p><font face="Calibri"> Nom d'utilisateur:<span lang="ar-dz"> </span>
</font></td>
<td width="57%" height="32">
<p>
<h:inputText size="40" value="#{index.nom}" style="height : 25px; width : 221px;" maxlength="100" id="nom"/></td>
</tr>
<tr>
<td width="43%" height="33"><font face="Calibri"> Mot de passe:</font></td>
<td width="57%" height="33">
<h:inputText size="40" value="#{index.pass}" style="width : 219px; height : 23px;" maxlength="100" id="pass"/> </td>
</tr>
<tr style=" height : 30px;" valign="top">
<td width="194"><b><font face="Calibri" size="4"></font></b></td>
<td style=" width : 411;">
<font face="Calibri">
<a4j:outputPanel ajaxRendered="true">
<h:messages id="msg1"/>
</a4j:outputPanel>
</font>
</td>
</tr>
<tr>
<td width="44%" height="51" bgcolor="#FFCC66" style="border-style: solid; border-width: 1" bordercolor="#FFCC66"> </td>
<td width="57%" height="51" bgcolor="#FFCC66" style="border-style: solid; border-width: 1" bordercolor="#FFCC66">
<h:commandButton action ="#{index.connexion}" value="Connexion" id="save1" style=" width : 111px;">
<a4j:support reRender="pass,msg1"/>
</h:commandButton>
</td>
</tr>
<tr>
<td width="101%" height="23" colspan="2" bordercolor="#008000" bgcolor="#FF9900" style="border-style: solid; border-width: 1">
<p align="center"><font color="#FFFFFF"><i><b><font face="Calibri" size="2">
</font><span style="line-height: 115%; font-family: Calibri">
<font size="2"></font></span></b></i></font></td>
</tr>
</table>
</h:form>
</body>
</html>
</f:view> |
et voici mon bean
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
package Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.util.Date;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.DataModel;
import javax.faces.model.SelectItem;
import javax.management.Query;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
import org.apache.catalina.Session;
import org.richfaces.model.selection.SimpleSelection;
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.Import;
public class index {
private String SqlStr="", nom="", pass="";
private Statement stmt;
private ResultSet RS;
private Connection con = new BDD().getCon();
private TablesDemDech tabled1,tabled11;
private Model model1;
private View view1 ;
private ArrayList<TablesDemDech> table1=new ArrayList<TablesDemDech>();
private ArrayList<TableDemandeur> table2=new ArrayList<TableDemandeur>();
private Tables tab1;
private HashMap param = new HashMap();
private JRBeanCollectionDataSource datasource;
private JasperPrint jasperPrint;
private boolean save1=true;
private Affect id;
private ArrayList<Affect> ac=new ArrayList<Affect>();
public index()
{
nom="";pass="";
}
public Model getModel1(){return this.model1;}
public void setModel1(Model model1) {this.model1 = model1;}
public View getView1(){return this.view1;}
public void setView1(View view1){this.view1 = view1;}
public TablesDemDech getTabled1(){return this.tabled1;}
public void setTabled1(TablesDemDech tabled1){this.tabled1 = tabled1;}
public boolean getSave1(){return this.save1;}
public void setSave1(boolean save1){this.save1 = save1;}
public String getNom() {return this.nom;}
public void setNom(String nom) {this.nom=nom;};
public String getPass() {return this.pass;}
public void setPass(String pass) {this.pass=pass;};
public void setPersons(ArrayList<Affect> ac){this.ac = ac;}
public ArrayList<Affect> getAc() {return this.ac;}
public String connexion()
{
String url="";
if ((nom.equals(""))|| (nom.equals(null)) ||(pass.equals(""))|| (pass.equals(null)))
{
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage("Erreur", new FacesMessage("Nom d'utilisateur ou mot de passe vide !!"));
url="no";
}
else
{
ADAuthenticator ada = new ADAuthenticator("domain.domain", "ldap://000.000.0.100:389", "dc=domain,dc=domain");
Map umap = ada.authenticate(nom,pass);
if (umap == null)
{
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage("Erreur", new FacesMessage("Nom d'utilisateur ou mot de passe incorrect !!"));
url="no";
}
else
{
url="yes";
}
}
return url;
}
} |
j'ai d'autres pages jsf
comment je peux interdire l'accès direct aux autres pages sauf pour (index)
en utilisant la balise
Code:
<security-constraint>
dans mon web.xml
Merci