Search in sources :

Example 61 with SystemConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType in project midpoint by Evolveum.

the class SchemaTransformer method determineObjectTemplate.

public <O extends ObjectType> ObjectTemplateType determineObjectTemplate(Class<O> objectClass, AuthorizationPhaseType phase, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException {
    PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
    if (systemConfiguration == null) {
        return null;
    }
    ObjectPolicyConfigurationType objectPolicyConfiguration = ModelUtils.determineObjectPolicyConfiguration(objectClass, null, systemConfiguration.asObjectable());
    if (objectPolicyConfiguration == null) {
        return null;
    }
    ObjectReferenceType objectTemplateRef = objectPolicyConfiguration.getObjectTemplateRef();
    if (objectTemplateRef == null) {
        return null;
    }
    PrismObject<ObjectTemplateType> template = cacheRepositoryService.getObject(ObjectTemplateType.class, objectTemplateRef.getOid(), null, result);
    return template.asObjectable();
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectPolicyConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)

Example 62 with SystemConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType in project midpoint by Evolveum.

the class SystemConfigurationHandler method invoke.

@Override
public <O extends ObjectType> HookOperationMode invoke(@NotNull ModelContext<O> context, @NotNull Task task, @NotNull OperationResult parentResult) {
    ModelState state = context.getState();
    if (state != ModelState.FINAL) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("sysconfig handler called in state = " + state + ", exiting.");
        }
        return HookOperationMode.FOREGROUND;
    } else {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("sysconfig handler called in state = " + state + ", proceeding.");
        }
    }
    if (context.getFocusClass() != SystemConfigurationType.class) {
        LOGGER.trace("invoke() EXITING: Changes not related to systemConfiguration");
        return HookOperationMode.FOREGROUND;
    }
    ModelContext<SystemConfigurationType> confContext = (ModelContext<SystemConfigurationType>) context;
    ModelElementContext<SystemConfigurationType> focusContext = confContext.getFocusContext();
    // is this config-related change a deletion?
    boolean isDeletion = false;
    PrismObject<SystemConfigurationType> object = focusContext.getObjectNew();
    if (object == null) {
        isDeletion = true;
        object = focusContext.getObjectOld();
    }
    if (object == null) {
        // if the handler would not work because of this, for us to see the reason
        LOGGER.warn("Probably invalid projection context: both old and new objects are null");
    }
    LOGGER.trace("change relates to sysconfig, is deletion: {}", isDeletion);
    OperationResult result = parentResult.createSubresult(DOT_CLASS + "invoke");
    try {
        if (isDeletion) {
            // because the new config (if any) will have version number probably starting at 1 - so to be sure to read it when it comes
            LoggingConfigurationManager.resetCurrentlyUsedVersion();
            LOGGER.trace("invoke() EXITING because operation is DELETION");
            return HookOperationMode.FOREGROUND;
        }
        /*
             * Because we need to know actual version of the system configuration (generated by repo), we have to re-read
             * current configuration. (At this moment, it is already stored there.)
             */
        PrismObject<SystemConfigurationType> config = cacheRepositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result);
        LOGGER.trace("invoke() SystemConfig from repo: {}, ApplyingLoggingConfiguration", config.getVersion());
        SystemConfigurationHolder.setCurrentConfiguration(config.asObjectable());
        SecurityUtil.setRemoteHostAddressHeaders(config.asObjectable());
        applyLoggingConfiguration(ProfilingConfigurationManager.checkSystemProfilingConfiguration(config), config.asObjectable().getVersion(), result);
        cacheRepositoryService.applyFullTextSearchConfiguration(config.asObjectable().getFullTextSearch());
        result.recordSuccessIfUnknown();
    } catch (ObjectNotFoundException e) {
        String message = "Cannot read system configuration because it does not exist in repository: " + e.getMessage();
        LoggingUtils.logException(LOGGER, message, e);
        result.recordFatalError(message, e);
    } catch (SchemaException e) {
        String message = "Cannot read system configuration because of schema exception: " + e.getMessage();
        LoggingUtils.logException(LOGGER, message, e);
        result.recordFatalError(message, e);
    }
    return HookOperationMode.FOREGROUND;
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ModelState(com.evolveum.midpoint.model.api.context.ModelState) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 63 with SystemConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType in project midpoint by Evolveum.

the class TestProjector method test451GuybrushInboundFromAbsolute.

@Test
public void test451GuybrushInboundFromAbsolute() throws Exception {
    final String TEST_NAME = "test451GuybrushInboundFromAbsolute";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestProjector.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<ValuePolicyType> passPolicy = PrismTestUtil.parseObject(PASSWORD_POLICY_GLOBAL_FILE);
    ObjectDelta delta = ObjectDelta.createAddDelta(passPolicy);
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    deltas.add(delta);
    modelService.executeChanges(deltas, null, task, result);
    deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta refDelta = ObjectDelta.createModificationAddReference(SystemConfigurationType.class, SYSTEM_CONFIGURATION_OID, SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY_REF, prismContext, passPolicy);
    // We need to execute this using repo. Otherwise logging config will be ruined
    repositoryService.modifyObject(SystemConfigurationType.class, SYSTEM_CONFIGURATION_OID, refDelta.getModifications(), result);
    PrismObject<ValuePolicyType> passPol = modelService.getObject(ValuePolicyType.class, PASSWORD_POLICY_GLOBAL_OID, null, task, result);
    assertNotNull(passPol);
    PrismObject<SystemConfigurationType> sysConfig = modelService.getObject(SystemConfigurationType.class, SYSTEM_CONFIGURATION_OID, null, task, result);
    assertNotNull("No global password policy", sysConfig.asObjectable().getGlobalPasswordPolicyRef());
    assertEquals(PASSWORD_POLICY_GLOBAL_OID, sysConfig.asObjectable().getGlobalPasswordPolicyRef().getOid());
    // GIVEN
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_GUYBRUSH_OID, result);
    fillContextWithAccountFromFile(context, ACCOUNT_GUYBRUSH_DUMMY_FILE, task, result);
    LensProjectionContext guybrushAccountContext = context.findProjectionContextByOid(ACCOUNT_SHADOW_GUYBRUSH_OID);
    guybrushAccountContext.setFullShadow(true);
    guybrushAccountContext.setDoReconciliation(true);
    context.recompute();
    display("Input context", context);
    assertFocusModificationSanity(context);
    // WHEN
    projector.project(context, "test", task, result);
    // THEN
    display("Output context", context);
    assertNoUserPrimaryDelta(context);
    assertUserSecondaryDelta(context);
    ObjectDelta<UserType> userSecondaryDelta = context.getFocusContext().getSecondaryDelta();
    assertTrue(userSecondaryDelta.getChangeType() == ChangeType.MODIFY);
    PrismAsserts.assertPropertyAdd(userSecondaryDelta, UserType.F_ORGANIZATIONAL_UNIT, PrismTestUtil.createPolyString("The crew of The Sea Monkey"));
    assertOriginWithSideEffectChanges(userSecondaryDelta, OriginType.INBOUND);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)40 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 Task (com.evolveum.midpoint.task.api.Task)14 Test (org.testng.annotations.Test)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)10 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)8 LoggingConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType)8 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)8 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 ObjectPolicyConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType)6 ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4