Search in sources :

Example 61 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class ExportObjects method execute.

public boolean execute() throws UnsupportedEncodingException, FileNotFoundException {
    System.out.println("Starting objects export.");
    File file = new File(filePath);
    if (file.exists() || file.canRead()) {
        System.out.println("XML file already exists, export won't be done.");
        return false;
    }
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONTEXTS);
    final OutputStreamWriter stream = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
    try {
        System.out.println("Loading spring contexts.");
        System.out.println("Set repository.");
        RepositoryService repository = context.getBean("repositoryService", RepositoryService.class);
        ResultHandler<ObjectType> handler = new ResultHandler<ObjectType>() {

            PrismContext prismContext = context.getBean(PrismContext.class);

            @Override
            public boolean handle(PrismObject<ObjectType> object, OperationResult parentResult) {
                String displayName = getDisplayName(object);
                System.out.println("Exporting object " + displayName);
                OperationResult resultExport = new OperationResult("Export " + displayName);
                try {
                    String stringObject = prismContext.serializeObjectToString(object, PrismContext.LANG_XML);
                    stream.write("\t" + stringObject + "\n");
                } catch (Exception ex) {
                    System.out.println("Failed to parse objects to string for xml. Reason: " + ex);
                    resultExport.recordFatalError("Failed to parse objects to string for xml. Reason: ", ex);
                }
                return true;
            }
        };
        stream.write(createHeaderForXml());
        OperationResult result = new OperationResult("search set");
        System.out.println("Creating xml file " + file.getName());
        repository.searchObjectsIterative(ObjectType.class, null, handler, null, false, result);
        stream.write("</objects>");
        System.out.println("Created xml file " + file.getName());
    } catch (Exception ex) {
        System.out.println("Exception occurred during context loading, reason: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        destroyContext(context);
        if (stream != null) {
            IOUtils.closeQuietly(stream);
        }
    }
    System.out.println("Objects export finished.");
    return true;
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 62 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class TestWSSecurity method test105GetConfigWrongUsernameDigest.

@Test
public void test105GetConfigWrongUsernameDigest() throws Exception {
    final String TEST_NAME = "test105GetConfigWrongUsernameDigest";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort("admin", USER_ADMINISTRATOR_PASSWORD, WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginFailed(tailer, "no user");
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Example 63 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class TestWSSecurity method test104GetConfigEmptyPasswordText.

@Test
public void test104GetConfigEmptyPasswordText() throws Exception {
    final String TEST_NAME = "test104GetConfigEmptyPasswordText";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort(USER_ADMINISTRATOR_USERNAME, "", WSConstants.PW_TEXT);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginFailed(tailer, "could not be authenticated or authorized");
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Example 64 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class TestWSSecurity method test110GetConfigGoodPasswordDigest.

@Test
public void test110GetConfigGoodPasswordDigest() throws Exception {
    final String TEST_NAME = "test110GetConfigGoodPasswordDigest";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort(USER_ADMINISTRATOR_USERNAME, USER_ADMINISTRATOR_PASSWORD, WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
    tailer.tail();
    assertAuditLoginLogout(tailer);
    assertAuditIds(tailer);
    tailer.assertAudit(2);
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) Test(org.testng.annotations.Test)

Example 65 with ObjectType

use of org.mitre.cybox.cybox_2.ObjectType in project midpoint by Evolveum.

the class TestWSSecurity method test131GetConfigAsCyclopsGoodPasswordDigest.

@Test
public void test131GetConfigAsCyclopsGoodPasswordDigest() throws Exception {
    final String TEST_NAME = "test131GetConfigAsCyclopsGoodPasswordDigest";
    displayTestTitle(TEST_NAME);
    modelPort = createModelPort(USER_CYCLOPS_USERNAME, USER_CYCLOPS_PASSWORD, WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    LogfileTestTailer tailer = createLogTailer();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginLogout(tailer);
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)243 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)126 Test (org.testng.annotations.Test)97 Task (com.evolveum.midpoint.task.api.Task)82 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)79 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)78 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)68 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)55 ArrayList (java.util.ArrayList)51 Holder (javax.xml.ws.Holder)48 QName (javax.xml.namespace.QName)32 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)29 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)28 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)25 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)25 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)24 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)23 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)22