Search in sources :

Example 36 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ShadowIntegrityCheckResultHandler method doFixIntent.

private void doFixIntent(ShadowCheckResult checkResult, PrismObject<ShadowType> fetchedShadow, PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, Task task, OperationResult result) {
    PrismObject<ShadowType> fullShadow;
    if (!checkFetch) {
        fullShadow = fetchShadow(checkResult, shadow, resource, task, result);
    } else {
        fullShadow = fetchedShadow;
    }
    if (fullShadow == null) {
        checkResult.recordError(Statistics.CANNOT_APPLY_FIX, new SystemException("Cannot fix missing intent, because the resource object couldn't be fetched"));
        return;
    }
    ObjectSynchronizationType synchronizationPolicy;
    try {
        synchronizationPolicy = synchronizationService.determineSynchronizationPolicy(resource.asObjectable(), fullShadow, configuration, task, result);
    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException e) {
        checkResult.recordError(Statistics.CANNOT_APPLY_FIX, new SystemException("Couldn't prepare fix for missing intent, because the synchronization policy couldn't be determined", e));
        return;
    }
    if (synchronizationPolicy != null) {
        if (synchronizationPolicy.getIntent() != null) {
            PropertyDelta delta = PropertyDelta.createReplaceDelta(fullShadow.getDefinition(), ShadowType.F_INTENT, synchronizationPolicy.getIntent());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Intent fix delta (not executed now) = \n{}", delta.debugDump());
            }
            checkResult.addFixDelta(delta, Statistics.NO_INTENT_SPECIFIED);
        } else {
            LOGGER.info("Synchronization policy does not contain intent: {}", synchronizationPolicy);
        }
    } else {
        LOGGER.info("Intent couldn't be fixed, because no synchronization policy was found");
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 37 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class PrismContainer method createNewValue.

public PrismContainerValue<C> createNewValue() {
    checkMutability();
    PrismContainerValue<C> pValue = new PrismContainerValue<>(prismContext);
    try {
        // No need to check uniqueness, we know that this value is new and therefore
        // it will change anyway and therefore the check is pointless.
        // However, the check is expensive (especially if there are many values).
        // So we are happy to avoid it.
        add(pValue, false);
    } catch (SchemaException e) {
        // This should not happen
        throw new SystemException("Internal Error: " + e.getMessage(), e);
    }
    return pValue;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 38 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class PrismReferenceValue method asReferencable.

public Referencable asReferencable() {
    if (referencable != null) {
        return referencable;
    }
    Itemable parent = getParent();
    if (parent != null) {
        QName xsdType = parent.getDefinition().getTypeName();
        Class clazz = getPrismContext().getSchemaRegistry().getCompileTimeClass(xsdType);
        if (clazz != null) {
            try {
                referencable = (Referencable) clazz.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                throw new SystemException("Couldn't create jaxb object instance of '" + clazz + "': " + e.getMessage(), e);
            }
        }
        referencable.setupReferenceValue(this);
    }
    // A hack, just to avoid crashes. TODO think about this!
    return new Referencable() {

        PrismReferenceValue referenceValue = PrismReferenceValue.this;

        @Override
        public PrismReferenceValue asReferenceValue() {
            return referenceValue;
        }

        @Override
        public void setupReferenceValue(PrismReferenceValue value) {
            referenceValue = value;
        }

        @Override
        public String getOid() {
            return referenceValue.getOid();
        }

        @Override
        public QName getType() {
            return referenceValue.getTargetType();
        }

        @Override
        public PolyStringType getTargetName() {
            return PrismForJAXBUtil.getReferenceTargetName(referenceValue);
        }

        @Override
        public QName getRelation() {
            return referenceValue.getRelation();
        }

        @Override
        public String getDescription() {
            return referenceValue.getDescription();
        }

        @Override
        public EvaluationTimeType getResolutionTime() {
            return referenceValue.getResolutionTime();
        }

        @Override
        public SearchFilterType getFilter() {
            SearchFilterType filter = new SearchFilterType();
            filter.setFilterClauseXNode(PrismForJAXBUtil.getReferenceFilterClauseXNode(referenceValue));
            return filter;
        }
    };
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName)

Example 39 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ProtectorImpl method init.

/**
     * @throws SystemException if jceks keystore is not available on {@link ProtectorImpl#getKeyStorePath}
     */
public void init() {
    InputStream stream = null;
    try {
        // Test if use file or classpath resource
        File f = new File(getKeyStorePath());
        if (f.exists()) {
            LOGGER.info("Using file keystore at {}", getKeyStorePath());
            if (!f.canRead()) {
                LOGGER.error("Provided keystore file {} is unreadable.", getKeyStorePath());
                throw new EncryptionException("Provided keystore file " + getKeyStorePath() + " is unreadable.");
            }
            stream = new FileInputStream(f);
        // Use class path keystore
        } else {
            LOGGER.warn("Using default keystore from classpath ({}).", getKeyStorePath());
            // Read from class path
            stream = ProtectorImpl.class.getClassLoader().getResourceAsStream(getKeyStorePath());
            // class path
            if (stream == null) {
                stream = ProtectorImpl.class.getClassLoader().getResourceAsStream("com/../../" + getKeyStorePath());
            }
        }
        // Test if we have valid stream
        if (stream == null) {
            throw new EncryptionException("Couldn't load keystore as resource '" + getKeyStorePath() + "'");
        }
        // Load keystore
        keyStore.load(stream, getKeyStorePassword().toCharArray());
        stream.close();
        // Initialze trust manager list
        TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmFactory.init(keyStore);
        trustManagers = new ArrayList<TrustManager>();
        for (TrustManager trustManager : tmFactory.getTrustManagers()) {
            trustManagers.add(trustManager);
        }
        //init apache crypto library
        Init.init();
    } catch (Exception ex) {
        LOGGER.error("Unable to work with keystore {}, reason {}.", new Object[] { getKeyStorePath(), ex.getMessage() }, ex);
        throw new SystemException(ex.getMessage(), ex);
    }
    randomNumberGenerator = new SecureRandom();
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SecureRandom(java.security.SecureRandom) File(java.io.File) FileInputStream(java.io.FileInputStream) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) KeyStoreException(java.security.KeyStoreException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) SystemException(com.evolveum.midpoint.util.exception.SystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchProviderException(java.security.NoSuchProviderException) TrustManager(javax.net.ssl.TrustManager)

Example 40 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class PrismContainerValue method copyDefinition.

// copies the definition from original to aClone (created outside of this method)
// it has to (artifically) create a parent PrismContainer to hold the definition
//
// without having a definition, such containers cannot be serialized using
// PrismJaxbProcessor.marshalContainerableToString (without definition, there is
// no information on corresponding element name)
//
// todo review usefulness and appropriateness of this method and its placement
@Deprecated
public static void copyDefinition(Containerable aClone, Containerable original, PrismContext prismContext) {
    try {
        Validate.notNull(original.asPrismContainerValue().getParent(), "original PrismContainerValue has no parent");
        ComplexTypeDefinition definition = original.asPrismContainerValue().getComplexTypeDefinition();
        Validate.notNull(definition, "original PrismContainer definition is null");
        PrismContainer<?> aCloneParent = prismContext.getSchemaRegistry().findContainerDefinitionByCompileTimeClass((Class<? extends Containerable>) definition.getCompileTimeClass()).instantiate();
        aCloneParent.add(aClone.asPrismContainerValue());
    } catch (SchemaException e) {
        throw new SystemException("Unexpected SchemaException when copying definition from original object to its clone", e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12