Entity

En src/main/java creamos el paquete com.tutosoftware.bombarderos.entity y en este
creamos la clase Usuario
 
      
          
       package com.tutosoftware.bombarderos.entity;

import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class Usuario {
	
	
	private Integer idUsuario;
	private String email;
	private String password;
	
	
	
public Usuario() {}
	
	
	
	public Usuario(Integer idUsuario,String email,String password) {
		
		this.idUsuario=idUsuario;
		this.email=email;
		this.password=password;
	}


}
          
          
     
     

Creamos la clase Jugador
 
    
   
  package com.tutosoftware.bombarderos.entity;



import java.io.InputStream;
import java.util.Date;


import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter @Setter @NoArgsConstructor
public class Jugador {
	
	private Integer idJugador;
	private Integer idTemporada;
	private byte[] fotografia;
	private String nombre;
	private String apellidoPaterno;
	private String apellidoMaterno;
	private Integer numVecesBat;
	private Integer numHit;
	private Date fechaUltimoJuego;
	private Double porcentaje;
	private InputStream imagen;
   
}
  
   
   
    
     

Creamos la clase Temporada
 
    
   
   package com.tutosoftware.bombarderos.entity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter @Setter @NoArgsConstructor
public class Temporada {
	
	
	private Integer idTemporada;
	private String nombreTemporada;
	private Integer temporadaActiva;

}
   
   
   
   
     

Creamos el paquete com.tutosoftware.bombarderos.util cremaos la clase DBConection
 
      
    package com.tutosoftware.bombarderos.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConection {
	
	public Connection connect() {
        Connection connection = null;
        try {
            Class.forName ("com.mysql.cj.jdbc.Driver").newInstance();
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/llanerosdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=America/Mexico_City&verifyServerCertificate=false&allowPublicKeyRetrieval=true&useSSL=false&requireSSL=false","admin","adminlara");
            System.out.println ("Database connection established");
        } catch (SQLException   e) {
            System.out.println(e.getMessage());
        }catch(ClassNotFoundException e) {
        	System.out.println(e.getMessage());
        }catch(InstantiationException e) {
        	System.out.println(e.getMessage());
        }catch(IllegalAccessException e) {
        	System.out.println(e.getMessage());
        }
        
        return connection;
    }

}
    
              
              
              
       
     

En el mismo paquete creamos la clase SessionUtils
 
     
  package com.tutosoftware.bombarderos.util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionUtils {
	
	public static HttpSession getSession() {
		return (HttpSession) FacesContext.getCurrentInstance()
				.getExternalContext().getSession(false);
	}

	public static HttpServletRequest getRequest() {
		return (HttpServletRequest) FacesContext.getCurrentInstance()
				.getExternalContext().getRequest();
	}

	public static String getUserName() {
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
				.getExternalContext().getSession(false);
		return session.getAttribute("username").toString();
	}

	public static String getUserId() {
		HttpSession session = getSession();
		if (session != null)
			return (String) session.getAttribute("userid");
		else
			return null;
	}


}
  
     
       
     

Creamos el paquete com.tutosoftware.bombarderos.filter creamos la clase AuthorizationFilter
 
   
 package com.tutosoftware.bombarderos.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;
import javax.servlet.http.HttpSession;

@WebFilter(filterName = "AuthFilter", urlPatterns = { "*.xhtml" })
public class AuthorizationFilter implements Filter {
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		try {

			HttpServletRequest reqt = (HttpServletRequest) request;
			HttpServletResponse resp = (HttpServletResponse) response;
			HttpSession ses = reqt.getSession(false);

			String reqURI = reqt.getRequestURI();
			if (reqURI.indexOf("/login.xhtml") >= 0
					|| (ses != null && ses.getAttribute("username") != null)
					|| reqURI.indexOf("/public/") >= 0
					|| reqURI.contains("javax.faces.resource"))
				chain.doFilter(request, response);
			else
				resp.sendRedirect(reqt.getContextPath() + "/faces/login.xhtml");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}