Search in sources :

Example 16 with CommunicationException

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

the class ResourceObjectReferenceResolver method fetchResourceObject.

public PrismObject<ShadowType> fetchResourceObject(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, AttributesToReturn attributesToReturn, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    try {
        if (!ResourceTypeUtil.isReadCapabilityEnabled(resource)) {
            throw new UnsupportedOperationException("Resource does not support 'read' operation");
        }
        ResourceObjectIdentification identification = ResourceObjectIdentification.create(objectClassDefinition, identifiers);
        identification = resolvePrimaryIdentifiers(ctx, identification, parentResult);
        identification.validatePrimaryIdenfiers();
        return connector.fetchObject(ShadowType.class, identification, attributesToReturn, ctx, parentResult);
    } catch (ObjectNotFoundException e) {
        parentResult.recordFatalError("Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e);
        throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass=" + PrettyPrinter.prettyPrint(objectClassDefinition.getTypeName()) + ": " + e.getMessage(), e);
    } catch (CommunicationException e) {
        parentResult.recordFatalError("Error communication with the connector " + connector + ": " + e.getMessage(), e);
        throw e;
    } catch (GenericFrameworkException e) {
        parentResult.recordFatalError("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
        throw new GenericConnectorException("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
    } catch (SchemaException ex) {
        parentResult.recordFatalError("Can't get resource object, schema error: " + ex.getMessage(), ex);
        throw ex;
    } catch (ExpressionEvaluationException ex) {
        parentResult.recordFatalError("Can't get resource object, expression error: " + ex.getMessage(), ex);
        throw ex;
    } catch (ConfigurationException e) {
        parentResult.recordFatalError(e);
        throw e;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ResourceObjectIdentification(com.evolveum.midpoint.schema.processor.ResourceObjectIdentification) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Example 17 with CommunicationException

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

the class AbstractModelIntegrationTest method assertAllowRequestItems.

protected void assertAllowRequestItems(String userOid, String targetRoleOid, AuthorizationDecisionType expectedDefaultDecision, QName... expectedAllowedItemQNames) throws SchemaException, SecurityViolationException, CommunicationException, ObjectNotFoundException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<UserType> user = getUser(userOid);
    PrismObject<RoleType> target = getRole(targetRoleOid);
    ItemSecurityDecisions decisions = modelInteractionService.getAllowedRequestAssignmentItems(user, target);
    display("Request decisions for " + target, decisions);
    assertEquals("Wrong assign default decision", expectedDefaultDecision, decisions.getDefaultDecision());
    assertEquals("Unexpected number of allowed items", expectedAllowedItemQNames.length, decisions.getItemDecisionMap().size());
    decisions.getItemDecisionMap().forEach((path, decision) -> {
        assertEquals("wrong item " + path + " decision", AuthorizationDecisionType.ALLOW, decision);
        QName lastPathName = path.lastNamed().getName();
        if (!Arrays.stream(expectedAllowedItemQNames).anyMatch(qname -> QNameUtil.match(qname, lastPathName))) {
            AssertJUnit.fail("Unexpected path " + path);
        }
    });
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Entry(org.opends.server.types.Entry) Map(java.util.Map) UserProfileService(com.evolveum.midpoint.security.api.UserProfileService) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) RepositoryDiag(com.evolveum.midpoint.schema.RepositoryDiag) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ModelService(com.evolveum.midpoint.model.api.ModelService) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) FilterInvocation(org.springframework.security.web.FilterInvocation) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Clock(com.evolveum.midpoint.common.Clock) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) HookRegistry(com.evolveum.midpoint.model.api.hooks.HookRegistry) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ConnectException(java.net.ConnectException) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) AfterClass(org.testng.annotations.AfterClass) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) IOException(java.io.IOException) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ModelElementContext(com.evolveum.midpoint.model.api.context.ModelElementContext) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SystemObjectsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) PrismValue(com.evolveum.midpoint.prism.PrismValue) NotificationManager(com.evolveum.midpoint.notifications.api.NotificationManager) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Date(java.util.Date) AuthorizationConstants(com.evolveum.midpoint.security.api.AuthorizationConstants) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) AssignmentSelectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentSelectorType) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) SecurityContext(org.springframework.security.core.context.SecurityContext) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) SecurityConfig(org.springframework.security.access.SecurityConfig) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Checker(com.evolveum.midpoint.test.Checker) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) AssertJUnit(org.testng.AssertJUnit) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) AdminGuiConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AdminGuiConfigurationType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) SchemaTestConstants(com.evolveum.midpoint.schema.util.SchemaTestConstants) DummyAuditService(com.evolveum.midpoint.test.DummyAuditService) OrgFilter(com.evolveum.midpoint.prism.query.OrgFilter) DebugUtil(com.evolveum.midpoint.util.DebugUtil) DummyResourceContoller(com.evolveum.midpoint.test.DummyResourceContoller) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) HashSet(java.util.HashSet) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) AuthorizationPhaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationPhaseType) FileInputStream(java.io.FileInputStream) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Consumer(java.util.function.Consumer) ItemSecurityDecisions(com.evolveum.midpoint.security.api.ItemSecurityDecisions) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) PrismReference(com.evolveum.midpoint.prism.PrismReference) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Arrays(java.util.Arrays) ChangeType(com.evolveum.midpoint.prism.delta.ChangeType) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) AssertJUnit.assertNull(org.testng.AssertJUnit.assertNull) MidpointFunctions(com.evolveum.midpoint.model.api.expr.MidpointFunctions) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) Holder(com.evolveum.midpoint.util.Holder) Set(java.util.Set) Task(com.evolveum.midpoint.task.api.Task) TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) ObjectPolicyConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Authorization(com.evolveum.midpoint.security.api.Authorization) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) Trace(com.evolveum.midpoint.util.logging.Trace) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ArrayList(java.util.ArrayList) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) RefinedResourceSchemaImpl(com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl) PrismContext(com.evolveum.midpoint.prism.PrismContext) SynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationType) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) File(java.io.File) ModelDiagnosticService(com.evolveum.midpoint.model.api.ModelDiagnosticService) CommonException(com.evolveum.midpoint.util.exception.CommonException) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) MidPointAsserts(com.evolveum.midpoint.test.util.MidPointAsserts) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ModelAuditService(com.evolveum.midpoint.model.api.ModelAuditService) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) AuthorityUtils(org.springframework.security.core.authority.AuthorityUtils) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) TaskExecutionStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStatusType) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) QNameUtil(com.evolveum.midpoint.util.QNameUtil) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) DirectoryException(org.opends.server.types.DirectoryException) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) ConfigAttribute(org.springframework.security.access.ConfigAttribute) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) FileNotFoundException(java.io.FileNotFoundException) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) List(java.util.List) Optional(java.util.Optional) Authentication(org.springframework.security.core.Authentication) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Item(com.evolveum.midpoint.prism.Item) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SecurityEnforcer(com.evolveum.midpoint.security.api.SecurityEnforcer) HashMap(java.util.HashMap) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) RoleSelectionSpecification(com.evolveum.midpoint.model.api.RoleSelectionSpecification) ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) AuthorizationDecisionType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationDecisionType) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) Containerable(com.evolveum.midpoint.prism.Containerable) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) DeltaBuilder(com.evolveum.midpoint.prism.delta.builder.DeltaBuilder) DummyResource(com.evolveum.icf.dummy.resource.DummyResource) TaskExecutionStatus(com.evolveum.midpoint.task.api.TaskExecutionStatus) IntegrationTestTools.display(com.evolveum.midpoint.test.IntegrationTestTools.display) Message(com.evolveum.midpoint.notifications.api.transports.Message) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) FailableProcessor(com.evolveum.midpoint.util.FailableProcessor) SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Collections(java.util.Collections) AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) QName(javax.xml.namespace.QName) ItemSecurityDecisions(com.evolveum.midpoint.security.api.ItemSecurityDecisions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 18 with CommunicationException

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

the class ConnectorInstanceConnIdImpl method addObject.

@Override
public AsynchronousOperationReturnValue<Collection<ResourceAttribute<?>>> addObject(PrismObject<? extends ShadowType> shadow, Collection<Operation> additionalOperations, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ObjectAlreadyExistsException, ConfigurationException {
    validateShadow(shadow, "add", false);
    ShadowType shadowType = shadow.asObjectable();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".addObject");
    result.addParam("resourceObject", shadow);
    // because of serialization issues
    result.addParam("additionalOperations", DebugUtil.debugDump(additionalOperations));
    ObjectClassComplexTypeDefinition ocDef;
    ResourceAttributeContainerDefinition attrContDef = attributesContainer.getDefinition();
    if (attrContDef != null) {
        ocDef = attrContDef.getComplexTypeDefinition();
    } else {
        ocDef = resourceSchema.findObjectClassDefinition(shadow.asObjectable().getObjectClass());
        if (ocDef == null) {
            throw new SchemaException("Unknown object class " + shadow.asObjectable().getObjectClass());
        }
    }
    // getting icf object class from resource object class
    ObjectClass icfObjectClass = connIdNameMapper.objectClassToIcf(shadow, getSchemaNamespace(), connectorType, legacySchema);
    if (icfObjectClass == null) {
        result.recordFatalError("Couldn't get icf object class from " + shadow);
        throw new IllegalArgumentException("Couldn't get icf object class from " + shadow);
    }
    // setting ifc attributes from resource object attributes
    Set<Attribute> attributes = null;
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("midPoint object before conversion:\n{}", attributesContainer.debugDump());
        }
        attributes = connIdConvertor.convertFromResourceObject(attributesContainer, ocDef);
        if (shadowType.getCredentials() != null && shadowType.getCredentials().getPassword() != null) {
            PasswordType password = shadowType.getCredentials().getPassword();
            ProtectedStringType protectedString = password.getValue();
            GuardedString guardedPassword = ConnIdUtil.toGuardedString(protectedString, "new password", protector);
            if (guardedPassword != null) {
                attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_NAME, guardedPassword));
            }
        }
        if (ActivationUtil.hasAdministrativeActivation(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, ActivationUtil.isAdministrativeEnabled(shadowType)));
        }
        if (ActivationUtil.hasValidFrom(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.ENABLE_DATE_NAME, XmlTypeConverter.toMillis(shadowType.getActivation().getValidFrom())));
        }
        if (ActivationUtil.hasValidTo(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.DISABLE_DATE_NAME, XmlTypeConverter.toMillis(shadowType.getActivation().getValidTo())));
        }
        if (ActivationUtil.hasLockoutStatus(shadowType)) {
            attributes.add(AttributeBuilder.build(OperationalAttributes.LOCK_OUT_NAME, ActivationUtil.isLockedOut(shadowType)));
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("ICF attributes after conversion:\n{}", ConnIdUtil.dump(attributes));
        }
    } catch (SchemaException | RuntimeException ex) {
        result.recordFatalError("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
        throw new SchemaException("Error while converting resource object attributes. Reason: " + ex.getMessage(), ex);
    }
    if (attributes == null) {
        result.recordFatalError("Couldn't set attributes for icf.");
        throw new IllegalStateException("Couldn't set attributes for icf.");
    }
    List<String> icfAuxiliaryObjectClasses = new ArrayList<>();
    for (QName auxiliaryObjectClass : shadowType.getAuxiliaryObjectClass()) {
        icfAuxiliaryObjectClasses.add(connIdNameMapper.objectClassToIcf(auxiliaryObjectClass, resourceSchemaNamespace, connectorType, false).getObjectClassValue());
    }
    if (!icfAuxiliaryObjectClasses.isEmpty()) {
        AttributeBuilder ab = new AttributeBuilder();
        ab.setName(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME);
        ab.addValue(icfAuxiliaryObjectClasses);
        attributes.add(ab.build());
    }
    OperationOptionsBuilder operationOptionsBuilder = new OperationOptionsBuilder();
    OperationOptions options = operationOptionsBuilder.build();
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
    OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".create");
    connIdResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
    connIdResult.addArbitraryCollectionAsParam("auxiliaryObjectClasses", icfAuxiliaryObjectClasses);
    connIdResult.addArbitraryCollectionAsParam("attributes", attributes);
    connIdResult.addArbitraryObjectAsParam("options", options);
    connIdResult.addContext("connector", connIdConnectorFacade.getClass());
    Uid uid = null;
    try {
        // CALL THE ICF FRAMEWORK
        InternalMonitor.recordConnectorOperation("create");
        // TODO provide object name
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_CREATE, ocDef, null);
        uid = connIdConnectorFacade.create(icfObjectClass, attributes, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_CREATE, ocDef, uid);
    } catch (Throwable ex) {
        // TODO name
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_CREATE, ocDef, ex, null);
        Throwable midpointEx = processIcfException(ex, this, connIdResult);
        result.computeStatus("Add object failed");
        // exception
        if (midpointEx instanceof ObjectAlreadyExistsException) {
            throw (ObjectAlreadyExistsException) midpointEx;
        } else if (midpointEx instanceof CommunicationException) {
            //				result.muteError();
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            throw (SchemaException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
    if (uid == null || uid.getUidValue() == null || uid.getUidValue().isEmpty()) {
        connIdResult.recordFatalError("ICF did not returned UID after create");
        result.computeStatus("Add object failed");
        throw new GenericFrameworkException("ICF did not returned UID after create");
    }
    Collection<ResourceAttribute<?>> identifiers = ConnIdUtil.convertToIdentifiers(uid, attributesContainer.getDefinition().getComplexTypeDefinition(), resourceSchema);
    for (ResourceAttribute<?> identifier : identifiers) {
        attributesContainer.getValue().addReplaceExisting(identifier);
    }
    connIdResult.recordSuccess();
    result.recordSuccess();
    return AsynchronousOperationReturnValue.wrap(attributesContainer.getAttributes(), result);
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Attribute(org.identityconnectors.framework.common.objects.Attribute) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) GuardedString(org.identityconnectors.common.security.GuardedString) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) Uid(org.identityconnectors.framework.common.objects.Uid) QualifiedUid(org.identityconnectors.framework.common.objects.QualifiedUid) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 19 with CommunicationException

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

