Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Filter;
- 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;
- @WebFilter(urlPatterns = "*.do")
- public class LoginRequiredFilter implements Filter {
- // private static final Logger logger =
- // LogManager.getLogger(LoginRequiredFilter.class);
- // private static final Logger logger =
- // LogManager.getLogger("Filter.LoginRequiredFilter");
- // private static final Logger logger = LogManager.getLogger();
- public void destroy() {
- }
- @Override
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
- throws IOException, ServletException {
- HttpServletRequest request = (HttpServletRequest) servletRequest;
- request.setCharacterEncoding("UTF-8");
- servletResponse.setContentType("text/plain");
- servletResponse.setCharacterEncoding("UTF-8");
- String path = request.getRequestURI();
- if (path.matches("^/admin.*$")) {
- if (path.equals("/adminsignup.do")) {
- chain.doFilter(servletRequest, servletResponse);
- } else {
- if (request.getSession().getAttribute("admin") != null) {
- chain.doFilter(servletRequest, servletResponse);
- } else {
- request.getRequestDispatcher("/adminlogin.do").forward(servletRequest, servletResponse);
- }
- }
- }
- else if (path.equals("/signup.do")) {
- chain.doFilter(servletRequest, servletResponse);
- } else {
- if (request.getSession().getAttribute("name") != null) {
- chain.doFilter(servletRequest, servletResponse);
- } else {
- request.getRequestDispatcher("/login.do").forward(servletRequest, servletResponse);
- }
- }
- }
- @Override
- public void init(FilterConfig arg0) throws ServletException {
- }
- }
- package Filter;
- 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;
- @WebFilter(urlPatterns = "/views/*")
- public class AuthFilter implements Filter {
- @Override
- public void destroy() {
- }
- @Override
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
- throws IOException, ServletException {
- HttpServletRequest request = (HttpServletRequest) servletRequest;
- HttpServletResponse response = (HttpServletResponse) servletResponse;
- request.setCharacterEncoding("UTF-8");
- servletResponse.setContentType("text/plain");
- servletResponse.setCharacterEncoding("UTF-8");
- String path = request.getRequestURI();
- if (path.matches("^\\/views\\/back-end\\/.*")) {
- if (request.getSession().getAttribute("admin") != null) {
- chain.doFilter(servletRequest, servletResponse);
- } else {
- response.sendRedirect("/adminlogin.do");
- }
- } else {
- if (request.getSession().getAttribute("name") != null) {
- chain.doFilter(servletRequest, servletResponse);
- } else {
- response.sendRedirect("/login.do");
- }
- }
- }
- @Override
- public void init(FilterConfig arg0) throws ServletException {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement