use of fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket in project muikku by otavanopisto.
the class WebSocketTicketDAO method create.
public WebSocketTicket create(String ticket, Long user, String ip, Date timestamp) {
WebSocketTicket webSocketTicket = new WebSocketTicket();
webSocketTicket.setTicket(ticket);
webSocketTicket.setUser(user);
webSocketTicket.setIp(ip);
webSocketTicket.setTimestamp(timestamp);
getEntityManager().persist(webSocketTicket);
return webSocketTicket;
}
use of fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket in project muikku by otavanopisto.
the class WebSocketTicketDAO method findByTicket.
public WebSocketTicket findByTicket(String ticket) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WebSocketTicket> criteria = criteriaBuilder.createQuery(WebSocketTicket.class);
Root<WebSocketTicket> root = criteria.from(WebSocketTicket.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(WebSocketTicket_.ticket), ticket));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket in project muikku by otavanopisto.
the class WebSocketRESTService method check.
@GET
@Path("/ticket/{TICKET}/check")
@RESTPermitUnimplemented
public Response check(@PathParam("TICKET") String ticketStr) {
WebSocketTicket ticket = webSocketTicketController.findTicket(ticketStr);
if (ticket != null) {
UserEntity user = sessionController.getLoggedUserEntity();
Long userId = user != null ? user.getId() : null;
boolean valid = userId != null ? userId.equals(ticket.getUser()) : ticket.getUser() == null;
if (valid)
return Response.noContent().build();
else
return Response.status(Response.Status.NOT_FOUND).build();
} else
return Response.status(Response.Status.NOT_FOUND).build();
}
Aggregations