List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.eurodyn.qlack2.fuse.idm.impl.IDMServiceImpl.java
License:EUPL
private AuthenticateResponse authenticate(String username, String password, boolean isSSO) { LOGGER.log(Level.FINE, "Requesting authentication for {0} [SSO={1}].", new Object[] { username, isSSO }); AuthenticateResponse retVal = new AuthenticateResponse(); if (StringUtils.isEmpty(username)) { return retVal; }/*from ww w .j a va2 s.c om*/ String userID; // Skip credentials verification if this is an SSO login. if (!isSSO) { // Do not try to authenticate users with empty credentials. if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { LOGGER.log(Level.FINE, "User could not be authenticated via" + " username and password [username or password was" + "empty].", username); return retVal; } // Check if the user can be authenticated. userID = userService.canAuthenticate(username, password); if (userID == null) { LOGGER.log(Level.FINE, "User {0} could not be authenticated via" + " username and password [credentials did not match].", username); return retVal; } // Check if the status of the user implies an active user. int userStatus = userService.getUserById(userID).getStatus(); if (!validUserStatus.contains(userStatus)) { retVal.setActive(false); retVal.setStatus(userStatus); return retVal; } } else { // The AuthenticateResponse will actually be just a wrapper around the // SignedTicket. The SignedTicket contains a reference to the user ID // (i.e. a UUID) that was successfully authenticated. Since on an SSO // authentication we do not call AAA's canAuthenticate (therefore we do // not get such a user ID) we setup one manually here (which is the // username that SSO authentication took place with). userID = username; } // Generate a ticket for the just authenticated user. SignedTicket signedTicket = null; try { TicketDTO ticketDTO = new TicketDTO(); ticketDTO.setCreatedBy("QLACK IDM"); ticketDTO.setPayload(username); if (ticketValidUntil != null && ticketValidUntil > 0) { ticketDTO.setValidUntil(DateTime.now().getMillis() + ticketValidUntil); } if (ticketAutoExtendValidUntil != null && ticketAutoExtendValidUntil > 0) { ticketDTO.setAutoExtendValidUntil(DateTime.now().getMillis() + ticketAutoExtendValidUntil); } if (ticketAutoExtendDuration != null && ticketAutoExtendDuration > 0) { ticketDTO.setAutoExtendDuration(ticketAutoExtendDuration); } String ticketID = ticketService.createTicket(ticketDTO); if (ticketID != null) { signedTicket = new SignedTicket(); signedTicket.setTicketID(ticketID); signedTicket.setUserID(userID); signedTicket.setUsername(username); signedTicket.setValidUntil(ticketDTO.getValidUntil()); signedTicket.setAutoExtendDuration(ticketDTO.getAutoExtendDuration()); signedTicket.setAutoExtendValidUntil(ticketDTO.getAutoExtendValidUntil()); signedTicket.setSignature(generateSignature(signedTicket)); } } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOGGER.log(Level.SEVERE, MessageFormat.format("Could not create a ticket for user {0}.", username), e); } return new AuthenticateResponse(signedTicket); }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public String createTicket(TicketDTO ticketDTO) { DateTime now = DateTime.now(); Ticket ticket = new Ticket(); ticket.setId(UUID.randomUUID().toString()); ticket.setCreatedAt(now.getMillis()); if (StringUtils.isNotBlank(ticketDTO.getCreatedBy())) { ticket.setCreatedBy(ticketDTO.getCreatedBy()); }/* w w w .j a va 2s. c o m*/ if (StringUtils.isNotBlank(ticketDTO.getPayload())) { ticket.setPayload(ticketDTO.getPayload()); } ticket.setRevoked(false); if (ticketDTO.getValidUntil() != null) { ticket.setValidUntil(ticketDTO.getValidUntil()); } if (ticketDTO.getAutoExtendValidUntil() != null) { ticket.setAutoExtendUntil(ticketDTO.getAutoExtendValidUntil()); } if (ticketDTO.getAutoExtendDuration() != null) { ticket.setAutoExtendDuration(ticketDTO.getAutoExtendDuration()); } em.persist(ticket); return ticket.getId().toString(); }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public boolean isValid(String ticketID) { boolean retVal = false; Ticket ticket = em.find(Ticket.class, ticketID); if (!ticket.isRevoked() && ((ticket.getValidUntil() == null) || (DateTime.now().getMillis() < ticket.getValidUntil()))) { retVal = true;/*from w w w . jav a 2s .co m*/ } // Check if the ticket should be auto-extended. // Only a valid ticket, with a expiring original duration, having a // auto-extend duration > 0 can be auto-extended. if (retVal && ticket.getValidUntil() != null && ticket.getAutoExtendDuration() != null && ticket.getAutoExtendDuration().longValue() > 0) { long now = DateTime.now().getMillis(); long newValidUntil; if (ticket.getAutoExtendUntil() == null || (now + ticket.getAutoExtendDuration().longValue() < ticket.getAutoExtendUntil())) { newValidUntil = now + ticket.getAutoExtendDuration().longValue(); } else { newValidUntil = ticket.getAutoExtendUntil(); } ticket.setValidUntil(newValidUntil); } return retVal; }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public void revoke(String ticketID) { Ticket ticket = em.find(Ticket.class, ticketID); if (ticket.isRevoked()) { throw new QTicketRevokedException( MessageFormat.format("Cannot revoke ticket with ID {0}; the ticket is already " + "revoked", new Object[] { ticketID })); }//w ww . ja va 2 s . com ticket.setRevoked(true); ticket.setLastModifiedAt(DateTime.now().getMillis()); }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public void extendValidity(String ticketID, Long validUntil) { Ticket ticket = em.find(Ticket.class, ticketID); if (ticket.isRevoked()) { throw new QTicketRevokedException(MessageFormat.format( "Cannot extend the validity of ticket with ID " + "{0}; the ticket is revoked.", new Object[] { ticketID })); }/* w ww . j a va 2 s. c o m*/ ticket.setValidUntil(validUntil); ticket.setLastModifiedAt(DateTime.now().getMillis()); }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public void extendAutoExtendValidity(String ticketID, Long validUntil) { Ticket ticket = em.find(Ticket.class, ticketID); if (ticket.isRevoked()) { throw new QTicketRevokedException(MessageFormat.format( "Cannot extend the auto extend date of ticket with ID {0} " + "; the ticket is revoked.", new Object[] { ticketID })); }/*from ww w. j a v a 2 s. c o m*/ ticket.setAutoExtendUntil(validUntil); ticket.setLastModifiedAt(DateTime.now().getMillis()); }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public Set<TicketDTO> findTickets(TicketSearchCriteria criteria) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Ticket> cq = cb.createQuery(Ticket.class); Root<Ticket> root = cq.from(Ticket.class); // Apply criteria if (StringUtils.isNotBlank(criteria.getPayload())) { Predicate pr = null;//from w w w .java 2 s. c o m if (criteria.getPayloadMatch() == PayloadMatch.EXACT) { pr = cb.equal(root.<String>get("payload"), criteria.getPayload()); } else if (criteria.getPayloadMatch() == PayloadMatch.CONTAINS) { pr = cb.like(root.<String>get("payload"), criteria.getPayload()); } if (cq.getRestriction() != null) { cq = cq.where(cb.and(cq.getRestriction(), pr)); } else { cq = cq.where(pr); } // cq = cq.where(cb.and(cq.getRestriction(), pr)); } if (criteria.getExpired() != null) { Predicate pr = null; Long targetDate = (criteria.getTargetDate() != null) ? criteria.getTargetDate() : DateTime.now().getMillis(); if (criteria.getExpired()) { pr = cb.lt(root.<Long>get("validUntil"), targetDate); } else { pr = cb.ge(root.<Long>get("validUntil"), targetDate); } if (cq.getRestriction() != null) { cq = cq.where(cb.and(cq.getRestriction(), pr)); } else { cq = cq.where(pr); } } if (criteria.getRevoked() != null) { Predicate pr = cb.equal(root.<Boolean>get("revoked"), criteria.getRevoked()); if (cq.getRestriction() != null) { cq = cq.where(cb.and(cq.getRestriction(), pr)); } else { cq = cq.where(pr); } } TypedQuery<Ticket> query = em.createQuery(cq); List<Ticket> queryResult = query.getResultList(); Set<TicketDTO> retVal = new HashSet<>(queryResult.size()); for (Ticket ticket : queryResult) { retVal.add(ConverterUtil.ticketToTicketDTO(ticket)); } return retVal; }
From source file:com.eurodyn.qlack2.fuse.ticketserver.impl.TicketServerServiceImpl.java
License:EUPL
@Override public void cleanupExpired() { Query query = em.createQuery("DELETE FROM Ticket t WHERE t.validUntil < :currentDate"); query.setParameter("currentDate", DateTime.now().getMillis()); query.executeUpdate();//from w ww.j av a 2 s.c om // Flush and clear the entity manager so as to pick up the deletion of // the tickets above // since the delete query bypasses the first-level cache of the entity // manager em.flush(); em.clear(); }
From source file:com.evolveum.polygon.connector.googleapps.cache.ConnectorObjectWrapper.java
public ConnectorObjectWrapper(ConnectorObject connectorObject) { this.connectorObject = connectorObject; this.timeAdded = DateTime.now(); }
From source file:com.evolveum.polygon.connector.googleapps.cache.ConnectorObjectWrapper.java
public void markAsUpdatedNow() { this.timeUpdated = DateTime.now(); }