the class ConfigurationExceptionHandler method handleError.

@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof ConfigurationException) {
            throw (ConfigurationException) ex;
        } else {
            throw new ConfigurationException(ex.getMessage(), ex);
        }
    }
    ObjectDelta delta = null;
    switch(op) {
        case ADD:
            delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
            break;
        case DELETE:
            delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
            break;
        case MODIFY:
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
            break;
        case GET:
            OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ConfigurationExceptionHandler.handleError." + op.name());
            operationResult.addParam("shadow", shadow);
            operationResult.addParam("currentOperation", op);
            operationResult.addParam("exception", ex.getMessage());
            for (OperationResult subRes : parentResult.getSubresults()) {
                subRes.muteError();
            }
            operationResult.recordPartialError("Could not get " + ObjectTypeUtil.toShortString(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because of configuration error. Returning shadow from the repository");
            shadow.setFetchResult(operationResult.createOperationResultType());
            return shadow;
    }
    if (op != FailedOperation.GET) {
        //		Task task = taskManager.createTaskInstance();
        ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
        changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
    }
    if (shadow.getOid() == null) {
        throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
    }
    Collection<ItemDelta> modification = createAttemptModification(shadow, null);
    try {
        ConstraintsChecker.onShadowModifyOperation(modification);
        cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
    } catch (Exception e) {
        //this should not happen. But if it happens, we should return original exception
        LOGGER.error("Unexpected error while modifying shadow {}: {}", shadow, e.getMessage(), e);
        if (ex instanceof SchemaException) {
            throw ((SchemaException) ex);
        } else if (ex instanceof GenericFrameworkException) {
            throw ((GenericFrameworkException) ex);
        } else if (ex instanceof CommunicationException) {
            throw ((CommunicationException) ex);
        } else if (ex instanceof ObjectNotFoundException) {
            throw ((ObjectNotFoundException) ex);
        } else if (ex instanceof ObjectAlreadyExistsException) {
            throw ((ObjectAlreadyExistsException) ex);
        } else if (ex instanceof ConfigurationException) {
            throw ((ConfigurationException) ex);
        }
    }
    parentResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
    throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 20 with CommunicationException

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

the class AbstractLdapHierarchyTest method reconcileAllOrgs.

protected void reconcileAllOrgs() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final Task task = createTask("reconcileAllOrgs");
    OperationResult result = task.getResult();
    ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {

        @Override
        public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
            try {
                display("reconciling " + object);
                reconcileOrg(object.getOid(), task, parentResult);
            } catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
                throw new SystemException(e.getMessage(), e);
            }
            return true;
        }
    };
    display("Reconciling all orgs");
    modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)105 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)90 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)84 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)83 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)72 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)70 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)62 SystemException (com.evolveum.midpoint.util.exception.SystemException)42 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)37 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 Task (com.evolveum.midpoint.task.api.Task)29 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)24 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)20 Collection (java.util.Collection)17 ArrayList (java.util.ArrayList)16 QName (javax.xml.namespace.QName)16 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 List (java.util.List)13