package ro.jademy.presentation;

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.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;

import ro.jademy.domain.entities.User;

@WebFilter(value = "/*", description = "Session Checker Filter")
@Component

public class WebFilterController implements Filter {

	private FilterConfig config = null;

	public void init(FilterConfig config) throws ServletException {
		this.config = config;
		config.getServletContext().log("Initializing SessionCheckerFilter");
	}

	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws ServletException, IOException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		System.out.println("Request URI" + request.getRequestURI().toString()); //debug - arata calea
		User currentUser =(User) request.getSession().getAttribute("currentUser");
		if (request.getRequestURI().endsWith("/login") ||
			request.getRequestURI().endsWith("/header.jsp") ||
			request.getRequestURI().endsWith("/footer.jsp") ||
			request.getRequestURI().endsWith("/login.jsp") ||
			request.getRequestURI().endsWith("/favicon.ico") ||
			request.getRequestURI().endsWith("/register") ||
			request.getRequestURI().endsWith("/registerMenu.jsp") ||
			request.getRequestURI().endsWith("/registerUser") ||
			request.getRequestURI().endsWith("/forgotPassword") ||
			request.getRequestURI().endsWith("/forgotPassword.jsp") ||
			request.getRequestURI().endsWith("/generatePassword/*") ||
			request.getRequestURI().endsWith("/resetPassword") ||
			request.getRequestURI().endsWith("/resetPassword.jsp")) {
			System.out.println("Am intrat pe url-urile interzise"); //debug - arata ca intra pe exceptii de uri
		} else if (currentUser == null) {
			response.sendRedirect(request.getContextPath() + "/login");
			}

		chain.doFilter(req, res);
	}

	public void destroy() {
		config.getServletContext().log("Destroying SessionCheckerFilter");
	}
}

@@ -1072,104 +1072,8 @@
 es;%0A
-%09%09System.out.println(%22Request URI%22 + request.getRequestURI().toString()); //debug - arata calea%0A
 %09%09Us
@@ -1088,16 +1088,17 @@
 ntUser =
+ 
 (User) r
@@ -1193,28 +1193,25 @@
 %22/login%22) %7C%7C
-%0A%09%09%09
+ 
 request.getR
@@ -1237,39 +1237,40 @@
 h(%22/header.jsp%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.getReque
@@ -1295,36 +1295,33 @@
 /footer.jsp%22) %7C%7C
-%0A%09%09%09
+ 
 request.getReque
@@ -1346,31 +1346,32 @@
 /login.jsp%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.getR
@@ -1405,28 +1405,25 @@
 con.ico%22) %7C%7C
-%0A%09%09%09
+ 
 request.getR
@@ -1451,31 +1451,32 @@
 %22/register%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.getR
@@ -1512,31 +1512,32 @@
 erMenu.jsp%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.getR
@@ -1573,23 +1573,24 @@
 erUser%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.
@@ -1624,39 +1624,40 @@
 forgotPassword%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.getReque
@@ -1695,23 +1695,24 @@
 rd.jsp%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.
@@ -1758,23 +1758,24 @@
 word/*%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 request.
@@ -1820,15 +1820,16 @@
 rd%22)
- %7C%7C
 %0A%09%09%09
+%09%7C%7C 
 requ
@@ -1886,111 +1886,8 @@
 ) %7B%0A
-%09%09%09System.out.println(%22Am intrat pe url-urile interzise%22); //debug - arata ca intra pe exceptii de uri%0A
 %09%09%7D 
@@ -1981,17 +1981,16 @@
 ogin%22);%0A
-%09
 %09%09%7D%0A%0A%09%09c

modified webfilter. no sysouts