Browse Source

Token

master
DANIEL IVAN ESTRADA MORANDO 6 months ago
parent
commit
82004ed9d8
  1. 114
      InventarioJakartaJIN-ejb/src/java/mx/edu/tsj/chapala/sistemas/jin/modelo/Tokens.java
  2. 28
      InventarioJakartaJIN-war/src/java/mx/edu/tsj/chapala/sistemas/jin/servicios/ProductosServlet.java

114
InventarioJakartaJIN-ejb/src/java/mx/edu/tsj/chapala/sistemas/jin/modelo/Tokens.java

@ -0,0 +1,114 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package mx.edu.tsj.chapala.sistemas.jin.modelo;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author estra
*/
@Entity
@Table(name = "tokens")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Tokens.findAll", query = "SELECT t FROM Tokens t"),
@NamedQuery(name = "Tokens.findById", query = "SELECT t FROM Tokens t WHERE t.id = :id"),
@NamedQuery(name = "Tokens.findByToken", query = "SELECT t FROM Tokens t WHERE t.token = :token"),
@NamedQuery(name = "Tokens.findByServicio", query = "SELECT t FROM Tokens t WHERE t.servicio = :servicio")})
public class Tokens implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 100)
@Column(name = "token")
private String token;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 100)
@Column(name = "servicio")
private String servicio;
public Tokens() {
}
public Tokens(Integer id) {
this.id = id;
}
public Tokens(Integer id, String token, String servicio) {
this.id = id;
this.token = token;
this.servicio = servicio;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getServicio() {
return servicio;
}
public void setServicio(String servicio) {
this.servicio = servicio;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Tokens)) {
return false;
}
Tokens other = (Tokens) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "mx.edu.tsj.chapala.sistemas.jin.modelo.Tokens[ id=" + id + " ]";
}
}

28
InventarioJakartaJIN-war/src/java/mx/edu/tsj/chapala/sistemas/jin/servicios/ProductosServlet.java

@ -28,7 +28,6 @@ import mx.edu.tsj.chapala.sistemas.jin.modelo.Ubicacion;
* @author estra
*/
@WebServlet(name = "ProductosServlet", urlPatterns = {"/ProductosServlet"})
public class ProductosServlet extends HttpServlet {
@ -47,7 +46,6 @@ public class ProductosServlet extends HttpServlet {
@EJB
private ProductoBLLocal productoBL;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
@ -62,25 +60,32 @@ public class ProductosServlet extends HttpServlet {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
String opcion = request.getParameter("Opc");
// Verificar el token
String token = request.getParameter("token");
if (!"4jLz8mQ1sT2nEw7Vb9XRp6Aa".equals(token)) {
out.print("Acceso Denegado");
return;
}
String opcion = request.getParameter("Opc");
switch(opcion){
switch (opcion) {
case "1":
Producto p = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id")));
if(p.getStatus() == 0){
if (p.getStatus() == 0) {
out.print("No existe ese producto");
}else{
out.print("<h1>"+p.getNombre()+"</h1>");
} else {
out.print("<h1>" + p.getNombre() + "</h1>");
}
break;
case "2":
Producto pE = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id")));
if(pE.getStatus() == 0){
if (pE.getStatus() == 0) {
out.print("No existe ese elemento");
}else{
} else {
productoBL.eliminar(pE);
out.print("Eliminado con éxito");
}
@ -117,8 +122,6 @@ public class ProductosServlet extends HttpServlet {
break;
}
}
}
@ -134,7 +137,6 @@ public class ProductosServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

Loading…
Cancel
Save