From 7f10af146a027823b8d8abdb1925cd5e11153c6d Mon Sep 17 00:00:00 2001 From: Ivan Noris Date: Mon, 14 Mar 2016 09:30:40 +0100 Subject: [PATCH 01/11] Bumped year to 2016 in headers --- .../multitenant-idm-saas/lookupTables/lookup-employee-type.xml | 2 +- .../objectTemplates/object-template-org.xml | 2 +- .../objectTemplates/object-template-user.xml | 2 +- samples/stories/multitenant-idm-saas/org/org-top.xml | 2 +- .../multitenant-idm-saas/resources/crm-simulation-sync.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/stories/multitenant-idm-saas/lookupTables/lookup-employee-type.xml b/samples/stories/multitenant-idm-saas/lookupTables/lookup-employee-type.xml index a9d7c2367a2..ea0fd04fadd 100644 --- a/samples/stories/multitenant-idm-saas/lookupTables/lookup-employee-type.xml +++ b/samples/stories/multitenant-idm-saas/lookupTables/lookup-employee-type.xml @@ -1,6 +1,6 @@ + diff --git a/samples/stories/multitenant-idm-saas/valuePolicies/stronger-password-policy.xml b/samples/stories/multitenant-idm-saas/valuePolicies/stronger-password-policy.xml index 19cd0996737..7c6876b0f4c 100644 --- a/samples/stories/multitenant-idm-saas/valuePolicies/stronger-password-policy.xml +++ b/samples/stories/multitenant-idm-saas/valuePolicies/stronger-password-policy.xml @@ -1,4 +1,19 @@ + diff --git a/samples/stories/multitenant-idm-saas/valuePolicies/verystrong-password-policy.xml b/samples/stories/multitenant-idm-saas/valuePolicies/verystrong-password-policy.xml index 2bbd5716ad7..202fa33b6d6 100644 --- a/samples/stories/multitenant-idm-saas/valuePolicies/verystrong-password-policy.xml +++ b/samples/stories/multitenant-idm-saas/valuePolicies/verystrong-password-policy.xml @@ -1,4 +1,19 @@ + From 42478f306a395ed14e925bafd9587245c1dd6380 Mon Sep 17 00:00:00 2001 From: honchar Date: Mon, 14 Mar 2016 14:10:07 +0100 Subject: [PATCH 03/11] MID-2785 fixed --- .../web/component/progress/ProgressPanel.html | 1 + .../web/component/progress/ProgressPanel.java | 28 +++++++++++- .../component/progress/ProgressReporter.java | 16 ++++++- .../web/page/admin/PageAdminFocus.java | 4 +- .../page/admin/PageAdminObjectDetails.java | 2 +- .../web/page/admin/roles/PageRole.java | 2 +- .../web/page/admin/users/PageOrgUnit.java | 2 +- .../web/page/admin/users/PageUser.java | 2 +- .../web/page/self/PageSelfProfile.java | 2 +- .../evolveum/midpoint/web/PageLoginTest.java | 43 +++++++++++++++++++ .../resources/ctx-admin-gui-test-main.xml | 6 +-- .../resources/csvfile/midpoint-flatfile.csv | 4 ++ 12 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 gui/admin-gui/src/test/java/com/evolveum/midpoint/web/PageLoginTest.java diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.html index 2ef3036db5c..bc1e735c222 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.html @@ -47,6 +47,7 @@ diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.java index fb1c16463a9..8b69ab44f8e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressPanel.java @@ -21,10 +21,12 @@ import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.web.component.AjaxSubmitButton; import com.evolveum.midpoint.web.component.form.Form; +import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails; import com.evolveum.midpoint.web.page.admin.server.dto.OperationResultStatusIcon; import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType; import org.apache.wicket.AttributeModifier; +import org.apache.wicket.Page; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; @@ -221,8 +223,30 @@ protected void onError(AjaxRequestTarget target, target.add(page.getFeedbackPanel()); } }; - progressReporter.registerAbortButton(abortButton); - progressForm.add(abortButton); + + progressReporter.registerAbortButton(abortButton); + progressForm.add(abortButton); + + AjaxSubmitButton backButton = new AjaxSubmitButton("back", + createStringResource("pageAdminFocus.button.back")) { + + @Override + protected void onSubmit(AjaxRequestTarget target, + org.apache.wicket.markup.html.form.Form form) { + Page page = getPage(); + if (page != null && page instanceof PageAdminObjectDetails){ + setResponsePage(((PageAdminObjectDetails) page).getDefaultBackPage()); + } + } + + @Override + protected void onError(AjaxRequestTarget target, + org.apache.wicket.markup.html.form.Form form) { + target.add(page.getFeedbackPanel()); + } + }; + progressReporter.registerBackButton(backButton); + progressForm.add(backButton); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressReporter.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressReporter.java index cdc99649898..c0c37f8b204 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressReporter.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/progress/ProgressReporter.java @@ -68,6 +68,7 @@ public class ProgressReporter implements Serializable { // links to wicket artefacts on parent page private AjaxSubmitButton abortButton; + private AjaxSubmitButton backButton; private ProgressReportingAwarePage parentPage; private ProgressPanel progressPanel; private Behavior refreshingBehavior = null; // behavior is attached to the progress panel @@ -191,6 +192,7 @@ public void run() { if (abortEnabled) { showAbortButton(target); } + showBackButton(target); result.recordInProgress(); // to disable showing not-final results (why does it work? and why is the result shown otherwise?) @@ -244,6 +246,13 @@ public void registerAbortButton(AjaxSubmitButton abortButton) { this.abortButton = abortButton; } + public void registerBackButton(AjaxSubmitButton backButton) { + backButton.setOutputMarkupId(true); + backButton.setOutputMarkupPlaceholderTag(true); + backButton.setVisible(false); + this.backButton = backButton; + } + /** * You have to call this method when Abort button is pressed */ @@ -266,7 +275,7 @@ public void onAbortSubmit(AjaxRequestTarget target) { hideAbortButton(target); } - private void hideAbortButton(AjaxRequestTarget target) { + public void hideAbortButton(AjaxRequestTarget target) { abortButton.setVisible(false); target.add(abortButton); } @@ -276,6 +285,11 @@ public void showAbortButton(AjaxRequestTarget target) { target.add(abortButton); } + public void showBackButton(AjaxRequestTarget target) { + backButton.setVisible(true); + target.add(backButton); + } + // ================= Other methods ================= diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminFocus.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminFocus.java index 4250ebac3a1..f4fecf50291 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminFocus.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminFocus.java @@ -203,7 +203,9 @@ public void finishProcessing(AjaxRequestTarget target, OperationResult result) { } goBackPage(); } else { - showResult(result); + getProgressReporter().showBackButton(target); + getProgressReporter().hideAbortButton(target); + showResult(result); target.add(getFeedbackPanel()); // if we only stayed on the page because of displaying results, hide diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminObjectDetails.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminObjectDetails.java index 305c14ac0a3..fdf95e0a42f 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminObjectDetails.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/PageAdminObjectDetails.java @@ -637,7 +637,7 @@ public void goBackPage() { } } - protected abstract PageBase getDefaultBackPage(); + public abstract PageBase getDefaultBackPage(); public List getObjectFormTypes() { Task task = createSimpleTask(OPERATION_LOAD_GUI_CONFIGURATION); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/roles/PageRole.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/roles/PageRole.java index 35ef0dc37f0..04dfb8bc38d 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/roles/PageRole.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/roles/PageRole.java @@ -196,7 +196,7 @@ protected AbstractObjectMainPanel createMainPanel(String id) { } @Override - protected PageBase getDefaultBackPage() { + public PageBase getDefaultBackPage() { return new PageRoles(false, ""); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageOrgUnit.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageOrgUnit.java index 57c699aab37..abfd877ee36 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageOrgUnit.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageOrgUnit.java @@ -165,7 +165,7 @@ protected AbstractObjectMainPanel createMainPanel(String id) { } @Override - protected PageBase getDefaultBackPage() { + public PageBase getDefaultBackPage() { return new PageOrgTree(); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUser.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUser.java index 1bf38b9a7d4..e78f79a6017 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUser.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUser.java @@ -129,7 +129,7 @@ protected AbstractObjectMainPanel createMainPanel(String id) { } @Override - protected PageBase getDefaultBackPage() { + public PageBase getDefaultBackPage() { return new PageUsers(); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageSelfProfile.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageSelfProfile.java index d4720e7638e..284a06ff57e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageSelfProfile.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/self/PageSelfProfile.java @@ -54,7 +54,7 @@ protected String getObjectOidParameter() { } @Override - protected PageBase getDefaultBackPage() { + public PageBase getDefaultBackPage() { return new PageSelfProfile(); } // diff --git a/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/PageLoginTest.java b/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/PageLoginTest.java new file mode 100644 index 00000000000..e0806c4d2fc --- /dev/null +++ b/gui/admin-gui/src/test/java/com/evolveum/midpoint/web/PageLoginTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010-2016 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.evolveum.midpoint.web; + +import com.evolveum.midpoint.web.page.admin.users.PageUser; +import com.evolveum.midpoint.web.page.login.PageLogin; +import org.apache.wicket.util.tester.WicketTester; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.Test; + +/** + * Created by honchar + */ +@ContextConfiguration(locations = {"classpath:ctx-admin-gui-test-main.xml"}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +public class PageLoginTest extends AbstractInitializedGuiIntegrationTest { + + @Test + public void test001BasicRender() { + WicketTester tester = new WicketTester(); + PageLogin page = tester.startPage(PageLogin.class); + tester.assertRenderedPage(PageUser.class); + } + + + +} diff --git a/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml b/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml index 5743e9504df..c255b2ff20b 100644 --- a/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml +++ b/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml @@ -39,7 +39,7 @@ - - - + + + \ No newline at end of file diff --git a/samples/resources/csvfile/midpoint-flatfile.csv b/samples/resources/csvfile/midpoint-flatfile.csv index 5cac4cded74..1b7d0d16346 100644 --- a/samples/resources/csvfile/midpoint-flatfile.csv +++ b/samples/resources/csvfile/midpoint-flatfile.csv @@ -1,3 +1,7 @@ "id","firstname","lastname","disabled","password" "user01","Firstname","Lastname","false","secret" "user02","Test","Lastname","false","secret" +"nnnnn","fffff","lllll","false","password" +"AAAA_DEL_PROJ11","AAAA_DEL_PROJ","last","false","password" +"maxeassign11","maxeassign1","maxeassign1","false","maxeassign1" +"AAA_del_proj_user","AAA_del_proj_user","AAA_del_proj_user","false","AAA_del_proj_user" From 7776aeea996533296c852451b98dd2cc8ddc1a5b Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Mon, 14 Mar 2016 20:11:10 +0100 Subject: [PATCH 04/11] Fixing handling of native auxiliary object class change. More prism delta tests. --- .../midpoint/prism/PrismProperty.java | 12 +- .../com/evolveum/midpoint/prism/TestDiff.java | 261 +++++++++++++++++- .../provisioning/impl/ShadowCache.java | 123 +++------ .../provisioning/impl/ShadowManager.java | 67 ++++- .../midpoint/testing/story/TestUnix.java | 110 +++++++- 5 files changed, 477 insertions(+), 96 deletions(-) diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/PrismProperty.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/PrismProperty.java index 8336ec640ba..876ca0e5886 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/PrismProperty.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/PrismProperty.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Evolveum + * Copyright (c) 2010-2016 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -393,6 +393,16 @@ public PropertyDelta diff(PrismProperty other, boolean ignoreMetadata, boo } return (PropertyDelta)deltas.get(0); } + + public static PropertyDelta diff(PrismProperty a, PrismProperty b) { + if (a == null) { + PropertyDelta delta = b.createDelta(); + delta.addValuesToAdd(PrismValue.cloneCollection(b.getValues())); + return delta; + } else { + return a.diff(b); + } + } @Override protected void checkDefinition(PrismPropertyDefinition def) { diff --git a/infra/prism/src/test/java/com/evolveum/midpoint/prism/TestDiff.java b/infra/prism/src/test/java/com/evolveum/midpoint/prism/TestDiff.java index 8567962ff86..b2352b98b65 100644 --- a/infra/prism/src/test/java/com/evolveum/midpoint/prism/TestDiff.java +++ b/infra/prism/src/test/java/com/evolveum/midpoint/prism/TestDiff.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Evolveum + * Copyright (c) 2010-2016 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.evolveum.midpoint.prism; +import static org.testng.AssertJUnit.assertNull; import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNotNull; @@ -28,12 +29,14 @@ import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.delta.ObjectDelta; +import com.evolveum.midpoint.prism.delta.PropertyDelta; import com.evolveum.midpoint.prism.foo.AssignmentType; import com.evolveum.midpoint.prism.foo.UserType; import com.evolveum.midpoint.prism.path.IdItemPathSegment; import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.path.ItemPathSegment; import com.evolveum.midpoint.prism.path.NameItemPathSegment; +import com.evolveum.midpoint.prism.polystring.PolyString; import com.evolveum.midpoint.prism.util.PrismAsserts; import com.evolveum.midpoint.prism.util.PrismTestUtil; import com.evolveum.midpoint.util.DebugUtil; @@ -75,6 +78,52 @@ public void testUserSimplePropertyDiffNoChange() throws Exception { assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); } + + @Test + public void testPropertySimplePropertyDiffNoChange() throws Exception { + System.out.println("\n\n===[ testPropertySimplePropertyDiffNoChange ]===\n"); + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + user1.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); + PrismProperty user1NameProp = user1.findProperty(UserType.F_NAME); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + user2.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); + PrismProperty user2NameProp = user2.findProperty(UserType.F_NAME); + + // WHEN + PropertyDelta delta = user1NameProp.diff(user2NameProp); + + // THEN + assertNull(delta); + } + + @Test + public void testPropertySimplePropertyDiffNoChangeStatic() throws Exception { + System.out.println("\n\n===[ testPropertySimplePropertyDiffNoChangeStatic ]===\n"); + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + user1.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); + PrismProperty user1NameProp = user1.findProperty(UserType.F_NAME); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + user2.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); + PrismProperty user2NameProp = user2.findProperty(UserType.F_NAME); + + // WHEN + PropertyDelta delta = PrismProperty.diff(user1NameProp, user2NameProp); + + // THEN + assertNull(delta); + } @Test public void testUserSimplePropertyDiffReplace() throws Exception { @@ -102,6 +151,58 @@ public void testUserSimplePropertyDiffReplace() throws Exception { delta.checkConsistence(); } + @Test + public void testPropertyUserSimplePropertyDiffReplace() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimplePropertyDiffReplace ]===\n"); + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + user1.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); + PrismProperty user1NameProp = user1.findProperty(UserType.F_NAME); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + user2.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("other name")); + PrismProperty user2NameProp = user2.findProperty(UserType.F_NAME); + + // WHEN + PropertyDelta delta = user1NameProp.diff(user2NameProp); + + // THEN + assertNotNull(delta); + System.out.println(delta.debugDump()); + PrismAsserts.assertReplace(delta, PrismTestUtil.createPolyString("other name")); + delta.checkConsistence(); + } + + @Test + public void testPropertyUserSimplePropertyDiffReplaceStatic() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimplePropertyDiffReplaceStatic ]===\n"); + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + user1.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); + PrismProperty user1NameProp = user1.findProperty(UserType.F_NAME); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + user2.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("other name")); + PrismProperty user2NameProp = user2.findProperty(UserType.F_NAME); + + // WHEN + PropertyDelta delta = PrismProperty.diff(user1NameProp, user2NameProp); + + // THEN + assertNotNull(delta); + System.out.println(delta.debugDump()); + PrismAsserts.assertReplace(delta, PrismTestUtil.createPolyString("other name")); + delta.checkConsistence(); + } + @Test public void testUserSimpleDiffMultiNoChange() throws Exception { System.out.println("\n\n===[ testUserSimpleDiffMultiNoChange ]===\n"); @@ -130,6 +231,58 @@ public void testUserSimpleDiffMultiNoChange() throws Exception { assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); } + + @Test + public void testPropertyUserSimpleDiffMultiNoChange() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimpleDiffMultiNoChange ]===\n"); + + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp1.addRealValue("foo"); + additionalNamesProp1.addRealValue("bar"); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp2.addRealValue("foo"); + additionalNamesProp2.addRealValue("bar"); + + // WHEN + PropertyDelta delta = additionalNamesProp1.diff(additionalNamesProp2); + + // THEN + assertNull(delta); + } + + @Test + public void testPropertyUserSimpleDiffMultiNoChangeStatic() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimpleDiffMultiNoChangeStatic ]===\n"); + + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp1.addRealValue("foo"); + additionalNamesProp1.addRealValue("bar"); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp2.addRealValue("foo"); + additionalNamesProp2.addRealValue("bar"); + + // WHEN + PropertyDelta delta = PrismProperty.diff(additionalNamesProp1, additionalNamesProp2); + + // THEN + assertNull(delta); + } @Test public void testUserSimpleDiffMultiAdd() throws Exception { @@ -162,6 +315,112 @@ public void testUserSimpleDiffMultiAdd() throws Exception { assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); } + + @Test + public void testPropertyUserSimpleDiffMultiAdd() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimpleDiffMultiAdd ]===\n"); + + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp1.addRealValue("foo"); + additionalNamesProp1.addRealValue("bar"); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp2.addRealValue("foo"); + additionalNamesProp2.addRealValue("bar"); + additionalNamesProp2.addRealValue("baz"); + + // WHEN + PropertyDelta delta = additionalNamesProp1.diff(additionalNamesProp2); + + // THEN + assertNotNull(delta); + System.out.println(delta.debugDump()); + PrismAsserts.assertAdd(delta, "baz"); + delta.checkConsistence(); + } + + @Test + public void testPropertyUserSimpleDiffMultiAddStatic() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimpleDiffMultiAddStatic ]===\n"); + + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user1 = userDef.instantiate(); + user1.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp1.addRealValue("foo"); + additionalNamesProp1.addRealValue("bar"); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp2.addRealValue("foo"); + additionalNamesProp2.addRealValue("bar"); + additionalNamesProp2.addRealValue("baz"); + + // WHEN + PropertyDelta delta = PrismProperty.diff(additionalNamesProp1, additionalNamesProp2); + + // THEN + assertNotNull(delta); + System.out.println(delta.debugDump()); + PrismAsserts.assertAdd(delta, "baz"); + delta.checkConsistence(); + } + + @Test + public void testPropertyUserSimpleDiffMultiAddStaticNull1() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimpleDiffMultiAddStaticNull1 ]===\n"); + + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp2.addRealValue("foo"); + additionalNamesProp2.addRealValue("bar"); + + // WHEN + PropertyDelta delta = PrismProperty.diff(null, additionalNamesProp2); + + // THEN + assertNotNull(delta); + System.out.println(delta.debugDump()); + PrismAsserts.assertAdd(delta, "foo", "bar"); + delta.checkConsistence(); + } + + @Test + public void testPropertyUserSimpleDiffMultiAddStaticNull2() throws Exception { + System.out.println("\n\n===[ testPropertyUserSimpleDiffMultiAddStaticNull2 ]===\n"); + + // GIVEN + PrismObjectDefinition userDef = getUserTypeDefinition(); + + PrismObject user2 = userDef.instantiate(); + user2.setOid(USER_JACK_OID); + PrismProperty additionalNamesProp1 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES); + additionalNamesProp1.addRealValue("bar"); + additionalNamesProp1.addRealValue("baz"); + + // WHEN + PropertyDelta delta = PrismProperty.diff(additionalNamesProp1, null); + + // THEN + assertNotNull(delta); + System.out.println(delta.debugDump()); + PrismAsserts.assertDelete(delta, "bar", "baz"); + delta.checkConsistence(); + } @Test public void testContainerSimpleDiffNoChange() throws Exception { diff --git a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java index ac4ab619909..87abf967547 100644 --- a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java +++ b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowCache.java @@ -265,6 +265,9 @@ public PrismObject getShadow(String oid, PrismObject rep resourceShadow = resouceObjectConverter.getResourceObject(ctx, identifiers, true, parentResult); + // Resource shadow may have different auxiliary object classes than the original repo shadow. Make sure we have + // the definition that applies to resource shadow. We will fix repo shadow later. + ProvisioningContext shadowCtx = ctx.spawn(resourceShadow); resourceManager.modifyResourceAvailabilityStatus(resource.asPrismObject(), AvailabilityStatusType.UP, parentResult); //try to apply changes to the account only if the resource if UP @@ -280,9 +283,9 @@ public PrismObject getShadow(String oid, PrismObject rep LOGGER.trace("Resource object fetched from resource:\n{}", resourceShadow.debugDump()); } - forceRenameIfNeeded(ctx, resourceShadow.asObjectable(), repositoryShadow.asObjectable(), parentResult); + shadowManager.updateRepoShadow(shadowCtx, resourceShadow.asObjectable(), repositoryShadow.asObjectable(), parentResult); // Complete the shadow by adding attributes from the resource object - PrismObject resultShadow = completeShadow(ctx, resourceShadow, repositoryShadow, parentResult); + PrismObject resultShadow = completeShadow(shadowCtx, resourceShadow, repositoryShadow, parentResult); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Shadow when assembled:\n{}", resultShadow.debugDump()); @@ -731,7 +734,7 @@ public boolean handle(PrismObject resourceShadow) { // This determines the definitions exactly. How the repo shadow should have proper kind/intent ProvisioningContext shadowCtx = applyAttributesDefinition(ctx, repoShadow); - forceRenameIfNeeded(shadowCtx, resourceShadow.asObjectable(), repoShadow.asObjectable(), parentResult); + shadowManager.updateRepoShadow(shadowCtx, resourceShadow.asObjectable(), repoShadow.asObjectable(), parentResult); resultShadow = completeShadow(shadowCtx, resourceShadow, repoShadow, parentResult); @@ -1346,7 +1349,7 @@ void processChange(ProvisioningContext ctx, Change change, PrismObje oldShadow, parentResult); change.setCurrentShadow(currentShadow); ShadowType currentShadowType = currentShadow.asObjectable(); - forceRenameIfNeeded(ctx, currentShadowType, oldShadowType, parentResult); + shadowManager.updateRepoShadow(ctx, currentShadowType, oldShadowType, parentResult); } // FIXME: hack. the object delta must have oid specified. @@ -1364,57 +1367,6 @@ void processChange(ProvisioningContext ctx, Change change, PrismObje } - // TODO: better move this to shadowManager? - private void forceRenameIfNeeded(ProvisioningContext ctx, ShadowType currentShadowType, ShadowType oldShadowType, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, CommunicationException { - Collection> oldSecondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(oldShadowType); - if (oldSecondaryIdentifiers.isEmpty()){ - return; - } - ResourceAttributeContainer newSecondaryIdentifiers = ShadowUtil.getAttributesContainer(currentShadowType); - - //remember name before normalizing attributes - PolyString currentShadowName = ShadowUtil.determineShadowName(currentShadowType); - currentShadowType.setName(new PolyStringType(currentShadowName)); - - Iterator> oldSecondaryIterator = oldSecondaryIdentifiers.iterator(); - Collection renameDeltas = new ArrayList(); - while (oldSecondaryIterator.hasNext()){ - ResourceAttribute oldSecondaryIdentifier = oldSecondaryIterator.next(); - ResourceAttribute newSecondaryIdentifier = newSecondaryIdentifiers.findAttribute(oldSecondaryIdentifier.getElementName()); - Collection newValue = newSecondaryIdentifier.getRealValues(); - - if (!shadowManager.compareAttribute(ctx.getObjectClassDefinition(), newSecondaryIdentifier, oldSecondaryIdentifier)){ - PropertyDelta propertyDelta = PropertyDelta.createDelta(new ItemPath(ShadowType.F_ATTRIBUTES, oldSecondaryIdentifier.getElementName()), oldShadowType.asPrismObject().getDefinition()); - propertyDelta.addValuesToDelete(PrismPropertyValue.cloneCollection((Collection)oldSecondaryIdentifier.getValues())); - propertyDelta.addValuesToAdd(PrismPropertyValue.cloneCollection((Collection)newSecondaryIdentifier.getValues())); - renameDeltas.add(propertyDelta); - } - - } - - if (!renameDeltas.isEmpty()){ - - PropertyDelta shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, - oldShadowType.asPrismObject().getDefinition(),currentShadowName); - renameDeltas.add(shadowNameDelta); - } else { - - if (!oldShadowType.getName().getOrig().equals(currentShadowType.getName().getOrig())){ - PropertyDelta shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, - oldShadowType.asPrismObject().getDefinition(), currentShadowName); - renameDeltas.add(shadowNameDelta); - - } - } - if (!renameDeltas.isEmpty()){ - shadowManager.normalizeDeltas((Collection)renameDeltas, ctx.getObjectClassDefinition()); - ConstraintsChecker.onShadowModifyOperation(renameDeltas); - repositoryService.modifyObject(ShadowType.class, oldShadowType.getOid(), renameDeltas, parentResult); - oldShadowType.setName(new PolyStringType(currentShadowName)); - } - - } - public PrismProperty fetchCurrentToken(ResourceShadowDiscriminator shadowCoordinates, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException { Validate.notNull(parentResult, "Operation result must not be null."); @@ -1436,18 +1388,7 @@ public PrismProperty fetchCurrentToken(ResourceShadowDiscriminator shadowCoor parentResult.recordSuccess(); return lastToken; } - - - ////////////////////////////////////////////////////////////////////////////////////// - - -// public ObjectClassComplexTypeDefinition applyAttributesDefinition(ProvisioningContext ctx, ObjectDelta delta, -// PrismObject shadow) throws SchemaException, ConfigurationException { -// RefinedResourceSchema refinedSchema = ProvisioningUtil.getRefinedSchema(resource); -// ObjectClassComplexTypeDefinition objectClassDefinition = refinedSchema.determineCompositeObjectClassDefinition(shadow); -// return applyAttributesDefinition(delta, objectClassDefinition, resource, refinedSchema); -// } - + private void applyAttributesDefinition(ProvisioningContext ctx, ObjectDelta delta) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException { if (delta.isAdd()) { applyAttributesDefinition(ctx, delta.getObjectToAdd()); @@ -1588,11 +1529,9 @@ private PrismObject completeShadow(ProvisioningContext ctx, PrismObj throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, GenericConnectorException { PrismObject resultShadow = repoShadow.clone(); - boolean resultIsResourceShadowClone = false; - if (resultShadow == null) { // todo how could this happen (see above)? [mederly] - resultShadow = resourceShadow.clone(); - resultIsResourceShadowClone = true; - } + + // The real definition may be different than that of repo shadow (e.g. different auxiliary object classes). + resultShadow.applyDefinition(ctx.getObjectClassDefinition().getObjectDefinition(), true); assert resultShadow.getPrismContext() != null : "No prism context in resultShadow"; @@ -1603,6 +1542,15 @@ private PrismObject completeShadow(ProvisioningContext ctx, PrismObj ShadowType repoShadowType = repoShadow.asObjectable(); ShadowType resourceShadowType = resourceShadow.asObjectable(); + // Always take auxiliary object classes from the resource. Unlike structural object classes + // the auxiliary object classes may change. + resultShadow.removeProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS); + PrismProperty resourceAuxOcProp = resourceShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS); + if (resourceAuxOcProp != null) { + PrismProperty resultAuxOcProp = resultShadow.findOrCreateProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS); + resultAuxOcProp.addAll(PrismPropertyValue.cloneCollection(resourceAuxOcProp.getValues())); + } + if (resultShadowType.getObjectClass() == null) { resultShadowType.setObjectClass(resourceAttributesContainer.getDefinition().getTypeName()); } @@ -1614,28 +1562,23 @@ private PrismObject completeShadow(ProvisioningContext ctx, PrismObj } - // If the shadows are the same then no copy is needed. This was already copied by clone. - if (!resultIsResourceShadowClone) { - // Attributes - resultShadow.removeContainer(ShadowType.F_ATTRIBUTES); - ResourceAttributeContainer resultAttibutes = resourceAttributesContainer.clone(); - accessChecker.filterGetAttributes(resultAttibutes, ctx.getObjectClassDefinition(), parentResult); - resultShadow.add(resultAttibutes); - -// resultShadowType.setProtectedObject(resourceShadowType.isProtectedObject()); - resultShadowType.setIgnored(resourceShadowType.isIgnored()); + // Attributes + resultShadow.removeContainer(ShadowType.F_ATTRIBUTES); + ResourceAttributeContainer resultAttibutes = resourceAttributesContainer.clone(); + accessChecker.filterGetAttributes(resultAttibutes, ctx.getObjectClassDefinition(), parentResult); + resultShadow.add(resultAttibutes); + + resultShadowType.setIgnored(resourceShadowType.isIgnored()); - resultShadowType.setActivation(resourceShadowType.getActivation()); - - // Credentials - ShadowType resultAccountShadow = resultShadow.asObjectable(); - ShadowType resourceAccountShadow = resourceShadow.asObjectable(); - resultAccountShadow.setCredentials(resourceAccountShadow.getCredentials()); - } + resultShadowType.setActivation(resourceShadowType.getActivation()); + + // Credentials + ShadowType resultAccountShadow = resultShadow.asObjectable(); + ShadowType resourceAccountShadow = resourceShadow.asObjectable(); + resultAccountShadow.setCredentials(resourceAccountShadow.getCredentials()); //protected resouceObjectConverter.setProtectedFlag(ctx, resultShadow); -// resultShadowType.setProtectedObject(); // Activation ActivationType resultActivationType = resultShadowType.getActivation(); diff --git a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java index 4b02065fb3a..df845a87db4 100644 --- a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java +++ b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/ShadowManager.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; @@ -50,6 +51,7 @@ import com.evolveum.midpoint.prism.match.MatchingRule; import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.prism.polystring.PolyString; import com.evolveum.midpoint.prism.query.AndFilter; import com.evolveum.midpoint.prism.query.EqualFilter; import com.evolveum.midpoint.prism.query.ObjectFilter; @@ -809,7 +811,70 @@ public Collection updateShadow(ProvisioningContext ctx, PrismObject> oldSecondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(oldShadowType); + if (oldSecondaryIdentifiers.isEmpty()){ + return; + } + ResourceAttributeContainer newSecondaryIdentifiers = ShadowUtil.getAttributesContainer(currentShadowType); + + //remember name before normalizing attributes + PolyString currentShadowName = ShadowUtil.determineShadowName(currentShadowType); + currentShadowType.setName(new PolyStringType(currentShadowName)); + + Iterator> oldSecondaryIterator = oldSecondaryIdentifiers.iterator(); + Collection repoShadowDeltas = new ArrayList(); + while (oldSecondaryIterator.hasNext()){ + ResourceAttribute oldSecondaryIdentifier = oldSecondaryIterator.next(); + ResourceAttribute newSecondaryIdentifier = newSecondaryIdentifiers.findAttribute(oldSecondaryIdentifier.getElementName()); + Collection newValue = newSecondaryIdentifier.getRealValues(); + + if (!compareAttribute(ctx.getObjectClassDefinition(), newSecondaryIdentifier, oldSecondaryIdentifier)){ + PropertyDelta propertyDelta = PropertyDelta.createDelta(new ItemPath(ShadowType.F_ATTRIBUTES, oldSecondaryIdentifier.getElementName()), oldShadowType.asPrismObject().getDefinition()); + propertyDelta.addValuesToDelete(PrismPropertyValue.cloneCollection((Collection)oldSecondaryIdentifier.getValues())); + propertyDelta.addValuesToAdd(PrismPropertyValue.cloneCollection((Collection)newSecondaryIdentifier.getValues())); + repoShadowDeltas.add(propertyDelta); + } + + } + + if (!repoShadowDeltas.isEmpty()){ + + PropertyDelta shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, + oldShadowType.asPrismObject().getDefinition(),currentShadowName); + repoShadowDeltas.add(shadowNameDelta); + } else { + + if (!oldShadowType.getName().getOrig().equals(currentShadowType.getName().getOrig())){ + PropertyDelta shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, + oldShadowType.asPrismObject().getDefinition(), currentShadowName); + repoShadowDeltas.add(shadowNameDelta); + + } + } + + PropertyDelta auxOcDelta = PrismProperty.diff( + oldShadowType.asPrismObject().findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS), + currentShadowType.asPrismObject().findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS)); + if (auxOcDelta != null) { + repoShadowDeltas.add(auxOcDelta); + } + + if (!repoShadowDeltas.isEmpty()){ + normalizeDeltas((Collection)repoShadowDeltas, ctx.getObjectClassDefinition()); + ConstraintsChecker.onShadowModifyOperation(repoShadowDeltas); + LOGGER.trace("Modifying repository shadow {}:\n{}", oldShadowType, DebugUtil.debugDump(repoShadowDeltas)); + repositoryService.modifyObject(ShadowType.class, oldShadowType.getOid(), repoShadowDeltas, parentResult); + oldShadowType.setName(new PolyStringType(currentShadowName)); + } + + } /** * Re-reads the shadow, re-evaluates the identifiers and stored values, updates them if necessary. Returns diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestUnix.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestUnix.java index e2ea33eb526..e65d3493b75 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestUnix.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestUnix.java @@ -243,6 +243,9 @@ public class TestUnix extends AbstractStoryTest { private String accountRangerOid; private String accountRangerDn; + private String accountWallyOid; + private String accountWallyDn; + private String roleMonkeyIslandOid; private String groupMonkeyIslandDn; @@ -1169,11 +1172,11 @@ public void test310AddUserWallyUnix() throws Exception { assertNotNull("No herman user", userAfter); display("User after", userAfter); assertUserPosix(userAfter, USER_WALLY_USERNAME, USER_WALLY_FIST_NAME, USER_WALLY_LAST_NAME, USER_WALLY_UID_NUMBER); - accountMancombOid = getSingleLinkOid(userAfter); + accountWallyOid = getSingleLinkOid(userAfter); - PrismObject shadow = getShadowModel(accountMancombOid); + PrismObject shadow = getShadowModel(accountWallyOid); display("Shadow (model)", shadow); - accountMancombDn = assertPosixAccount(shadow, USER_WALLY_UID_NUMBER); + accountWallyDn = assertPosixAccount(shadow, USER_WALLY_UID_NUMBER); PrismObject sequenceAfter = getObject(SequenceType.class, SEQUENCE_UIDNUMBER_OID); display("Sequence after", sequenceAfter); @@ -1181,6 +1184,107 @@ public void test310AddUserWallyUnix() throws Exception { assertTrue("Unexpected unused values in the sequence", sequenceAfter.asObjectable().getUnusedValues().isEmpty()); } + /** + * Remove posixAccount directly in LDAP server. Then try to get the account. MidPoint should survive that. + */ + @Test + public void test312AccountWallyRemovePosixObjectclassNative() throws Exception { + final String TEST_NAME = "test312AccountWallyRemovePosixObjectclassNative"; + TestUtil.displayTestTile(this, TEST_NAME); + Task task = taskManager.createTaskInstance(TestUnix.class.getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + + openDJController.executeLdifChange("dn: "+accountWallyDn+"\n"+ + "changetype: modify\n"+ + "delete: objectclass\n"+ + "objectclass: posixAccount\n"+ + "-\n"+ + "delete: uidNumber\n"+ + "uidNumber: "+USER_WALLY_UID_NUMBER+"\n"+ + "-\n"+ + "delete: gidNumber\n"+ + "gidNumber: "+USER_WALLY_UID_NUMBER+"\n"+ + "-\n"+ + "delete: homeDirectory\n"+ + "homeDirectory: /home/wally"); + + Entry entryWallyBefore = openDJController.fetchEntry(accountWallyDn); + display("Wally LDAP account before", entryWallyBefore); + + // WHEN + TestUtil.displayWhen(TEST_NAME); + PrismObject shadow = modelService.getObject(ShadowType.class, accountWallyOid, null, task, result); + + // THEN + TestUtil.displayThen(TEST_NAME); + result.computeStatus(); + TestUtil.assertSuccess(result); + + display("Shadow (model)", shadow); + assertBasicAccount(shadow); + + PrismObject repoShadow = repositoryService.getObject(ShadowType.class, accountWallyOid, null, result); + display("Shadow (repo)", repoShadow); + PrismAsserts.assertNoItem(repoShadow, ShadowType.F_AUXILIARY_OBJECT_CLASS); +// PrismAsserts.assertPropertyValue(repoShadow, ShadowType.F_AUXILIARY_OBJECT_CLASS); + + PrismObject userAfter = findUserByUsername(USER_WALLY_USERNAME); + assertNotNull("No herman user", userAfter); + display("User after", userAfter); + assertUserPosix(userAfter, USER_WALLY_USERNAME, USER_WALLY_FIST_NAME, USER_WALLY_LAST_NAME, USER_WALLY_UID_NUMBER); + accountMancombOid = getSingleLinkOid(userAfter); + } + + /** + * Add posixAccount directly in LDAP server. Then try to get the account. MidPoint should survive that. + */ + @Test + public void test314AccountWallyAddPosixObjectclassNative() throws Exception { + final String TEST_NAME = "test314AccountWallyAddPosixObjectclassNative"; + TestUtil.displayTestTile(this, TEST_NAME); + Task task = taskManager.createTaskInstance(TestUnix.class.getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + + openDJController.executeLdifChange("dn: "+accountWallyDn+"\n"+ + "changetype: modify\n"+ + "add: objectclass\n"+ + "objectclass: posixAccount\n"+ + "-\n"+ + "add: uidNumber\n"+ + "uidNumber: "+USER_WALLY_UID_NUMBER+"\n"+ + "-\n"+ + "add: gidNumber\n"+ + "gidNumber: "+USER_WALLY_UID_NUMBER+"\n"+ + "-\n"+ + "add: homeDirectory\n"+ + "homeDirectory: /home/wally"); + + Entry entryWallyBefore = openDJController.fetchEntry(accountWallyDn); + display("Wally LDAP account before", entryWallyBefore); + + // WHEN + TestUtil.displayWhen(TEST_NAME); + PrismObject shadow = modelService.getObject(ShadowType.class, accountWallyOid, null, task, result); + + // THEN + TestUtil.displayThen(TEST_NAME); + result.computeStatus(); + TestUtil.assertSuccess(result); + + display("Shadow (model)", shadow); + assertPosixAccount(shadow, USER_WALLY_UID_NUMBER); + + PrismObject repoShadow = repositoryService.getObject(ShadowType.class, accountWallyOid, null, result); + display("Shadow (repo)", repoShadow); + PrismAsserts.assertPropertyValue(repoShadow, ShadowType.F_AUXILIARY_OBJECT_CLASS, OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME); + + PrismObject userAfter = findUserByUsername(USER_WALLY_USERNAME); + assertNotNull("No herman user", userAfter); + display("User after", userAfter); + assertUserPosix(userAfter, USER_WALLY_USERNAME, USER_WALLY_FIST_NAME, USER_WALLY_LAST_NAME, USER_WALLY_UID_NUMBER); + accountMancombOid = getSingleLinkOid(userAfter); + } + @Test public void test400ListAllAccountsObjectClass() throws Exception { final String TEST_NAME = "test400ListAllAccountsObjectClass"; From 0839797f867250e6feff791c6746a902e4b93cd5 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Tue, 15 Mar 2016 00:19:51 +0100 Subject: [PATCH 05/11] unix management configuration files --- .../unix-management/extension-unix.xsd | 59 ++++ .../unix-management/midpoint-user-example.txt | 3 + .../resource-unix-advanced.xml | 285 ++++++++++++++++++ .../role-assignment-inducement-metarole.xml | 62 ++++ 4 files changed, 409 insertions(+) create mode 100644 samples/stories/unix-management/extension-unix.xsd create mode 100644 samples/stories/unix-management/midpoint-user-example.txt create mode 100644 samples/stories/unix-management/resource-unix-advanced.xml create mode 100644 samples/stories/unix-management/role-assignment-inducement-metarole.xml diff --git a/samples/stories/unix-management/extension-unix.xsd b/samples/stories/unix-management/extension-unix.xsd new file mode 100644 index 00000000000..0da66e9bc63 --- /dev/null +++ b/samples/stories/unix-management/extension-unix.xsd @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + true + Group Name + + + + + + + false + Unix Permissions + + + + + + + + + + + + + + + + + + + false + Public Key + + + + + + + + diff --git a/samples/stories/unix-management/midpoint-user-example.txt b/samples/stories/unix-management/midpoint-user-example.txt new file mode 100644 index 00000000000..3b7a599a3d1 --- /dev/null +++ b/samples/stories/unix-management/midpoint-user-example.txt @@ -0,0 +1,3 @@ +Host_Alias HOST = ALL + +midpoint HOST=(ALL) NOPASSWD: /usr/sbin/useradd,/usr/sbin/usermod,/usr/sbin/userdel,/usr/sbin/groupadd,/usr/sbin/groupmod,/usr/sbin/groupdel,/bin/mv,/usr/bin/passwd,/usr/bin/getent,/bin/echo,/usr/bin/tee,/bin/chown,/bin/chmod,/bin/mkdir,/usr/bin/groups,/usr/bin/id,/usr/bin/replace,/bin/rm,/bin/cat \ No newline at end of file diff --git a/samples/stories/unix-management/resource-unix-advanced.xml b/samples/stories/unix-management/resource-unix-advanced.xml new file mode 100644 index 00000000000..449d5fbf430 --- /dev/null +++ b/samples/stories/unix-management/resource-unix-advanced.xml @@ -0,0 +1,285 @@ + + Unix Resource + + + + connectorType + org.connid.bundles.unix.UnixConnector + + + + + + false + + + midpoint + + secret + + 192.168.56.101 + 22 + true + true + $ + false + true + 0 + + secret + + 10000 + + + + + + entitlement + unixGroup + UNIX Group + ri:GroupObjectClass + + icfs:name + mr:stringIgnoreCase + + + + account + Normal Account + true + ri:AccountObjectClass + + icfs:name + Distinguished Name + + 0 + + true + true + true + + + + + name + + + + + icfs:uid + Entry UUID + + + true + false + true + + + + + ri:comment + Comment + + + fullName + + + + + ri:homeDir + Home directory + + + name + + + + + + + + ri:uid + Unix UID + + + employeeNumber + + + + + ri:publicKey + Public Key + + + publicKeys + extension/ext:publicKey + + + + + + + + ri:shell + Shell + + + /bin/bash + + + + + ri:unixGroup + LDAP Group Membership + entitlement + unixGroup + subjectToObject + ri:groups + icfs:name + + + midpoint + + + root + + + + + + + + + + + + + + + + + + + + + + + + 2016-03-14T22:45:57.550+01:00 + 1141db340df1573e-621c56a87c47c088 + + + + + + + + + + + false + + + + + + + + + + connector + + + + + + + ri:AccountObjectClass + account + UserType + true + + + name + + $shadow/attributes/icfs:name + + + + + linked + true + + + unlinked + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#link + + + + unmatched + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus + + + + + ri:GroupObjectClass + entitlement + unixGroup + OrgType + true + + + name + + $shadow/attributes/icfs:name + + + + + linked + true + + + unlinked + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#link + + + + + \ No newline at end of file diff --git a/samples/stories/unix-management/role-assignment-inducement-metarole.xml b/samples/stories/unix-management/role-assignment-inducement-metarole.xml new file mode 100644 index 00000000000..b04d9fa7af6 --- /dev/null +++ b/samples/stories/unix-management/role-assignment-inducement-metarole.xml @@ -0,0 +1,62 @@ + + Assignemnt & Inducement UNIX Group Metarole + Create group in the unix, assign this group to the user when role with this metarole is assigned. + + + + + entitlement + unixGroup + + icfs:name + mr:stringIgnoreCase + + + groupName + extension/ext:groupName + + + + + ri:permissions + + + permissions + extension/ext:permissions + + + + + + + + + account + default + + ri:unixGroup + + strong + + + + entitlement + unixGroup + + + + + + + 2 + UserType + + \ No newline at end of file From e5b07203b83ec27d523cb6ee809aec4bcd35b950 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Tue, 15 Mar 2016 00:25:03 +0100 Subject: [PATCH 06/11] unix resource configuration example --- .../resources/unix/midpoint-user-example.txt | 3 + .../resources/unix/resource-unix-advanced.xml | 271 ++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 samples/resources/unix/midpoint-user-example.txt create mode 100644 samples/resources/unix/resource-unix-advanced.xml diff --git a/samples/resources/unix/midpoint-user-example.txt b/samples/resources/unix/midpoint-user-example.txt new file mode 100644 index 00000000000..3b7a599a3d1 --- /dev/null +++ b/samples/resources/unix/midpoint-user-example.txt @@ -0,0 +1,3 @@ +Host_Alias HOST = ALL + +midpoint HOST=(ALL) NOPASSWD: /usr/sbin/useradd,/usr/sbin/usermod,/usr/sbin/userdel,/usr/sbin/groupadd,/usr/sbin/groupmod,/usr/sbin/groupdel,/bin/mv,/usr/bin/passwd,/usr/bin/getent,/bin/echo,/usr/bin/tee,/bin/chown,/bin/chmod,/bin/mkdir,/usr/bin/groups,/usr/bin/id,/usr/bin/replace,/bin/rm,/bin/cat \ No newline at end of file diff --git a/samples/resources/unix/resource-unix-advanced.xml b/samples/resources/unix/resource-unix-advanced.xml new file mode 100644 index 00000000000..b0c74fa6109 --- /dev/null +++ b/samples/resources/unix/resource-unix-advanced.xml @@ -0,0 +1,271 @@ + + Unix Resource + + + + connectorType + org.connid.bundles.unix.UnixConnector + + + + + + false + + + midpoint + + secret + + localhost + 22 + true + true + $ + false + true + 0 + + secret + + 10000 + + + + + + entitlement + unixGroup + UNIX Group + ri:GroupObjectClass + + icfs:name + mr:stringIgnoreCase + + + name + + + + + + + account + Normal Account + true + ri:AccountObjectClass + + icfs:name + Distinguished Name + + 0 + + true + true + true + + + + + $user/name + + + + + icfs:uid + Entry UUID + + + true + false + true + + + + + ri:comment + Comment + + + fullName + + + + + ri:homeDir + Home directory + + + name + + + + + + + + ri:uid + Unix UID + + + employeeNumber + + + + + ri:shell + Shell + + + /bin/bash + + + + + ri:unixGroup + LDAP Group Membership + entitlement + unixGroup + subjectToObject + ri:groups + icfs:name + + + midpoint + + + root + + + + + + + + + + + + + + + + + + + + + + + + 2016-01-08T10:55:09.834+01:00 + 9daad27c2782934a-6fb5c4a527e3b230 + + + + + + + + + + + false + + + + + + + + + + connector + + + + + + + ri:AccountObjectClass + account + UserType + true + + + name + + $shadow/attributes/icfs:name + + + + + linked + true + + + deleted + false + + + unlinked + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#link + + + + unmatched + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#addFocus + + + + + ri:GroupObjectClass + entitlement + unixGroup + OrgType + true + + + name + + $shadow/attributes/icfs:name + + + + + linked + true + + + deleted + false + + + unlinked + true + + http://midpoint.evolveum.com/xml/ns/public/model/action-3#link + + + + + + From 1201747182202209569044c6ff520874eec3c551 Mon Sep 17 00:00:00 2001 From: honchar Date: Tue, 15 Mar 2016 10:06:08 +0100 Subject: [PATCH 07/11] refactoring using ConfirmationDialog to main popup from PageBase with ConfirmationPanel as a body --- .../midpoint/gui/api/page/PageBase.java | 14 +- .../assignment/AssignmentTablePanel.html | 1 - .../assignment/AssignmentTablePanel.java | 53 ++--- .../objectdetails/AbstractObjectTabPanel.java | 4 +- .../certification/PageCertCampaigns.html | 6 - .../certification/PageCertCampaigns.java | 186 +++++++++--------- 6 files changed, 137 insertions(+), 127 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java index a07aaf1154d..9fefcd4d35b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java @@ -553,11 +553,17 @@ public void showMainPopup(AjaxRequestTarget target) { getMainPopup().show(target); } - public void hideMainPopup(AjaxRequestTarget target) { - getMainPopup().close(target); - } + public void showMainPopup(Component body, IModel title, AjaxRequestTarget target) { + setMainPopupContent(body); + setMainPopupTitle(title); + showMainPopup(target); + } + + public void hideMainPopup(AjaxRequestTarget target) { + getMainPopup().close(target); + } - private VisibleEnableBehaviour createUserStatusBehaviour(final boolean visibleIfLoggedIn) { + private VisibleEnableBehaviour createUserStatusBehaviour(final boolean visibleIfLoggedIn) { return new VisibleEnableBehaviour() { @Override diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.html index 38a69b95673..64fb8b609b2 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.html @@ -19,7 +19,6 @@
-
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.java index a22c66c4299..47f90b45174 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssignmentTablePanel.java @@ -34,6 +34,7 @@ import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.web.component.dialog.ConfirmationDialog; +import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; import com.evolveum.midpoint.web.component.menu.cog.InlineMenu; import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem; import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction; @@ -41,6 +42,7 @@ import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus; import com.evolveum.midpoint.xml.ns._public.common.common_3.*; +import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox; import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; @@ -77,8 +79,6 @@ public class AssignmentTablePanel extends BasePanel getUserDefinition() { }; AssignableSelectionPage.prepareDialog(assignWindow, assignableSelectionContext, this, "AssignmentTablePanel.modal.title.selectAssignment", ID_ASSIGNMENTS); add(assignWindow); - - ModalWindow deleteDialog = new ConfirmationDialog(ID_MODAL_DELETE_ASSIGNMENT, - createStringResource("AssignmentTablePanel.modal.title.confirmDeletion"), - new AbstractReadOnlyModel() { - - @Override - public String getObject() { - return createStringResource("AssignmentTablePanel.modal.message.delete", - getSelectedAssignments().size()).getString(); - } - }) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - deleteAssignmentConfirmedPerformed(target, getSelectedAssignments()); - } - }; - add(deleteDialog); } private List createAssignmentMenu() { @@ -329,7 +310,11 @@ private void showModalWindow(String id, AjaxRequestTarget target) { window.show(target); } - private void showAssignablePopupPerformed(AjaxRequestTarget target, Class type, + protected void showModalWindow(Component body, IModel title, AjaxRequestTarget target) { + getPageBase().showMainPopup(body, title, target); + } + + private void showAssignablePopupPerformed(AjaxRequestTarget target, Class type, QName searchParameter) { assignableSelectionContext.setType(type); assignableSelectionContext.setSearchParameter(searchParameter); @@ -350,9 +335,31 @@ private void deleteAssignmentPerformed(AjaxRequestTarget target) { return; } - showModalWindow(ID_MODAL_DELETE_ASSIGNMENT, target); + showModalWindow(getDeleteAssignmentPopupContent(), createStringResource("AssignmentTablePanel.modal.title.confirmDeletion"), target); } + private Component getDeleteAssignmentPopupContent(){ + return new ConfirmationPanel(getPageBase().getMainPopupBodyId(), + new AbstractReadOnlyModel() { + + @Override + public String getObject() { + return createStringResource("AssignmentTablePanel.modal.message.delete", + getSelectedAssignments().size()).getString(); + } + }) { + + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + deleteAssignmentConfirmedPerformed(target, getSelectedAssignments()); + } + } + }; + } + private void deleteAssignmentConfirmedPerformed(AjaxRequestTarget target, List toDelete) { List assignments = getAssignmentModel().getObject(); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectTabPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectTabPanel.java index d301578cef6..91eeaec0100 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectTabPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/objectdetails/AbstractObjectTabPanel.java @@ -138,9 +138,7 @@ protected void showModalWindow(String id, AjaxRequestTarget target) { } protected void showModalWindow(Component body, IModel title, AjaxRequestTarget target) { - getPageBase().setMainPopupContent(body); - getPageBase().setMainPopupTitle(title); - getPageBase().showMainPopup(target); + getPageBase().showMainPopup(body, title, target); target.add(getFeedbackPanel()); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.html index 040e6acdc79..d3a1a501aec 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.html @@ -20,12 +20,6 @@ -
-
-
-
-
-
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.java index 94cbe766b47..0d298e5612b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertCampaigns.java @@ -50,6 +50,7 @@ import com.evolveum.midpoint.web.component.data.column.LinkColumn; import com.evolveum.midpoint.web.component.data.column.SingleButtonColumn; import com.evolveum.midpoint.web.component.dialog.ConfirmationDialog; +import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem; import com.evolveum.midpoint.web.component.util.Selectable; import com.evolveum.midpoint.web.page.admin.certification.dto.CertCampaignListItemDto; @@ -120,11 +121,6 @@ public class PageCertCampaigns extends PageAdminCertification { public static final String OP_CLOSE_STAGE = "PageCertCampaigns.button.closeStage"; public static final String OP_OPEN_NEXT_STAGE = "PageCertCampaigns.button.openNextStage"; public static final String OP_START_REMEDIATION = "PageCertCampaigns.button.startRemediation"; - private static final String DIALOG_CONFIRM_CLOSE_STAGE = "confirmCloseStagePopup"; - private static final String DIALOG_CONFIRM_DELETE_CAMPAIGN ="confirmDeleteCampaignPopup"; - private static final String DIALOG_CONFIRM_DELETE_MULTIPLE_CAMPAIGNS = "confirmDeleteMultipleCampaignsPopup"; - private static final String DIALOG_CONFIRM_CLOSE_CAMPAIGN ="confirmCloseCampaignPopup"; - private static final String DIALOG_CONFIRM_CLOSE_MULTIPLE_CAMPAIGNS ="confirmCloseMultipleCampaignsPopup"; // campaign on which close-stage/close-campaign/delete has to be executed (if chosen directly from row menu) private CertCampaignListItemDto relevantCampaign; @@ -213,66 +209,6 @@ private void initLayout() { Form mainForm = new Form(ID_MAIN_FORM); add(mainForm); - add(new ConfirmationDialog( - DIALOG_CONFIRM_CLOSE_STAGE, - createStringResource("PageCertCampaigns.dialog.title.confirmCloseStage"), - createCloseStageConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - closeStageConfirmedPerformed(target, relevantCampaign); - } - }); - - add(new ConfirmationDialog( - DIALOG_CONFIRM_CLOSE_CAMPAIGN, - createStringResource("PageCertCampaigns.dialog.title.confirmCloseCampaign"), - createCloseCampaignConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - closeCampaignConfirmedPerformed(target, relevantCampaign); - } - }); - - add(new ConfirmationDialog( - DIALOG_CONFIRM_CLOSE_MULTIPLE_CAMPAIGNS, - createStringResource("PageCertCampaigns.dialog.title.confirmCloseCampaign"), - createCloseSelectedCampaignsConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - closeSelectedCampaignsConfirmedPerformed(target); - } - }); - - add(new ConfirmationDialog( - DIALOG_CONFIRM_DELETE_CAMPAIGN, - createStringResource("PageCertCampaigns.dialog.title.confirmDeleteCampaign"), - createDeleteCampaignConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - deleteCampaignConfirmedPerformed(target); - } - }); - - add(new ConfirmationDialog( - DIALOG_CONFIRM_DELETE_MULTIPLE_CAMPAIGNS, - createStringResource("PageCertCampaigns.dialog.title.confirmDeleteCampaign"), - createDeleteSelectedCampaignsConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - deleteSelectedCampaignsConfirmedPerformed(target); - } - }); - CertCampaignListItemDtoProvider provider = createProvider(); int itemsPerPage = (int) getItemsPerPage(UserProfileStorage.TableId.PAGE_CERT_CAMPAIGNS_PANEL); BoxedTablePanel table = new BoxedTablePanel<>( @@ -574,20 +510,48 @@ private void closeSelectedCampaignsConfirmation(AjaxRequestTarget target) { if (!ensureSomethingIsSelected(target)) { return; } - ModalWindow dialog = (ModalWindow) get(DIALOG_CONFIRM_CLOSE_MULTIPLE_CAMPAIGNS); - dialog.show(target); - } - - private void deleteSelectedCampaignsConfirmation(AjaxRequestTarget target) { + showMainPopup(getCloseSelectedCampaignsConfirmationPanel(), createStringResource("PageCertCampaigns.dialog.title.confirmCloseCampaign"), + target); + } + + private Component getCloseSelectedCampaignsConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createCloseSelectedCampaignsConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + closeSelectedCampaignsConfirmedPerformed(target); + } + } + }; + } + + private void deleteSelectedCampaignsConfirmation(AjaxRequestTarget target) { this.relevantCampaign = null; if (!ensureSomethingIsSelected(target)) { return; } - ModalWindow dialog = (ModalWindow) get(DIALOG_CONFIRM_DELETE_MULTIPLE_CAMPAIGNS); - dialog.show(target); - } - - private boolean ensureSomethingIsSelected(AjaxRequestTarget target) { + showMainPopup(getDeleteSelectedCampaignsConfirmationPanel(), createStringResource("PageCertCampaigns.dialog.title.confirmDeleteCampaign"), + target); + } + + private Component getDeleteSelectedCampaignsConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createDeleteSelectedCampaignsConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + deleteSelectedCampaignsConfirmedPerformed(target); + } + } + }; + } + + private boolean ensureSomethingIsSelected(AjaxRequestTarget target) { if (relevantCampaign != null) { return true; } else if (!WebComponentUtil.getSelectedData(getTable()).isEmpty()) { @@ -603,23 +567,65 @@ private boolean ensureSomethingIsSelected(AjaxRequestTarget target) { private void closeStageConfirmation(AjaxRequestTarget target, CertCampaignListItemDto campaignDto) { this.relevantCampaign = campaignDto; - ModalWindow dialog = (ModalWindow) get(DIALOG_CONFIRM_CLOSE_STAGE); - dialog.show(target); - } - - private void closeCampaignConfirmation(AjaxRequestTarget target, CertCampaignListItemDto campaignDto) { + showMainPopup(getCloseStageConfirmationPanel(), createStringResource("PageCertCampaigns.dialog.title.confirmCloseStage"), + target); + } + + private Component getCloseStageConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createCloseStageConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + closeStageConfirmedPerformed(target, relevantCampaign); + } + } + }; + } + + private void closeCampaignConfirmation(AjaxRequestTarget target, CertCampaignListItemDto campaignDto) { this.relevantCampaign = campaignDto; - ModalWindow dialog = (ModalWindow) get(DIALOG_CONFIRM_CLOSE_CAMPAIGN); - dialog.show(target); - } - - private void deleteCampaignConfirmation(AjaxRequestTarget target, CertCampaignListItemDto campaignDto) { + showMainPopup(getCloseCampaignConfirmationPanel(), createStringResource("PageCertCampaigns.dialog.title.confirmCloseCampaign"), + target); + } + + private Component getCloseCampaignConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createCloseCampaignConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + closeCampaignConfirmedPerformed(target, relevantCampaign); + } + } + }; + } + + private void deleteCampaignConfirmation(AjaxRequestTarget target, CertCampaignListItemDto campaignDto) { this.relevantCampaign = campaignDto; - ModalWindow dialog = (ModalWindow) get(DIALOG_CONFIRM_DELETE_CAMPAIGN); - dialog.show(target); - } - - // actions after confirmation (single and multiple versions mixed) + showMainPopup(getDeleteCampaignConfirmationPanel(), createStringResource("PageCertCampaigns.dialog.title.confirmDeleteCampaign"), + target); + } + + private Component getDeleteCampaignConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createDeleteCampaignConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + deleteCampaignConfirmedPerformed(target); + } + } + }; + } + + // actions after confirmation (single and multiple versions mixed) private void deleteCampaignConfirmedPerformed(AjaxRequestTarget target) { deleteCampaignsPerformed(target, Arrays.asList(relevantCampaign)); From 3b6282d16c7e7a61a33367d2cf7342bba362448d Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Tue, 15 Mar 2016 11:29:18 +0100 Subject: [PATCH 08/11] fixing test initialization - GUI --- .../src/test/resources/ctx-admin-gui-test-main.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml b/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml index c255b2ff20b..5743e9504df 100644 --- a/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml +++ b/gui/admin-gui/src/test/resources/ctx-admin-gui-test-main.xml @@ -39,7 +39,7 @@ - - - + + + \ No newline at end of file From df11ac1079abf269f4131f08347d0a580c5fe494 Mon Sep 17 00:00:00 2001 From: honchar Date: Tue, 15 Mar 2016 12:08:27 +0100 Subject: [PATCH 09/11] more refactoring: ConfirmationDialog is replaced with main popup from PageBase with ConfirmationPanel as a body --- .../certification/PageCertDefinitions.html | 2 - .../certification/PageCertDefinitions.java | 29 ++++--- .../admin/configuration/PageDebugList.html | 1 - .../admin/configuration/PageDebugList.java | 76 ++++++++++--------- .../localization/Midpoint.properties | 2 +- .../localization/Midpoint_en_US.properties | 2 +- 6 files changed, 58 insertions(+), 54 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.html index e4dd15db490..2425ef844cb 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.html @@ -18,8 +18,6 @@ -
-
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.java index de76d7aac1f..75b21a85043 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/certification/PageCertDefinitions.java @@ -35,6 +35,7 @@ import com.evolveum.midpoint.web.component.data.column.LinkColumn; import com.evolveum.midpoint.web.component.data.column.MultiButtonColumn; import com.evolveum.midpoint.web.component.dialog.ConfirmationDialog; +import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; import com.evolveum.midpoint.web.component.util.SelectableBean; import com.evolveum.midpoint.web.page.admin.configuration.PageDebugView; import com.evolveum.midpoint.web.page.admin.workflow.PageAdminWorkItems; @@ -77,7 +78,6 @@ public class PageCertDefinitions extends PageAdminWorkItems { private static final String DOT_CLASS = PageCertDefinitions.class.getName() + "."; private static final String OPERATION_CREATE_CAMPAIGN = DOT_CLASS + "createCampaign"; private static final String OPERATION_DELETE_DEFINITION = DOT_CLASS + "deleteDefinition"; - private static final String DIALOG_CONFIRM_DELETE = "confirmDeletePopup"; private static final String ID_MAIN_FORM = "mainForm"; private static final String ID_DEFINITIONS_TABLE = "definitionsTable"; @@ -114,15 +114,6 @@ private void initLayout() { ObjectDataProvider provider = createProvider(); - add(new ConfirmationDialog(DIALOG_CONFIRM_DELETE, - createStringResource("PageCertDefinitions.title.confirmDelete"), createDeleteConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - deleteDefinitionPerformed(target, singleDelete); - } - }); int itemsPerPage = (int) getItemsPerPage(UserProfileStorage.TableId.PAGE_CERT_DEFINITIONS_PANEL); BoxedTablePanel table = new BoxedTablePanel<>(ID_DEFINITIONS_TABLE, provider, initColumns(), UserProfileStorage.TableId.PAGE_CERT_DEFINITIONS_PANEL, itemsPerPage); @@ -244,8 +235,8 @@ private void createCampaignPerformed(AjaxRequestTarget target, AccessCertificati private void deleteConfirmation(AjaxRequestTarget target, AccessCertificationDefinitionType definition) { this.singleDelete = definition; - ModalWindow dialog = (ModalWindow) get(DIALOG_CONFIRM_DELETE); - dialog.show(target); + showMainPopup(getDeleteDefinitionConfirmationPanel(), createStringResource("PageCertDefinitions.title.confirmDelete"), + target); } private void deleteDefinitionPerformed(AjaxRequestTarget target, AccessCertificationDefinitionType definition) { @@ -288,4 +279,18 @@ private void definitionDetailsPerformed(AjaxRequestTarget target, String oid) { } //endregion + + private Component getDeleteDefinitionConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createDeleteConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + deleteDefinitionPerformed(target, singleDelete); + } + } + }; + } } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.html index c3f95a560a0..be4f5d9a35d 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.html @@ -18,7 +18,6 @@ -
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.java index b31f56c31b2..11278f9c57b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageDebugList.java @@ -23,6 +23,7 @@ import javax.xml.namespace.QName; +import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; import org.apache.commons.lang.StringUtils; import org.apache.wicket.AttributeModifier; import org.apache.wicket.Component; @@ -173,7 +174,6 @@ public class PageDebugList extends PageAdminConfiguration { private static final String OPERATION_LOAD_RESOURCES = DOT_CLASS + "loadResources"; private static final String OPERATION_DELETE_SHADOWS = DOT_CLASS + "deleteShadows"; - private static final String ID_CONFIRM_DELETE_POPUP = "confirmDeletePopup"; private static final String ID_MAIN_FORM = "mainForm"; private static final String ID_ZIP_CHECK = "zipCheck"; private static final String ID_TABLE = "table"; @@ -268,35 +268,6 @@ public void yesPerformed(AjaxRequestTarget target) { }; add(deleteAllDialog); - ConfirmationDialog deleteConfirm = new ConfirmationDialog(ID_CONFIRM_DELETE_POPUP, - createStringResource("pageDebugList.dialog.title.confirmDelete"), - createDeleteConfirmString()) { - - @Override - public void yesPerformed(AjaxRequestTarget target) { - close(target); - - DebugConfDialogDto dto = confDialogModel.getObject(); - switch (dto.getOperation()) { - case DELETE_ALL_TYPE: - deleteAllTypeConfirmed(target); - break; - case DELETE_SELECTED: - deleteSelectedConfirmed(target, dto.getObjects()); - break; - case DELETE_RESOURCE_SHADOWS: - deleteAllShadowsOnResourceConfirmed(target); - break; - } - } - - @Override - public boolean getLabelEscapeModelStrings() { - return false; - } - }; - add(deleteConfirm); - Form main = new Form(ID_MAIN_FORM); add(main); @@ -715,8 +686,8 @@ private void deleteAllType(AjaxRequestTarget target) { searchDto.getType().getClassDefinition()); confDialogModel.setObject(dto); - ModalWindow dialog = (ModalWindow) get(ID_CONFIRM_DELETE_POPUP); - dialog.show(target); + showMainPopup(getDeleteConfirmationPanel(), createStringResource("pageDebugList.dialog.title.confirmDelete"), + target); } private List getSelectedData(AjaxRequestTarget target, DebugObjectItem item) { @@ -747,8 +718,8 @@ private void deleteSelected(AjaxRequestTarget target, DebugObjectItem item) { selected, searchDto.getType().getClassDefinition()); confDialogModel.setObject(dto); - ModalWindow dialog = (ModalWindow) get(ID_CONFIRM_DELETE_POPUP); - dialog.show(target); + showMainPopup(getDeleteConfirmationPanel(), createStringResource("pageDebugList.dialog.title.confirmDelete"), + target); } private void deleteAllIdentities(AjaxRequestTarget target) { @@ -824,11 +795,42 @@ private void deleteAllShadowsOnResource(AjaxRequestTarget target) { DebugConfDialogDto.Operation.DELETE_RESOURCE_SHADOWS, null, null); confDialogModel.setObject(dialogDto); - ModalWindow dialog = (ModalWindow) get(ID_CONFIRM_DELETE_POPUP); - dialog.show(target); + showMainPopup(getDeleteConfirmationPanel(), createStringResource("pageDebugList.dialog.title.confirmDelete"), + target); } - private void deleteAllShadowsOnResourceConfirmed(AjaxRequestTarget target) { + + private Component getDeleteConfirmationPanel() { + return new ConfirmationPanel(getMainPopupBodyId(), + createDeleteConfirmString()) { + @Override + public void yesPerformed(AjaxRequestTarget target) { + ModalWindow modalWindow = findParent(ModalWindow.class); + if (modalWindow != null) { + modalWindow.close(target); + DebugConfDialogDto dto = confDialogModel.getObject(); + switch (dto.getOperation()) { + case DELETE_ALL_TYPE: + deleteAllTypeConfirmed(target); + break; + case DELETE_SELECTED: + deleteSelectedConfirmed(target, dto.getObjects()); + break; + case DELETE_RESOURCE_SHADOWS: + deleteAllShadowsOnResourceConfirmed(target); + break; + } + } + } + + @Override + public boolean getLabelEscapeModelStrings() { + return false; + } + }; + } + + private void deleteAllShadowsOnResourceConfirmed(AjaxRequestTarget target) { DebugSearchDto dto = searchModel.getObject(); String resourceOid = dto.getResource().getOid(); diff --git a/gui/admin-gui/src/main/resources/localization/Midpoint.properties b/gui/admin-gui/src/main/resources/localization/Midpoint.properties index e9783ac7b1a..afddfa0eb33 100644 --- a/gui/admin-gui/src/main/resources/localization/Midpoint.properties +++ b/gui/admin-gui/src/main/resources/localization/Midpoint.properties @@ -1535,7 +1535,7 @@ pageDebugList.message.singleOrgDeleteProblem=Couldn't delete org. unit pageDebugList.message.singleShadowDeleteProblem=Couldn't delete shadow pageDebugList.message.singleUserDeleteProblem=Couldn't delete user pageDebugList.messsage.deleteAllOfType=Deleting objects of type {0}. -pageDebugList.messsage.deleteAllResourceShadows=Do your really want to delete all shadows on resource {0}? +pageDebugList.messsage.deleteAllResourceShadows=Do you really want to delete all shadows on resource {0}? pageDebugList.messsage.deleteAllShadowsStarted=Task which deletes all shadows on resource {0} was started. pageDebugList.name=Name pageDebugList.oid=Oid diff --git a/gui/admin-gui/src/main/resources/localization/Midpoint_en_US.properties b/gui/admin-gui/src/main/resources/localization/Midpoint_en_US.properties index dc1d0ba87b9..811933d94c0 100644 --- a/gui/admin-gui/src/main/resources/localization/Midpoint_en_US.properties +++ b/gui/admin-gui/src/main/resources/localization/Midpoint_en_US.properties @@ -1505,7 +1505,7 @@ pageDebugList.message.singleOrgDeleteProblem=Couldn't delete org. unit pageDebugList.message.singleShadowDeleteProblem=Couldn't delete shadow pageDebugList.message.singleUserDeleteProblem=Couldn't delete user pageDebugList.messsage.deleteAllOfType=Deleting objects of type {0}. -pageDebugList.messsage.deleteAllResourceShadows=Do your really want to delete all shadows on resource {0}? +pageDebugList.messsage.deleteAllResourceShadows=Do you really want to delete all shadows on resource {0}? pageDebugList.messsage.deleteAllShadowsStarted=Task which deletes all shadows on resource {0} was started. pageDebugList.name=Name pageDebugList.oid=Oid From cc7dd65323e5877c3f13535aa2ab744e2c1cad14 Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Tue, 15 Mar 2016 13:23:13 +0100 Subject: [PATCH 10/11] fixing displaying feedback panel on import page and page users --- .../midpoint/gui/api/page/PageBase.java | 1 + .../admin/configuration/PageImportObject.java | 467 +++++++++--------- .../web/page/admin/users/PageUsers.java | 7 +- 3 files changed, 238 insertions(+), 237 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java index 9fefcd4d35b..6f8b21c7538 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/page/PageBase.java @@ -704,6 +704,7 @@ public void showResult(OperationResult result, String errorMessageKey, boolean s } + protected String createComponentPath(String... components) { return StringUtils.join(components, ":"); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageImportObject.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageImportObject.java index e80bf3d2ca3..e51c401fc9b 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageImportObject.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/configuration/PageImportObject.java @@ -52,245 +52,250 @@ import org.apache.wicket.util.file.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; /** * @author lazyman * @author mserbak */ @PageDescriptor(url = "/admin/config/import", action = { - @AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL, - label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION), - @AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CONFIGURATION_IMPORT_URL, - label = "PageImportObject.auth.configImport.label", description = "PageImportObject.auth.configImport.description")}) + @AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL, label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION), + @AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CONFIGURATION_IMPORT_URL, label = "PageImportObject.auth.configImport.label", description = "PageImportObject.auth.configImport.description") }) public class PageImportObject extends PageAdminConfiguration { - private static final Trace LOGGER = TraceManager.getTrace(PageImportObject.class); - private static final String DOT_CLASS = PageImportObject.class.getName() + "."; - private static final String OPERATION_IMPORT_FILE = DOT_CLASS + "importFile"; - private static final String OPERATION_IMPORT_XML = DOT_CLASS + "importXml"; - - private static final String ID_MAIN_FORM = "mainForm"; - private static final String ID_BUTTON_BAR = "buttonBar"; - private static final String ID_IMPORT_OPTIONS = "importOptions"; - private static final String ID_IMPORT_RADIO_GROUP = "importRadioGroup"; - private static final String ID_FILE_RADIO = "fileRadio"; - private static final String ID_XML_RADIO = "xmlRadio"; - private static final String ID_IMPORT_FILE_BUTTON = "importFileButton"; - private static final String ID_IMPORT_XML_BUTTON = "importXmlButton"; - private static final String ID_INPUT = "input"; - private static final String ID_INPUT_ACE = "inputAce"; - private static final String ID_ACE_EDITOR = "aceEditor"; - private static final String ID_INPUT_FILE_LABEL = "inputFileLabel"; - private static final String ID_INPUT_FILE = "inputFile"; - private static final String ID_FILE_INPUT = "fileInput"; - - private static final Integer INPUT_FILE = 1; - private static final Integer INPUT_XML = 2; - - private LoadableModel model; - private IModel xmlEditorModel; - - public PageImportObject() { - model = new LoadableModel(false) { - - @Override - protected ImportOptionsType load() { - return MiscSchemaUtil.getDefaultImportOptions(); - } - }; - xmlEditorModel = new Model(null); - - initLayout(); - } - - private void initLayout() { - Form mainForm = new Form(ID_MAIN_FORM); - add(mainForm); - - ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, model); - mainForm.add(importOptions); - - final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT); - input.setOutputMarkupId(true); - mainForm.add(input); - - final WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR); - buttonBar.setOutputMarkupId(true); - mainForm.add(buttonBar); - - final IModel groupModel = new Model(INPUT_FILE); - RadioGroup importRadioGroup = new RadioGroup(ID_IMPORT_RADIO_GROUP, groupModel); - importRadioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() { - - @Override - protected void onUpdate(AjaxRequestTarget target) { - target.add(input); - target.add(buttonBar); - } - }); - mainForm.add(importRadioGroup); - - Radio fileRadio = new Radio(ID_FILE_RADIO, new Model(INPUT_FILE), importRadioGroup); - importRadioGroup.add(fileRadio); - - Radio xmlRadio = new Radio(ID_XML_RADIO, new Model(INPUT_XML), importRadioGroup); - importRadioGroup.add(xmlRadio); - - WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE); - addVisibileForInputType(inputAce, INPUT_XML, groupModel); - input.add(inputAce); - - AceEditor aceEditor = new AceEditor(ID_ACE_EDITOR, xmlEditorModel); - aceEditor.setOutputMarkupId(true); - inputAce.add(aceEditor); - - WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL); - addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel); - input.add(inputFileLabel); - - WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE); - addVisibileForInputType(inputFile, INPUT_FILE, groupModel); - input.add(inputFile); - - FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT); - inputFile.add(fileInput); - - initButtons(buttonBar, groupModel); - } - - private void addVisibileForInputType(Component comp, final Integer type, final IModel groupModel) { - comp.add(new VisibleEnableBehaviour() { - - @Override - public boolean isVisible() { - return type.equals(groupModel.getObject()); - } - - }); - } - - private void initButtons(WebMarkupContainer buttonBar, IModel inputType) { - AjaxSubmitButton saveFileButton = new AjaxSubmitButton(ID_IMPORT_FILE_BUTTON, - createStringResource("PageImportObject.button.import")) { - - @Override - protected void onSubmit(AjaxRequestTarget target, Form form) { - saveFilePerformed(target); - } - - @Override - protected void onError(AjaxRequestTarget target, Form form) { - target.add(getFeedbackPanel()); - } - }; - addVisibileForInputType(saveFileButton, INPUT_FILE, inputType); - buttonBar.add(saveFileButton); - - AjaxSubmitButton saveXmlButton = new AjaxSubmitButton(ID_IMPORT_XML_BUTTON, - createStringResource("PageImportObject.button.import")) { - - @Override - protected void onSubmit(AjaxRequestTarget target, Form form) { - saveXmlPerformed(target); - } - - @Override - protected void onError(AjaxRequestTarget target, Form form) { - target.add(getFeedbackPanel()); - } - }; - addVisibileForInputType(saveXmlButton, INPUT_XML, inputType); - buttonBar.add(saveXmlButton); - } - - private void saveFilePerformed(AjaxRequestTarget target) { - OperationResult result = new OperationResult(OPERATION_IMPORT_FILE); - - FileUploadField file = (FileUploadField) get(createComponentPath(ID_MAIN_FORM, ID_INPUT, ID_INPUT_FILE, ID_FILE_INPUT)); - final FileUpload uploadedFile = file.getFileUpload(); - if (uploadedFile == null) { - error(getString("pageImportObject.message.nullFile")); - target.add(getFeedbackPanel()); - - return; - } - - InputStream stream = null; - File newFile = null; - try { - // Create new file - MidPointApplication application = getMidpointApplication(); - WebApplicationConfiguration config = application.getWebApplicationConfiguration(); - File folder = new File(config.getImportFolder()); - if (!folder.exists() || !folder.isDirectory()) { - folder.mkdir(); - } - - newFile = new File(folder, uploadedFile.getClientFileName()); - // Check new file, delete if it already exists - if (newFile.exists()) { - newFile.delete(); - } - // Save file - Task task = createSimpleTask(OPERATION_IMPORT_FILE); - newFile.createNewFile(); - uploadedFile.writeTo(newFile); - - InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8"); - stream = new ReaderInputStream(reader, reader.getEncoding()); - getModelService().importObjectsFromStream(stream, model.getObject(), task, result); - - result.recomputeStatus(); - } catch (Exception ex) { - result.recordFatalError("Couldn't import file.", ex); - LoggingUtils.logException(LOGGER, "Couldn't import file", ex); - } finally { - if (stream != null) { - IOUtils.closeQuietly(stream); - } - if (newFile != null) { - FileUtils.deleteQuietly(newFile); - } - } - - showResult(result); - target.add(getFeedbackPanel()); - } - - private void saveXmlPerformed(AjaxRequestTarget target) { - String xml = xmlEditorModel.getObject(); - if (StringUtils.isEmpty(xml)) { - error(getString("pageImportObject.message.emptyXml")); - target.add(getFeedbackPanel()); - - return; - } - - OperationResult result = new OperationResult(OPERATION_IMPORT_XML); - InputStream stream = null; - try { - Task task = createSimpleTask(OPERATION_IMPORT_XML); - - stream = IOUtils.toInputStream(xml, "utf-8"); - getModelService().importObjectsFromStream(stream, model.getObject(), task, result); - - result.recomputeStatus(); - } catch (Exception ex) { - result.recordFatalError("Couldn't import object.", ex); - LoggingUtils.logException(LOGGER, "Error occured during xml import", ex); - } finally { - if (stream != null) { - IOUtils.closeQuietly(stream); - } - } - - if (result.isSuccess()) { - xmlEditorModel.setObject(null); - } - - showResult(result); - target.add(getFeedbackPanel()); - } + private static final Trace LOGGER = TraceManager.getTrace(PageImportObject.class); + private static final String DOT_CLASS = PageImportObject.class.getName() + "."; + private static final String OPERATION_IMPORT_FILE = DOT_CLASS + "importFile"; + private static final String OPERATION_IMPORT_XML = DOT_CLASS + "importXml"; + + private static final String ID_MAIN_FORM = "mainForm"; + private static final String ID_BUTTON_BAR = "buttonBar"; + private static final String ID_IMPORT_OPTIONS = "importOptions"; + private static final String ID_IMPORT_RADIO_GROUP = "importRadioGroup"; + private static final String ID_FILE_RADIO = "fileRadio"; + private static final String ID_XML_RADIO = "xmlRadio"; + private static final String ID_IMPORT_FILE_BUTTON = "importFileButton"; + private static final String ID_IMPORT_XML_BUTTON = "importXmlButton"; + private static final String ID_INPUT = "input"; + private static final String ID_INPUT_ACE = "inputAce"; + private static final String ID_ACE_EDITOR = "aceEditor"; + private static final String ID_INPUT_FILE_LABEL = "inputFileLabel"; + private static final String ID_INPUT_FILE = "inputFile"; + private static final String ID_FILE_INPUT = "fileInput"; + + private static final Integer INPUT_FILE = 1; + private static final Integer INPUT_XML = 2; + + private LoadableModel model; + private IModel xmlEditorModel; + + public PageImportObject() { + model = new LoadableModel(false) { + + @Override + protected ImportOptionsType load() { + return MiscSchemaUtil.getDefaultImportOptions(); + } + }; + xmlEditorModel = new Model(null); + + initLayout(); + } + + private void initLayout() { + Form mainForm = new Form(ID_MAIN_FORM); + add(mainForm); + + ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, model); + mainForm.add(importOptions); + + final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT); + input.setOutputMarkupId(true); + mainForm.add(input); + + final WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR); + buttonBar.setOutputMarkupId(true); + mainForm.add(buttonBar); + + final IModel groupModel = new Model(INPUT_FILE); + RadioGroup importRadioGroup = new RadioGroup(ID_IMPORT_RADIO_GROUP, groupModel); + importRadioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() { + + @Override + protected void onUpdate(AjaxRequestTarget target) { + target.add(input); + target.add(buttonBar); + } + }); + mainForm.add(importRadioGroup); + + Radio fileRadio = new Radio(ID_FILE_RADIO, new Model(INPUT_FILE), importRadioGroup); + importRadioGroup.add(fileRadio); + + Radio xmlRadio = new Radio(ID_XML_RADIO, new Model(INPUT_XML), importRadioGroup); + importRadioGroup.add(xmlRadio); + + WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE); + addVisibileForInputType(inputAce, INPUT_XML, groupModel); + input.add(inputAce); + + AceEditor aceEditor = new AceEditor(ID_ACE_EDITOR, xmlEditorModel); + aceEditor.setOutputMarkupId(true); + inputAce.add(aceEditor); + + WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL); + addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel); + input.add(inputFileLabel); + + WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE); + addVisibileForInputType(inputFile, INPUT_FILE, groupModel); + input.add(inputFile); + + FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT); + inputFile.add(fileInput); + + initButtons(buttonBar, groupModel); + } + + private void addVisibileForInputType(Component comp, final Integer type, + final IModel groupModel) { + comp.add(new VisibleEnableBehaviour() { + + @Override + public boolean isVisible() { + return type.equals(groupModel.getObject()); + } + + }); + } + + private void initButtons(WebMarkupContainer buttonBar, IModel inputType) { + AjaxSubmitButton saveFileButton = new AjaxSubmitButton(ID_IMPORT_FILE_BUTTON, + createStringResource("PageImportObject.button.import")) { + + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + savePerformed(false, OPERATION_IMPORT_FILE, target); + } + + @Override + protected void onError(AjaxRequestTarget target, Form form) { + target.add(getFeedbackPanel()); + } + }; + addVisibileForInputType(saveFileButton, INPUT_FILE, inputType); + buttonBar.add(saveFileButton); + + AjaxSubmitButton saveXmlButton = new AjaxSubmitButton(ID_IMPORT_XML_BUTTON, + createStringResource("PageImportObject.button.import")) { + + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + savePerformed(true, OPERATION_IMPORT_XML, target); + } + + @Override + protected void onError(AjaxRequestTarget target, Form form) { + target.add(getFeedbackPanel()); + } + }; + addVisibileForInputType(saveXmlButton, INPUT_XML, inputType); + buttonBar.add(saveXmlButton); + } + + private FileUpload getUploadedFile() { + FileUploadField file = (FileUploadField) get( + createComponentPath(ID_MAIN_FORM, ID_INPUT, ID_INPUT_FILE, ID_FILE_INPUT)); + return file.getFileUpload(); + } + + private boolean validateInput(boolean raw) { + if (raw) { + return StringUtils.isNotEmpty(xmlEditorModel.getObject()); + } + return getUploadedFile() != null; + + } + + private InputStream getInputStream(boolean raw) throws Exception { + if (raw) { + return IOUtils.toInputStream(xmlEditorModel.getObject(), "utf-8"); + } + File newFile = null; + try { + // Create new file + MidPointApplication application = getMidpointApplication(); + WebApplicationConfiguration config = application.getWebApplicationConfiguration(); + File folder = new File(config.getImportFolder()); + if (!folder.exists() || !folder.isDirectory()) { + folder.mkdir(); + } + + FileUpload uploadedFile = getUploadedFile(); + newFile = new File(folder, uploadedFile.getClientFileName()); + // Check new file, delete if it already exists + if (newFile.exists()) { + newFile.delete(); + } + // Save file + + newFile.createNewFile(); + uploadedFile.writeTo(newFile); + + InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8"); + return new ReaderInputStream(reader, reader.getEncoding()); + } finally { + if (newFile != null) { + FileUtils.deleteQuietly(newFile); + } + } + } + + private void clearOldFeedback(){ + getSession().getFeedbackMessages().clear(); + getFeedbackMessages().clear(); + } + + private void savePerformed(boolean raw, String operationName, AjaxRequestTarget target) { + clearOldFeedback(); + + OperationResult result = new OperationResult(operationName); + + if (!validateInput(raw)) { + error(getString("pageImportObject.message.nullFile")); + target.add(getFeedbackPanel()); + + return; + } + InputStream stream = null; + + try { + Task task = createSimpleTask(operationName); + stream = getInputStream(raw); + getModelService().importObjectsFromStream(stream, model.getObject(), task, result); + + result.recomputeStatus(); + } catch (Exception ex) { + result.recordFatalError("Couldn't import file.", ex); + LoggingUtils.logException(LOGGER, "Couldn't import file", ex); + } finally { + if (stream != null) { + IOUtils.closeQuietly(stream); + } + + } + + if (result.isSuccess()) { + xmlEditorModel.setObject(null); + } + + showResult(result); + target.add(getFeedbackPanel()); + } + + } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUsers.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUsers.java index 1350b6ae5da..209f0120793 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUsers.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/users/PageUsers.java @@ -126,11 +126,7 @@ public PageUsers() { public PageUsers(boolean clearPagingInSession) { this(clearPagingInSession, null, null); } - @Override - protected void onBeforeRender() { - // TODO Auto-generated method stub - super.onBeforeRender(); - } + public PageUsers(boolean clearPagingInSession, final UsersDto.SearchType type, final String text) { searchModel = new LoadableModel(false) { @@ -156,7 +152,6 @@ protected ExecuteChangeOptionsDto load() { }; getSessionStorage().clearPagingInSession(clearPagingInSession); - add(getFeedbackPanel()); initLayout(); } From b8c023cc99dc5cf21a47721b983f5a5d6bab9946 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Tue, 15 Mar 2016 14:35:02 +0100 Subject: [PATCH 11/11] Displaying auxiliary object class attributes in GUI (MID-2718) --- .../ModelInteractionServiceImpl.java | 17 ++-------- .../midpoint/testing/story/TestUnix.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ModelInteractionServiceImpl.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ModelInteractionServiceImpl.java index 9d8de7f6a9b..739b0a1df67 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ModelInteractionServiceImpl.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ModelInteractionServiceImpl.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; +import com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinition; import com.evolveum.midpoint.common.refinery.LayerRefinedAttributeDefinition; import com.evolveum.midpoint.common.refinery.LayerRefinedObjectClassDefinition; import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition; @@ -267,21 +268,7 @@ public RefinedObjectClassDefinition getEditObjectClassDefinition(PrismObject shadow = getShadowModel(accountMancombOid); + display("shadow", shadow); + + // WHEN + TestUtil.displayWhen(TEST_NAME); + RefinedObjectClassDefinition editObjectClassDefinition = modelInteractionService.getEditObjectClassDefinition(shadow, resourceOpenDj, AuthorizationPhaseType.REQUEST); + + // THEN + TestUtil.displayThen(TEST_NAME); + result.computeStatus(); + TestUtil.assertSuccess(result); + display("OC def", editObjectClassDefinition); + + PrismAsserts.assertPropertyDefinition(editObjectClassDefinition, + new QName(RESOURCE_OPENDJ_NAMESPACE, "cn"), DOMUtil.XSD_STRING, 1, -1); + PrismAsserts.assertPropertyDefinition(editObjectClassDefinition, + new QName(RESOURCE_OPENDJ_NAMESPACE, "o"), DOMUtil.XSD_STRING, 0, -1); + PrismAsserts.assertPropertyDefinition(editObjectClassDefinition, + new QName(RESOURCE_OPENDJ_NAMESPACE, "uidNumber"), DOMUtil.XSD_INT, 1, 1); + PrismAsserts.assertPropertyDefinition(editObjectClassDefinition, + new QName(RESOURCE_OPENDJ_NAMESPACE, "gidNumber"), DOMUtil.XSD_INT, 1, 1); + } + @Test public void test119DeleteUserMancombUnix() throws Exception { final String TEST_NAME = "test119DeleteUserMancombUnix";