Hi all.
i need to block the path /admin/ for all the pepole. only the people
logged in as root can access it.
i've done a filter, but struts seems to dosen't works with its
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>adminFilter</filter-name>
<filter-class>filter.AdminFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>adminFilter</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
public class AdminFilter implements Filter {
FilterConfig fc;
public AdminFilter() {
}
public void init(FilterConfig fc) throws ServletException {
this.fc = fc;
}
public void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain) throws IOException, ServletException {
System.out.println("i'm the filter!");
HttpServletResponse myResponse = (HttpServletResponse) response;
HttpServletRequest myRequest = (HttpServletRequest) request;
String user = (String) myRequest.getSession().getAttribute("logged");
ServletContext sc = fc.getServletContext();
if (user.equals("admin")) {
String requestURI = myRequest.getRequestURI();
int pathLength = myRequest.getContextPath().length();
StringBuffer relativeURI = new
StringBuffer(requestURI.substring(pathLength));
String query = myRequest.getQueryString();
if (query != null) {
relativeURI.append("?").append(query);
}
RequestDispatcher rd = null;
if (relativeURI.toString().length() > 0) {
rd = sc.getRequestDispatcher(relativeURI.toString());
} else {
rd = sc.getRequestDispatcher("/WAP-Shop-war/");
}
rd.forward(myRequest, myResponse);
} else {
RequestDispatcher rd = null;
rd = sc.getRequestDispatcher("/WAP-Shop-war/");
rd.forward(myRequest, myResponse);
}
return;
}
public void destroy() {
}
}
when i put the url like:
http://localhost:8080/WAP-Shop-war/admin/showAddItem.action i see the
page and i don't see the string: i'm the filter!
where's the fault?
--
Stefano
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]