/** * Generate a key pair given transformation and key length which can then be used * for asymmetric en- or decryption. * * @return the generated key as a byte array */ public static KeyPair generateKeyPair() { try { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(ASYMMETRIC_TRANSFORMATION); keyPairGenerator.initialize(ASYMMETRIC_KEY_LENGTH); return keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException ex) { new FatalImplementationErrorException("Key transformation non existent", EncryptionHelper.class, ex); return null; } }
/** * Generate a key with given transformation and key length which can then be used * for symmetric en- or decryption. * * @return the generated key as a byte array */ public static byte[] generateKey() { try { KeyGenerator keyGenerator = KeyGenerator.getInstance(SYMMETRIC_ALGORITHM); keyGenerator.init(SYMMETRIC_KEY_LENGTH); SecretKey secretKey = keyGenerator.generateKey(); return secretKey.getEncoded(); } catch (NoSuchAlgorithmException ex) { new FatalImplementationErrorException("Key transformation non existent", EncryptionHelper.class, ex); return null; } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(agentUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.AGENT_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(deviceUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.DEVICE_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
/** * Hashes a string that has to be UTF-8 encoeded symmetrically. * * @param string String to be hashed * @return Returns a byte[] representing the hashed string */ public static byte[] hash(final String string) { try { byte[] key = string.getBytes("UTF-8"); MessageDigest sha = MessageDigest.getInstance(HASH_ALGORITHM); key = sha.digest(key); return Arrays.copyOf(key, 16); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { new FatalImplementationErrorException("Hashing[" + string + "] failed!", EncryptionHelper.class, ex); return null; } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(appUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.APP_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
@Override public void uncaughtException(Thread t, Throwable ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException("UncaughtException found!", t, ex), LoggerFactory.getLogger(getClass())); } });
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(sceneConfigRemoteRegistry, unitRegistry, UnitRegistryData.SCENE_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
/** * * @return * @deprecated get your own instance via the registry pool. */ @Deprecated public DeviceRegistryRemote getDeviceRegistryRemote() { try { return CachedDeviceRegistryRemote.getRegistry(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } catch (NotAvailableException ex) { new FatalImplementationErrorException("registry not available", this, ex); } return null; }
private void verifyEnablingState() throws FatalImplementationErrorException { if (!isEnabled()) { if (JPService.testMode()) { throw new FatalImplementationErrorException("Waiting for data of a disabled unit should be avoided!", "Calling instance"); } else { logger.warn("Waiting for data of an disabled unit should be avoided! Probably this method will block forever!"); } } }
@Override public R call() throws Exception { try { internalAllOf(futureCollection, this); if (resultCallable == null) { throw new NotAvailableException("resultCallable"); } return resultCallable.call(); } catch (CouldNotPerformException | InterruptedException ex) { throw ex; } catch (Exception ex) { throw ExceptionPrinter.printHistoryAndReturnThrowable(new FatalImplementationErrorException("Task execution failed!", AbstractExecutorService.class, ex), LoggerFactory.getLogger(AbstractExecutorService.class)); } } });
new FatalImplementationErrorException("Decryption of [" + encryptedObject + "] failed", EncryptionHelper.class, ex); return null;
new FatalImplementationErrorException("Unable to encrypt object[" + object + "]", EncryptionHelper.class, ex); return null;
private boolean checkInitialization() { try { validateInitialization(); } catch (InvalidStateException ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException(this, ex), logger); return false; } return true; }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(userConfigRemoteRegistry, unitRegistry, UnitRegistryData.USER_UNIT_CONFIG_FIELD_NUMBER); bindRegistryRemoteToRemoteRegistry(authorizationGroupConfigRemoteRegistry, unitRegistry, UnitRegistryData.AUTHORIZATION_GROUP_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
@Override protected void bindRegistryRemoteToRemoteRegistries() { try { bindRegistryRemoteToRemoteRegistry(locationUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.LOCATION_UNIT_CONFIG_FIELD_NUMBER); bindRegistryRemoteToRemoteRegistry(connectionUnitConfigRemoteRegistry, unitRegistry, UnitRegistryData.CONNECTION_UNIT_CONFIG_FIELD_NUMBER); } catch (CouldNotPerformException ex) { new FatalImplementationErrorException("Could not bind registries", this, ex); } }
public static void verifyServiceState(final Message serviceState) throws VerificationFailedException { try { try { detectServiceStateVerificationMethod(serviceState).invoke(null, serviceState); } catch (NotAvailableException ex) { ExceptionPrinter.printHistory("Verification of ServiceState[ " + serviceState.getClass().getSimpleName() + "] skipped because verification method not supported yet.!", ex, LOGGER, LogLevel.DEBUG); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof VerificationFailedException) { throw (VerificationFailedException) ex.getTargetException(); } else { throw ex; } } } catch (VerificationFailedException ex) { throw ex; } catch (NullPointerException | IllegalAccessException | ExceptionInInitializerError | CouldNotPerformException | InvocationTargetException ex) { ExceptionPrinter.printHistory(new FatalImplementationErrorException("Verification of service state could no be performed!", Services.class, ex), LOGGER, LogLevel.WARN); } }
/** * Do not use this method! Use Registries.getLocationRegistry() instead! * * @return * * @throws org.openbase.jul.exception.NotAvailableException * @deprecated Do not use this method! Use Registries.getLocationRegistry() instead! */ @Deprecated default LocationRegistry getLocationRegistry() throws NotAvailableException { // method is only needed because the registry is still throwing a InterruptedException which will removed in a future release. // todo release: can be removed later on try { try { return CachedLocationRegistryRemote.getRegistry(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new FatalImplementationErrorException("", this, ex); } } catch (CouldNotPerformException ex) { throw new NotAvailableException(LocationRegistry.class); } }
@Override protected File getPropertyDefaultValue() { // use tmp folder in test case if (JPService.testMode()) { try { return JPService.getProperty(JPTmpDirectory.class).getValue(); } catch (JPNotAvailableException ex) { // exception is already printed in constructore so no further forwarding needed. new FatalImplementationErrorException("Could not link test tmp directory as bco home path for java tests.", this, ex); } } // use bco home system variable if defined String systemDefinedHome = System.getenv(SYSTEM_VARIABLE_BCO_HOME); if (systemDefinedHome != null) { return new File(systemDefinedHome); } return new File(DEFAULT_PATH); }
/** * Reset the unit remote pool by shutting down every remote instance and * clearing the local registry. This is needed for unit tests because else * remote states are not cleared between tests which can result in * unpredictable values. This method can only be triggered in test mode. * Else it throws a FatalImplementationErrorException. * * @param responsibleObject should be the object which triggers the reset * which is used for proper exception handling * @throws CouldNotPerformException if reset fails */ public static void reset(final Object responsibleObject) throws CouldNotPerformException { try { if (!JPService.testMode()) { throw new FatalImplementationErrorException("Units can only be reseted in test mode!", responsibleObject); } UNIT_REMOTE_REGISTRY_LOCK.writeLock().lock(); try { for (UnitRemote unitRemote : new ArrayList<>(unitRemoteRegistry.getEntries())) { removeUnitRemote(unitRemote); } } finally { UNIT_REMOTE_REGISTRY_LOCK.writeLock().unlock(); } } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not reset Units!", ex); } }