/** * Validates the provided password against the configured one * @param providedPassword Password to validate * @param userRequestedEmail User requested the password check * @throws IOException * @throws EncryptionMasterPasswordException */ @Lock(LockType.READ) @AccessTimeout(value = 3, unit = TimeUnit.SECONDS) public void checkPassword(String providedPassword, String userRequestedEmail) throws IOException, EncryptionMasterPasswordException { String sha = DigestUtils.sha256Hex(providedPassword); if (!getMasterEncryptionPassword().equals(sha)) { Users user = userFacade.findByEmail(userRequestedEmail); String logMsg = "*** Attempt to change master encryption password with wrong credentials"; if (user != null) { LOG.log(Level.INFO, logMsg + " by user <" + user.getUsername() + ">"); } else { LOG.log(Level.INFO, logMsg); } throw new EncryptionMasterPasswordException("Provided password is incorrect"); } }
@Lock(LockType.WRITE) @AccessTimeout(value=100) public void forceRemoveCertificates(String username, String projectName, boolean bothUserAndProject) { // Remove project specific certificates, if any MaterialKey key = new MaterialKey(username, projectName); FileRemover scheduledRemover = scheduledFileRemovers.remove(key); if (null != scheduledRemover) { scheduledRemover.scheduledFuture.cancel(true); } deleteMaterialFromLocalFs(key.getExtendedUsername()); materialMap.remove(key); if (bothUserAndProject) { // Remove project generic certificates, if any key = new MaterialKey(null, projectName); scheduledRemover = scheduledFileRemovers.remove(key); if (null != scheduledRemover) { scheduledRemover.scheduledFuture.cancel(true); } deleteMaterialFromLocalFs(key.getExtendedUsername()); materialMap.remove(key); } }
@Override @AccessTimeout(value=TelnetConnection.DEFAULT_READ_TIMEOUT,unit=TimeUnit.MILLISECONDS) public RedRatDevice getIrDevice( String ip ) { synchronized(new Object()){ RedRatDevice retVal = null; logger.info( "RedRatManager getIrDevice irDevices " + irDevices ); if (ip != null && irDevices != null ) { for ( RedRatDevice irDevice : irDevices ) { if ( irDevice instanceof IrNetBoxPro ) { if ( ( ( IrNetBoxPro ) irDevice ).getIpAddress().equals( ip ) ) { retVal = irDevice; } } } } return retVal; } }
@Lock(LockType.WRITE) @AccessTimeout(value=100) public void removeCertificate(String username, String projectName) { MaterialKey key = new MaterialKey(username, projectName); InternalCryptoMaterial material = materialMap.get(key); if (null != material) { LOG.log(Level.FINEST, "Requested removal of material for " + key .getExtendedUsername() + " Ref: " + material.references); } if (null != material && material.decrementReference()) { materialMap.remove(key); scheduleFileRemover(key, new FileRemover(key, material)); } }
@AccessTimeout(value = 5, unit = SECONDS) public String awaitText() { for (;;) { try { if (text != null) { return text; } MILLISECONDS.sleep(TEST_DELAY); } catch (InterruptedException e) { return null; } } }
@Asynchronous @Lock(READ) @AccessTimeout(-1) public Future<String> addJob(String jobName) { // Pretend this job takes a while doSomeHeavyLifting(); // Return our result return new AsyncResult<String>(jobName); }
@AccessTimeout(value = 1, unit = TimeUnit.MINUTES) public void observe(@Observes TestEvent event) { if ("five".equals(event.getMessage())) { logger.info("¡Evento recibido!"); } }
@AccessTimeout(value = 1, unit = TimeUnit.MINUTES) public void observe(@Observes TestEvent event) { initContext(); if ("five".equals(event.getMessage())) { logger.info("¡Evento recibido!"); } closeContext(); }
@AccessTimeout(0) public void doItNow() { // do something }
@AccessTimeout(value = 5, unit = SECONDS) public void doItSoon() { // do something }
@AccessTimeout(value = 2 , unit = TimeUnit.MILLISECONDS) @Override public void incrementCounter() { x = x + 1; }
@Lock(LockType.READ) @AccessTimeout(value = 3, unit = TimeUnit.SECONDS) public String getMasterEncryptionPassword() throws IOException { return FileUtils.readFileToString(masterPasswordFile).trim(); }
@Lock(LockType.WRITE) @AccessTimeout(value=500) public void materializeCertificates(String username, String projectName) throws IOException { MaterialKey key = new MaterialKey(username, projectName); InternalCryptoMaterial material = materialMap.get(key); FileRemover scheduledRemover = null; LOG.log(Level.FINEST, "Requested materialization for: " + key .getExtendedUsername()); if (material != null) { // Crypto material already exists material.incrementReference(); LOG.log(Level.FINEST, "User: " + key.getExtendedUsername() + " " + "Material exist, ref " + material.references); } else { // Crypto material does not exist in cache LOG.log(Level.FINEST, "Material for " + key.getExtendedUsername() + " does not exist in cache"); // But there might be scheduled a delayed removal from the local fs if ((scheduledRemover = scheduledFileRemovers.get(key)) != null) { LOG.log(Level.FINEST, "Exists scheduled removal for " + key .getExtendedUsername()); // Cancel the delayed removal boolean canceled = scheduledRemover.scheduledFuture.cancel(false); scheduledFileRemovers.remove(key); // If managed to cancel properly, just put back the reference if (canceled) { LOG.log(Level.FINEST, "Successfully canceled delayed removal for " + key.getExtendedUsername()); scheduledRemover.material.references++; materialMap.put(key, scheduledRemover.material); } else { // Otherwise materialize // Force deletion of material to avoid corrupted data LOG.log(Level.FINEST, "Could not cancel delayed removal, " + "materializing again for " + key.getExtendedUsername()); forceRemoveCertificates(key.username, key.projectName, false); materialize(key); } } else { // Otherwise the material has been wiped-out, so materialize it anyway LOG.log(Level.FINEST, "Material for " + key.getExtendedUsername() + " has been wiped out, materializing!"); materialize(key); } } }
@Lock(LockType.READ) @AccessTimeout(value=200) public boolean existsInStore(String username, String projectName) { MaterialKey key = new MaterialKey(username, projectName); return materialMap.containsKey(key); }
@AccessTimeout(20000) public void doBar() { System.out.println("doBar"); }
@AccessTimeout(value = 5, unit = TimeUnit.SECONDS) public void doItSoon() { // do something }
@AccessTimeout(-1) public void justDoIt() { // do something }
@AccessTimeout(value = 1, unit = TimeUnit.MINUTES) public void observe(@Observes TestEvent event) { if ("five".equals(event.getMessage())) { events.countDown(); } }
public void addClassLevelDeclaration(final AccessTimeout attribute, final Class type) { final ContainerConcurrency concurrency = getContainerConcurrency(type); concurrency.setAccessTimeout(toTimeout(attribute)); }
public void addMethodLevelDeclaration(final AccessTimeout attribute, final Method method) { final ContainerConcurrency concurrency = getContainerConcurrency(method); concurrency.setAccessTimeout(toTimeout(attribute)); }
private Timeout toTimeout(final AccessTimeout annotation) { final Timeout timeout = new Timeout(); timeout.setTimeout(annotation.value()); timeout.setUnit(annotation.unit()); return timeout; }
public Class<AccessTimeout> getAnnotationClass() { return AccessTimeout.class; }
@AccessTimeout(value = -1) public void method() { }
@AccessTimeout(value = 2, unit = TimeUnit.SECONDS) public void color() { }
@AccessTimeout(value = 3, unit = TimeUnit.SECONDS) public void color(final Object o) { }
@AccessTimeout(value = 1, unit = TimeUnit.MINUTES) public void red() { }
@AccessTimeout(value = 2, unit = TimeUnit.HOURS) public void crimson() { }
@AccessTimeout(value = 2, unit = TimeUnit.DAYS) public void scarlet() { }
@AccessTimeout(value = 2, unit = TimeUnit.HOURS) public void color(final Boolean s) { }
/** * Returns the featured item * @return featured item */ @Lock(LockType.READ) @AccessTimeout(value=2,unit=TimeUnit.MINUTES) public Item getFeaturedItem();