Search in sources :

Example 11 with ModelService

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService in project midpoint by Evolveum.

the class ConsistencyTest method test000Integrity.

/**
	 * Test integrity of the test setup.
	 */
@Test
public void test000Integrity() throws Exception {
    final String TEST_NAME = "test000Integrity";
    TestUtil.displayTestTile(this, TEST_NAME);
    assertNotNull(modelWeb);
    assertNotNull(modelService);
    assertNotNull(repositoryService);
    assertTrue(isSystemInitialized());
    assertNotNull(taskManager);
    assertNotNull(prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull(schemaRegistry);
    // This is defined in extra schema. So this effectively checks whether
    // the extra schema was loaded
    PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
    assertNotNull("No my:shipState definition", shipStateDefinition);
    assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
    assertNoRepoCache();
    OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
    // Check if OpenDJ resource was imported correctly
    PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
    display("Imported OpenDJ resource (repository)", openDjResource);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
    assertNoRepoCache();
    String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
    PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
    display("LDAP Connector: ", ldapConnector);
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 12 with ModelService

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService in project midpoint by Evolveum.

the class AbstractWebserviceTest method createModelPort.

/**
     * Creates webservice client connecting to midpoint
     * */
protected static ModelPortType createModelPort(String username, String password, String passwordType) {
    String endpoint = ENDPOINT;
    if (System.getProperty("midpoint.endpoint") != null) {
        endpoint = System.getProperty("midpoint.endpoint");
    }
    LOGGER.info("Creating model client endpoint: {} , username={}, password={}", new Object[] { endpoint, username, password });
    ModelService modelService = new ModelService();
    ModelPortType modelPort = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) modelPort;
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
    Map<String, Object> outProps = new HashMap<String, Object>();
    if (username != null) {
        outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        outProps.put(WSHandlerConstants.USER, username);
        outProps.put(WSHandlerConstants.PASSWORD_TYPE, passwordType);
        ClientPasswordHandler.setPassword(password);
        outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
        cxfEndpoint.getOutInterceptors().add(wssOut);
    }
    cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
    cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
    return modelPort;
}
Also used : ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) BindingProvider(javax.xml.ws.BindingProvider) ModelService(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 13 with ModelService

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService in project midpoint by Evolveum.

the class ResourceUtils method deleteSchema.

public static void deleteSchema(PrismObject<ResourceType> resource, ModelService modelService, PrismContext prismContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    PrismContainer<XmlSchemaType> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (schemaContainer != null && schemaContainer.getValue() != null) {
        PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findProperty(XmlSchemaType.F_DEFINITION);
        if (definitionProperty != null && !definitionProperty.isEmpty()) {
            PrismPropertyValue<SchemaDefinitionType> definitionValue = definitionProperty.getValue().clone();
            ObjectDelta<ResourceType> deleteSchemaDefinitionDelta = ObjectDelta.createModificationDeleteProperty(ResourceType.class, resource.getOid(), new ItemPath(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), prismContext, // TODO ...or replace with null?
            definitionValue.getValue());
            // delete schema
            modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(deleteSchemaDefinitionDelta), null, task, parentResult);
        }
    }
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with ModelService

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService in project midpoint by Evolveum.

the class PageDebugDownloadBehaviour method dumpObjectsToStream.

private void dumpObjectsToStream(final Writer writer, OperationResult result) throws Exception {
    final PageBase page = getPage();
    ResultHandler handler = (object, parentResult) -> {
        try {
            String xml = page.getPrismContext().xmlSerializer().options(createSerializeForExport()).serialize(object);
            writer.write('\t');
            writer.write(xml);
            writer.write('\n');
        } catch (IOException | SchemaException ex) {
            throw new SystemException(ex.getMessage(), ex);
        }
        return true;
    };
    ModelService service = page.getModelService();
    GetOperationOptionsBuilder optionsBuilder = page.getSchemaService().getOperationOptionsBuilder().raw().resolveNames();
    if (showAllItems) {
        optionsBuilder = optionsBuilder.retrieve();
    }
    service.searchObjectsIterative(type, query, handler, optionsBuilder.build(), page.createSimpleTask(OPERATION_SEARCH_OBJECT), result);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) LocalDateTime(java.time.LocalDateTime) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) StringUtils(org.apache.commons.lang3.StringUtils) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) SchemaConstantsGenerated(com.evolveum.midpoint.schema.SchemaConstantsGenerated) RestartResponseException(org.apache.wicket.RestartResponseException) ZipEntry(java.util.zip.ZipEntry) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) Files(org.apache.wicket.util.file.Files) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) PageDebugList(com.evolveum.midpoint.web.page.admin.configuration.PageDebugList) ModelService(com.evolveum.midpoint.model.api.ModelService) File(org.apache.wicket.util.file.File) java.io(java.io) SerializationOptions.createSerializeForExport(com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) SystemException(com.evolveum.midpoint.util.exception.SystemException) DateTimeFormatter(java.time.format.DateTimeFormatter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SystemException(com.evolveum.midpoint.util.exception.SystemException) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 15 with ModelService

use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService in project midpoint by Evolveum.

the class CapabilityStep method savePerformed.

private void savePerformed() {
    Task task = getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES);
    OperationResult result = task.getResult();
    ModelService modelService = getPageBase().getModelService();
    boolean saved = false;
    try {
        PrismObject<ResourceType> oldResource;
        final PrismObject<ResourceType> resourceObject = resourceModel.getObject();
        ResourceType resource = resourceObject.asObjectable();
        List<Object> unsupportedCapabilities = new ArrayList<>();
        if (resource.getCapabilities().getConfigured() != null) {
            for (Object o : resource.getCapabilities().getConfigured().getAny()) {
                CapabilityType capabilityType = CapabilityUtil.asCapabilityType(o);
                if (!Capability.supports(capabilityType.getClass())) {
                    unsupportedCapabilities.add(o);
                }
            }
        }
        // AnyArrayList that is used to implement getAny() is really strange (e.g. doesn't support iterator.remove();
        // and its support for clear() is questionable) -- so let's recreate it altogether
        resource.getCapabilities().setConfigured(new CapabilityCollectionType());
        resource.getCapabilities().getConfigured().getAny().addAll(unsupportedCapabilities);
        ObjectFactory capabilityFactory = new ObjectFactory();
        for (CapabilityDto dto : dtoModel.getObject().getCapabilities()) {
            JAXBElement<? extends CapabilityType> jaxbCapability = createJAXBCapability(dto.getCapability(), capabilityFactory);
            if (jaxbCapability != null) {
                resource.getCapabilities().getConfigured().getAny().add(jaxbCapability);
            }
        }
        oldResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
        if (oldResource != null) {
            ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, resourceObject);
            if (!delta.isEmpty()) {
                parentPage.logDelta(delta);
                @SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
                modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES), result);
                parentPage.resetModels();
                saved = true;
            }
        }
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save capabilities", e);
        result.recordFatalError(getString("CapabilityStep.message.cantSaveCaps"), e);
    } finally {
        result.computeStatusIfUnknown();
        setResult(result);
    }
    if (parentPage.showSaveResultInPage(saved, result)) {
        getPageBase().showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ModelService(com.evolveum.midpoint.model.api.ModelService) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)6 ModelService (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService)6 BindingProvider (javax.xml.ws.BindingProvider)6 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)6 Task (com.evolveum.midpoint.task.api.Task)5 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 HashMap (java.util.HashMap)4 Test (org.testng.annotations.Test)4 ModelService (com.evolveum.midpoint.model.api.ModelService)3 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)3 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)3 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)3 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)2 CommonException (com.evolveum.midpoint.util.exception.CommonException)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2