public void revive(Object bean, final PrismContext prismContext) throws SchemaException { Handler<Object> visitor = o -> { if (o instanceof Revivable) { try { ((Revivable)o).revive(prismContext); } catch (SchemaException e) { throw new TunnelException(e); } } return true; }; try { visit(bean, visitor); } catch (TunnelException te) { SchemaException e = (SchemaException) te.getCause(); throw e; } }
throw new TunnelException(e); Throwable originalException = te.getCause(); if (originalException instanceof SchemaException) { throw (SchemaException) originalException; throw (RuntimeException) originalException; } else { throw new IllegalStateException("Unexpected exception: "+te+": "+te.getMessage(), te);
@SuppressWarnings("WeakerAccess") public static <T> T unwrapTunnelledException(TunnelException te) throws CommonException { Throwable cause = te.getCause(); if (cause instanceof CommonException) { throw (CommonException) cause; } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else { throw te; } }
/** * Same as contains, but wraps exceptions in TunnelException. */ public <IV extends PrismValue> boolean containsTunnel(IV pval) { try { return contains(pval); } catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) { throw new TunnelException(e); } }
if (te.getCause() instanceof SchemaException) { throw (SchemaException)te.getCause(); } else if (te.getCause() instanceof ConfigurationException) { throw (ConfigurationException)te.getCause(); } else if (te.getCause() instanceof ExpressionEvaluationException) { throw (ExpressionEvaluationException)te.getCause(); } else if (te.getCause() instanceof ObjectNotFoundException) { throw (ObjectNotFoundException)te.getCause(); } else if (te.getCause() instanceof CommunicationException) { throw (CommunicationException)te.getCause(); } else if (te.getCause() instanceof SecurityViolationException) { throw (SecurityViolationException)te.getCause(); } else { throw new SystemException("Unexpected exception: "+te, te);
@NotNull private static Visitor createEncryptingVisitor(Protector protector) { return visitable -> { if (!(visitable instanceof PrismPropertyValue)) { return; } PrismPropertyValue<?> pval = (PrismPropertyValue<?>)visitable; try { encryptValue(protector, pval); } catch (EncryptionException e) { throw new TunnelException(e); } }; }
protected <F extends FocusType> ContainerDelta<AssignmentType> createAssignmentModification(Class<F> type, QName elementName, String roleOid, QName refType, QName relation, PrismContainer<?> extension, ActivationType activationType, boolean add) throws SchemaException { try { return createAssignmentModification(type, elementName, roleOid, refType, relation, assignment -> { if (extension != null) { try { assignment.asPrismContainerValue().add(extension.clone()); } catch (SchemaException e) { throw new TunnelException(e); } } assignment.setActivation(activationType); }, add); } catch (TunnelException te) { throw (SchemaException)te.getCause(); } }
throw new TunnelException( localizationService.translate( new ExpressionEvaluationException( ExceptionUtil.getUserFriendlyMessage(e)))); } catch (ObjectNotFoundException e) { throw new TunnelException(new ObjectNotFoundException(e.getMessage()+ "("+dumpSourceValues(sourceVariables)+") in "+contextDescription,e)); } catch (SchemaException e) { throw new TunnelException(new SchemaException(e.getMessage()+ "("+dumpSourceValues(sourceVariables)+") in "+contextDescription,e)); } catch (RuntimeException e) { throw new TunnelException(new RuntimeException(e.getMessage()+ "("+dumpSourceValues(sourceVariables)+") in "+contextDescription,e)); } catch (CommunicationException e) { throw new TunnelException(new CommunicationException(e.getMessage()+ "("+dumpSourceValues(sourceVariables)+") in "+contextDescription,e)); } catch (ConfigurationException e) { throw new TunnelException(new ConfigurationException(e.getMessage()+ "("+dumpSourceValues(sourceVariables)+") in "+contextDescription,e)); } catch (SecurityViolationException e) { throw new TunnelException(new SecurityViolationException(e.getMessage()+ "("+dumpSourceValues(sourceVariables)+") in "+contextDescription,e)); MiscUtil.carthesian((Collection)valueCollections, (Processor)processor); } catch (TunnelException e) { Throwable originalException = e.getCause(); if (originalException instanceof ExpressionEvaluationException) { throw (ExpressionEvaluationException)originalException;
/** * Encrypts all encryptable values in the object. */ public static <T extends ObjectType> void encryptValues(Protector protector, PrismObject<T> object) throws EncryptionException { try { object.accept(createEncryptingVisitor(protector)); } catch (TunnelException e) { throw (EncryptionException) e.getCause(); } }
public static <T> T runChecked(CheckedFunction<Producer<T>, T> function, CheckedProducer<T> checkedProducer) throws CommonException { try { return function.apply(() -> { try { return checkedProducer.get(); } catch (CommonException e) { throw new TunnelException(e); } }); } catch (TunnelException te) { return unwrapTunnelledException(te); // return is just for formal reasons -- this throws exceptions only } }
} catch (SchemaException | ObjectNotFoundException | ConfigurationException | CommunicationException | ExpressionEvaluationException e) { throw new TunnelException(e); Throwable cause = e.getCause(); if (cause instanceof SchemaException) { throw (SchemaException) cause;
/** * Encrypts all encryptable values in delta. */ public static <T extends ObjectType> void encryptValues(Protector protector, ObjectDelta<T> delta) throws EncryptionException { try { delta.accept(createEncryptingVisitor(protector)); } catch (TunnelException e) { throw (EncryptionException) e.getCause(); } }
task, result); } catch (SchemaException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | SecurityViolationException e) { throw new TunnelException(e);
} catch (SchemaException | ObjectNotFoundException | ConfigurationException | CommunicationException | ExpressionEvaluationException e) { throw new TunnelException(e); Throwable cause = e.getCause(); if (cause instanceof SchemaException) { throw (SchemaException) cause;
/** * Re-encrypts all encryptable values in the object. */ public static <T extends ObjectType> int reencryptValues(Protector protector, PrismObject<T> object) throws EncryptionException { try { Holder<Integer> modCountHolder = new Holder<>(0); object.accept(createVisitor((ps, propName) -> reencryptProtectedStringType(ps, propName, modCountHolder, protector))); return modCountHolder.getValue(); } catch (TunnelException e) { throw (EncryptionException) e.getCause(); } }
private static void reencryptProtectedStringType(ProtectedStringType ps, String propName, Holder<Integer> modCountHolder, Protector protector) { if (ps == null) { // nothing to do here } else if (ps.isHashed()) { // nothing to do here } else if (ps.getClearValue() != null) { try { protector.encrypt(ps); increment(modCountHolder); } catch (EncryptionException e) { throw new TunnelException(new EncryptionException("Failed to encrypt value for field " + propName + ": " + e.getMessage(), e)); } } else if (ps.getEncryptedDataType() != null) { try { if (!protector.isEncryptedByCurrentKey(ps.getEncryptedDataType())) { ProtectedStringType reencrypted = protector.encryptString(protector.decryptString(ps)); ps.setEncryptedData(reencrypted.getEncryptedDataType()); increment(modCountHolder); } } catch (EncryptionException e) { throw new TunnelException(new EncryptionException("Failed to check/reencrypt value for field " + propName + ": " + e.getMessage(), e)); } } else { // no clear nor encrypted value } }
ResourceAttributeDefinition attributeDefinition = objectClassDefinition.findAttributeDefinition(attributeName); if (attributeDefinition == null) { throw new TunnelException(new SchemaException("No definition for attribute " + attributeName + " in query " + query)); filter.accept(visitor); } catch (TunnelException te) { throw (SchemaException) te.getCause();
throw (SchemaException)e.getCause();
@Override public boolean handle(PrismObject<ShadowType> entitlementShadow) { PrismContainerValue<ShadowAssociationType> associationCVal = associationContainer.createNewValue(); associationCVal.asContainerable().setName(associationName); Collection<ResourceAttribute<?>> entitlementIdentifiers = ShadowUtil.getAllIdentifiers(entitlementShadow); try { ResourceAttributeContainer identifiersContainer = ObjectFactory.createResourceAttributeContainer( ShadowAssociationType.F_IDENTIFIERS, entitlementDef.toResourceAttributeContainerDefinition(), prismContext); associationCVal.add(identifiersContainer); identifiersContainer.getValue().addAll(Item.cloneCollection(entitlementIdentifiers)); // Remember the full shadow in user data. This is used later as an optimization to create the shadow in repo identifiersContainer.setUserData(ResourceObjectConverter.FULL_SHADOW_KEY, entitlementShadow); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Processed entitlement-to-subject association for account {} and entitlement {}", ShadowUtil.getHumanReadableName(resourceObject), ShadowUtil.getHumanReadableName(entitlementShadow)); } } catch (SchemaException e) { throw new TunnelException(e); } return true; } };
case ZERO: if (!PrismValueCollectionsUtil.containsRealValue(shouldBeParentOrgRefs, val)) { throw new TunnelException(new PolicyViolationException("Attempt to add parentOrgRef "+val.getOid()+", but it is not allowed by assignments")); throw new TunnelException(new PolicyViolationException("Attempt to delete parentOrgRef "+val.getOid()+", but it is mandated by assignments")); throw (PolicyViolationException)e.getCause();