public ApiToken refreshToken(ApiToken apiToken) { Calendar expiration = Calendar.getInstance(); expiration.add(Calendar.HOUR, TOKEN_LIFETIME_HOURS); apiToken.setExpiration(expiration.getTime()); apiToken = entityManager.merge(apiToken); WebSocketServerLogger.LOG.refreshValidTokenDebug( apiToken.getToken(), apiToken.getExpiration().toString()); return apiToken; }
public ApiToken createToken(Customer customer) { Calendar expiration = Calendar.getInstance(); expiration.add(Calendar.HOUR, TOKEN_LIFETIME_HOURS); ApiToken apiToken = new ApiToken(); apiToken.setCustomer(customer); apiToken.setToken(UUID.randomUUID().toString()); apiToken.setExpiration(expiration.getTime()); entityManager.persist(apiToken); WebSocketServerLogger.LOG.newTokenCreatedDebug( apiToken.getToken(), apiToken.getExpiration().toString()); return apiToken; }