http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/DisplayAttributesModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/DisplayAttributesModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/DisplayAttributesModalPage.java new file mode 100644 index 0000000..6f89ec3 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/DisplayAttributesModalPage.java @@ -0,0 +1,273 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.PreferenceManager; +import org.apache.syncope.common.lib.search.SearchableFields; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Check; +import org.apache.wicket.markup.html.form.CheckGroup; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; +import org.apache.wicket.markup.html.panel.Fragment; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.LoadableDetachableModel; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.spring.injection.annot.SpringBean; + +/** + * Modal window with Display attributes form. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class DisplayAttributesModalPage extends BaseModalPage { + + private static final long serialVersionUID = -4274117450918385110L; + + /** + * Max allowed selections. + */ + private static final int MAX_SELECTIONS = 9; + + public static final String[] DEFAULT_SELECTION = { "key", "username", "status" }; + + @SpringBean + private PreferenceManager prefMan; + + private final List<String> selectedDetails; + + private final List<String> selectedPlainSchemas; + + private final List<String> selectedDerSchemas; + + private final List<String> selectedVirSchemas; + + public DisplayAttributesModalPage(final PageReference pageRef, final ModalWindow window, + final List<String> schemaNames, final List<String> dSchemaNames, final List<String> vSchemaNames) { + + super(); + + final IModel<List<String>> fnames = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return SearchableFields.get(UserTO.class); + } + }; + + final IModel<List<String>> names = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return schemaNames; + } + }; + + final IModel<List<String>> dsnames = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return dSchemaNames; + } + }; + + final IModel<List<String>> vsnames = new LoadableDetachableModel<List<String>>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected List<String> load() { + return vSchemaNames; + } + }; + + final Form form = new Form(FORM); + form.setModel(new CompoundPropertyModel(this)); + + selectedDetails = prefMan.getList(getRequest(), Constants.PREF_USERS_DETAILS_VIEW); + + selectedPlainSchemas = prefMan.getList(getRequest(), Constants.PREF_USERS_ATTRIBUTES_VIEW); + + selectedDerSchemas = prefMan.getList(getRequest(), Constants.PREF_USERS_DERIVED_ATTRIBUTES_VIEW); + + selectedVirSchemas = prefMan.getList(getRequest(), Constants.PREF_USERS_VIRTUAL_ATTRIBUTES_VIEW); + + final CheckGroup dgroup = new CheckGroup("dCheckGroup", new PropertyModel(this, "selectedDetails")); + form.add(dgroup); + + final ListView<String> details = new ListView<String>("details", fnames) { + + private static final long serialVersionUID = 9101744072914090143L; + + @Override + protected void populateItem(final ListItem<String> item) { + item.add(new Check("dcheck", item.getModel())); + item.add(new Label("dname", new ResourceModel(item.getModelObject(), item.getModelObject()))); + } + }; + dgroup.add(details); + + if (names.getObject() == null || names.getObject().isEmpty()) { + final Fragment fragment = new Fragment("plainSchemas", "emptyFragment", form); + form.add(fragment); + + selectedPlainSchemas.clear(); + } else { + final Fragment fragment = new Fragment("plainSchemas", "sfragment", form); + form.add(fragment); + + final CheckGroup sgroup = new CheckGroup("psCheckGroup", new PropertyModel(this, "selectedPlainSchemas")); + fragment.add(sgroup); + + final ListView<String> schemas = new ListView<String>("plainSchemas", names) { + + private static final long serialVersionUID = 9101744072914090143L; + + @Override + protected void populateItem(final ListItem<String> item) { + item.add(new Check("scheck", item.getModel())); + item.add(new Label("sname", new ResourceModel(item.getModelObject(), item.getModelObject()))); + } + }; + sgroup.add(schemas); + } + + if (dsnames.getObject() == null || dsnames.getObject().isEmpty()) { + final Fragment fragment = new Fragment("dschemas", "emptyFragment", form); + form.add(fragment); + + selectedDerSchemas.clear(); + } else { + final Fragment fragment = new Fragment("dschemas", "dsfragment", form); + form.add(fragment); + + final CheckGroup dsgroup = new CheckGroup("dsCheckGroup", new PropertyModel(this, "selectedDerSchemas")); + fragment.add(dsgroup); + + final ListView<String> derSchemas = new ListView<String>("derSchemas", dsnames) { + + private static final long serialVersionUID = 9101744072914090143L; + + @Override + protected void populateItem(ListItem<String> item) { + item.add(new Check("dscheck", item.getModel())); + item.add(new Label("dsname", new ResourceModel(item.getModelObject(), item.getModelObject()))); + } + }; + dsgroup.add(derSchemas); + } + + if (vsnames.getObject() == null || vsnames.getObject().isEmpty()) { + final Fragment fragment = new Fragment("vschemas", "emptyFragment", form); + form.add(fragment); + + selectedVirSchemas.clear(); + } else { + final Fragment fragment = new Fragment("vschemas", "vsfragment", form); + form.add(fragment); + + final CheckGroup vsgroup = new CheckGroup("vsCheckGroup", new PropertyModel(this, "selectedVirSchemas")); + fragment.add(vsgroup); + + final ListView<String> virSchemas = new ListView<String>("virSchemas", vsnames) { + + private static final long serialVersionUID = 9101744072914090143L; + + @Override + protected void populateItem(ListItem<String> item) { + item.add(new Check("vscheck", item.getModel())); + item.add(new Label("vsname", new ResourceModel(item.getModelObject(), item.getModelObject()))); + } + }; + vsgroup.add(virSchemas); + } + + final AjaxButton submit = new IndicatingAjaxButton(SUBMIT, new ResourceModel(SUBMIT)) { + + private static final long serialVersionUID = -4804368561204623354L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + if (selectedDetails.size() + selectedPlainSchemas.size() + selectedVirSchemas.size() + selectedDerSchemas. + size() + > MAX_SELECTIONS) { + + error(getString("tooManySelections")); + onError(target, form); + } else { + final Map<String, List<String>> prefs = new HashMap<String, List<String>>(); + + prefs.put(Constants.PREF_USERS_DETAILS_VIEW, selectedDetails); + + prefs.put(Constants.PREF_USERS_ATTRIBUTES_VIEW, selectedPlainSchemas); + + prefs.put(Constants.PREF_USERS_DERIVED_ATTRIBUTES_VIEW, selectedDerSchemas); + + prefs.put(Constants.PREF_USERS_VIRTUAL_ATTRIBUTES_VIEW, selectedVirSchemas); + + prefMan.setList(getRequest(), getResponse(), prefs); + + ((BasePage) pageRef.getPage()).setModalResult(true); + + window.close(target); + } + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + feedbackPanel.refresh(target); + } + }; + + form.add(submit); + + final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + window.close(target); + } + }; + + cancel.setDefaultFormProcessing(false); + form.add(cancel); + + add(form); + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/EditUserModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/EditUserModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/EditUserModalPage.java new file mode 100644 index 0000000..af502d2 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/EditUserModalPage.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import java.util.ArrayList; +import org.apache.commons.lang3.SerializationUtils; +import org.apache.syncope.client.console.commons.Mode; +import org.apache.syncope.client.console.commons.status.StatusBean; +import org.apache.syncope.client.console.panels.AccountInformationPanel; +import org.apache.syncope.client.console.panels.MembershipsPanel; +import org.apache.syncope.client.console.panels.ResourcesPanel; +import org.apache.syncope.client.console.panels.StatusPanel; +import org.apache.syncope.common.lib.AttributableOperations; +import org.apache.syncope.common.lib.mod.UserMod; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.ResourceModel; + +/** + * Modal window with User form. + */ +public class EditUserModalPage extends UserModalPage { + + private static final long serialVersionUID = -6479209496805705739L; + + protected Form form; + + private final UserTO initialUserTO; + + private StatusPanel statusPanel; + + public EditUserModalPage(final PageReference pageRef, final ModalWindow window, final UserTO userTO) { + super(pageRef, window, userTO, Mode.ADMIN, true); + + this.initialUserTO = SerializationUtils.clone(userTO); + + form = setupEditPanel(); + + // add resource assignment details in case of update + if (userTO.getKey() != 0) { + form.addOrReplace(new Label("pwdChangeInfo", new ResourceModel("pwdChangeInfo"))); + + statusPanel = new StatusPanel("statuspanel", userTO, new ArrayList<StatusBean>(), getPageReference()); + statusPanel.setOutputMarkupId(true); + MetaDataRoleAuthorizationStrategy.authorize( + statusPanel, RENDER, xmlRolesReader.getEntitlement("Resources", "getConnectorObject")); + form.addOrReplace(statusPanel); + + form.addOrReplace(new AccountInformationPanel("accountinformation", userTO)); + + form.addOrReplace(new ResourcesPanel.Builder("resources").attributableTO(userTO). + statusPanel(statusPanel).build()); + + form.addOrReplace(new MembershipsPanel("memberships", userTO, mode, statusPanel, getPageReference())); + } + } + + @SuppressWarnings("rawtypes") + @Override + protected void submitAction(final AjaxRequestTarget target, final Form form) { + final UserTO updatedUserTO = (UserTO) form.getModelObject(); + + if (updatedUserTO.getKey() == 0) { + userTO = userRestClient.create(updatedUserTO, storePassword.getModelObject()); + } else { + final UserMod userMod = AttributableOperations.diff(updatedUserTO, initialUserTO); + + if (statusPanel != null) { + userMod.setPwdPropRequest(statusPanel.getStatusMod()); + } + + // update user just if it is changed + if (!userMod.isEmpty()) { + userTO = userRestClient.update(initialUserTO.getETagValue(), userMod); + } + } + } + + @SuppressWarnings("rawtypes") + @Override + protected void closeAction(final AjaxRequestTarget target, final Form form) { + setResponsePage(new ResultStatusModalPage.Builder(window, userTO).mode(mode).build()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/ErrorPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/ErrorPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/ErrorPage.java new file mode 100644 index 0000000..db46171 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/ErrorPage.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.wicket.Page; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.mapper.parameter.PageParameters; + +/** + * Error WebPage. + */ +public class ErrorPage extends BasePage { + + private static final long serialVersionUID = -390761262038796657L; + + public ErrorPage(final PageParameters parameters) { + super(parameters); + + add(new Label("errorTitle", new Model<String>(parameters.get("errorTitle").toString()))); + add(new Label("errorMessage", new Model<String>(parameters.get("errorMessage").toString()))); + + add(new BookmarkablePageLink<Page>("home", getApplication().getHomePage())); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/ExecMessageModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/ExecMessageModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/ExecMessageModalPage.java new file mode 100644 index 0000000..e39f3fc --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/ExecMessageModalPage.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.model.Model; + +public class ExecMessageModalPage extends BaseModalPage { + + private static final long serialVersionUID = 3163146190501510888L; + + public ExecMessageModalPage(final String message) { + final Label dialogContent = new Label("message", new Model<String>(message)); + add(dialogContent.setOutputMarkupId(true)); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/FailureMessageModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/FailureMessageModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/FailureMessageModalPage.java new file mode 100644 index 0000000..c0ee7ec --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/FailureMessageModalPage.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.model.Model; + +public class FailureMessageModalPage extends BaseModalPage { + + private static final long serialVersionUID = 9216117990503199258L; + + public FailureMessageModalPage(final String message, final String failureMessage) { + final Label executionFailureMessage; + if (!failureMessage.isEmpty()) { + executionFailureMessage = new Label("failureMessage", new Model<String>(failureMessage)); + } else { + executionFailureMessage = new Label("failureMessage"); + } + add(executionFailureMessage.setOutputMarkupId(true)); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/HomePage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/HomePage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/HomePage.java new file mode 100644 index 0000000..7b4ba68 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/HomePage.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.wicket.request.mapper.parameter.PageParameters; + +/** + * Syncope Home-Page. + */ +public class HomePage extends BasePage { + + private static final long serialVersionUID = -6712990478380766293L; + + public HomePage(final PageParameters parameters) { + super(parameters); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/InfoModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/InfoModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/InfoModalPage.java new file mode 100644 index 0000000..83e0163 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/InfoModalPage.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.syncope.client.console.SyncopeSession; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.ExternalLink; +import org.apache.wicket.spring.injection.annot.SpringBean; + +public class InfoModalPage extends BaseModalPage { + + private static final long serialVersionUID = 5558354927844399580L; + + @SpringBean(name = "site") + private String siteUrl; + + @SpringBean(name = "license") + private String licenseUrl; + + public InfoModalPage() { + super(); + + add(new ExternalLink("syncopeLink", siteUrl)); + add(new ExternalLink("licenseLink", licenseUrl)); + add(new Label("version", SyncopeSession.get().getVersion())); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java new file mode 100644 index 0000000..deaa359 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import java.security.AccessControlException; +import java.util.List; +import java.util.Locale; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.SyncopeSession; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.panels.NotificationPanel; +import org.apache.syncope.client.console.rest.UserSelfRestClient; +import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxLink; +import org.apache.syncope.client.console.wicket.markup.html.form.LinkPanel; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.wrap.EntitlementTO; +import org.apache.syncope.common.rest.api.CollectionWrapper; +import org.apache.syncope.common.rest.api.service.EntitlementService; +import org.apache.wicket.Component; +import org.apache.wicket.Page; +import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.JavaScriptHeaderItem; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.PasswordTextField; +import org.apache.wicket.markup.html.form.StatelessForm; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.panel.Fragment; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.request.cycle.RequestCycle; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; + +/** + * Syncope Login page. + */ +public class Login extends WebPage { + + private static final long serialVersionUID = -3744389270366566218L; + + private final static int SELF_REG_WIN_HEIGHT = 550; + + private final static int SELF_REG_WIN_WIDTH = 800; + + private final static int PWD_RESET_WIN_HEIGHT = 300; + + private final static int PWD_RESET_WIN_WIDTH = 800; + + @SpringBean(name = "version") + private String version; + + @SpringBean(name = "anonymousUser") + private String anonymousUser; + + @SpringBean(name = "anonymousKey") + private String anonymousKey; + + @SpringBean + private UserSelfRestClient userSelfRestClient; + + private final StatelessForm<Void> form; + + private final TextField<String> userIdField; + + private final TextField<String> passwordField; + + private final DropDownChoice<Locale> languageSelect; + + private final NotificationPanel feedbackPanel; + + public Login(final PageParameters parameters) { + super(parameters); + setStatelessHint(true); + + feedbackPanel = new NotificationPanel(Constants.FEEDBACK); + add(feedbackPanel); + + form = new StatelessForm<Void>("login"); + + userIdField = new TextField<String>("userId", new Model<String>()); + userIdField.setMarkupId("userId"); + form.add(userIdField); + + passwordField = new PasswordTextField("password", new Model<String>()); + passwordField.setMarkupId("password"); + form.add(passwordField); + + languageSelect = new LocaleDropDown("language"); + + form.add(languageSelect); + + AjaxButton submitButton = new AjaxButton("submit", new Model<String>(getString("submit"))) { + + private static final long serialVersionUID = 429178684321093953L; + + @Override + protected void onSubmit(AjaxRequestTarget target, Form<?> form) { + try { + if (anonymousUser.equals(userIdField.getRawInput())) { + throw new AccessControlException("Illegal username"); + } + + authenticate(userIdField.getRawInput(), passwordField.getRawInput()); + + setResponsePage(WelcomePage.class, parameters); + } catch (AccessControlException e) { + error(getString("login-error")); + feedbackPanel.refresh(target); + SyncopeSession.get().resetClients(); + } + } + }; + + submitButton.setDefaultFormProcessing(false); + form.add(submitButton); + + add(form); + + // Modal window for self registration + final ModalWindow selfRegModalWin = new ModalWindow("selfRegModal"); + selfRegModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + selfRegModalWin.setInitialHeight(SELF_REG_WIN_HEIGHT); + selfRegModalWin.setInitialWidth(SELF_REG_WIN_WIDTH); + selfRegModalWin.setCookieName("self-reg-modal"); + add(selfRegModalWin); + + Fragment selfRegFrag; + if (userSelfRestClient.isSelfRegistrationAllowed()) { + selfRegFrag = new Fragment("selfRegistration", "selfRegAllowed", this); + + final AjaxLink<Void> selfRegLink = new ClearIndicatingAjaxLink<Void>("link", getPageReference()) { + + private static final long serialVersionUID = -7978723352517770644L; + + @Override + protected void onClickInternal(final AjaxRequestTarget target) { + selfRegModalWin.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @Override + public Page createPage() { + // anonymous authentication needed for self-registration + authenticate(anonymousUser, anonymousKey); + + return new UserSelfModalPage(Login.this.getPageReference(), selfRegModalWin, new UserTO()); + } + }); + + selfRegModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 251794406325329768L; + + @Override + public void onClose(final AjaxRequestTarget target) { + SyncopeSession.get().invalidate(); + } + }); + + selfRegModalWin.show(target); + } + }; + selfRegLink.add(new Label("linkTitle", getString("selfRegistration"))); + + Panel panel = new LinkPanel("selfRegistration", new ResourceModel("selfRegistration")); + panel.add(selfRegLink); + selfRegFrag.add(panel); + } else { + selfRegFrag = new Fragment("selfRegistration", "selfRegNotAllowed", this); + } + add(selfRegFrag); + + // Modal window for password reset request + final ModalWindow pwdResetReqModalWin = new ModalWindow("pwdResetReqModal"); + pwdResetReqModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + pwdResetReqModalWin.setInitialHeight(PWD_RESET_WIN_HEIGHT); + pwdResetReqModalWin.setInitialWidth(PWD_RESET_WIN_WIDTH); + pwdResetReqModalWin.setCookieName("pwd-reset-req-modal"); + add(pwdResetReqModalWin); + + Fragment pwdResetFrag; + if (userSelfRestClient.isPasswordResetAllowed()) { + pwdResetFrag = new Fragment("passwordReset", "pwdResetAllowed", this); + + final AjaxLink<Void> pwdResetLink = new ClearIndicatingAjaxLink<Void>("link", getPageReference()) { + + private static final long serialVersionUID = -6957616042924610290L; + + @Override + protected void onClickInternal(final AjaxRequestTarget target) { + pwdResetReqModalWin.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @Override + public Page createPage() { + // anonymous authentication needed for password reset request + authenticate(anonymousUser, anonymousKey); + + return new RequestPasswordResetModalPage(pwdResetReqModalWin); + } + }); + + pwdResetReqModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 8804221891699487139L; + + @Override + public void onClose(final AjaxRequestTarget target) { + SyncopeSession.get().invalidate(); + setResponsePage(Login.class); + } + }); + + pwdResetReqModalWin.show(target); + } + }; + pwdResetLink.add(new Label("linkTitle", getString("passwordReset"))); + + Panel panel = new LinkPanel("passwordReset", new ResourceModel("passwordReset")); + panel.add(pwdResetLink); + pwdResetFrag.add(panel); + } else { + pwdResetFrag = new Fragment("passwordReset", "pwdResetNotAllowed", this); + } + add(pwdResetFrag); + + // Modal window for password reset confirm - automatically shown when token is available as request parameter + final String pwdResetToken = RequestCycle.get().getRequest().getRequestParameters(). + getParameterValue(Constants.PARAM_PASSWORD_RESET_TOKEN).toOptionalString(); + final ModalWindow pwdResetConfModalWin = new ModalWindow("pwdResetConfModal"); + if (StringUtils.isNotBlank(pwdResetToken)) { + pwdResetConfModalWin.add(new AbstractDefaultAjaxBehavior() { + + private static final long serialVersionUID = 3109256773218160485L; + + @Override + protected void respond(final AjaxRequestTarget target) { + ModalWindow window = (ModalWindow) getComponent(); + window.show(target); + } + + @Override + public void renderHead(final Component component, final IHeaderResponse response) { + response.render(JavaScriptHeaderItem.forScript(getCallbackScript(), null)); + } + }); + } + pwdResetConfModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + pwdResetConfModalWin.setInitialHeight(PWD_RESET_WIN_HEIGHT); + pwdResetConfModalWin.setInitialWidth(PWD_RESET_WIN_WIDTH); + pwdResetConfModalWin.setCookieName("pwd-reset-conf-modal"); + pwdResetConfModalWin.setPageCreator(new ModalWindow.PageCreator() { + + private static final long serialVersionUID = -7834632442532690940L; + + @Override + public Page createPage() { + // anonymous authentication needed for password reset confirm + authenticate(anonymousUser, anonymousKey); + + return new ConfirmPasswordResetModalPage(pwdResetConfModalWin, pwdResetToken); + } + }); + pwdResetConfModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { + + private static final long serialVersionUID = 8804221891699487139L; + + @Override + public void onClose(final AjaxRequestTarget target) { + SyncopeSession.get().invalidate(); + setResponsePage(Login.class); + } + }); + add(pwdResetConfModalWin); + } + + private void authenticate(final String username, final String password) { + List<EntitlementTO> entitlements = SyncopeSession.get(). + getService(EntitlementService.class, username, password).getOwnEntitlements(); + + SyncopeSession.get().setUsername(username); + SyncopeSession.get().setPassword(password); + SyncopeSession.get().setEntitlements(CollectionWrapper.unwrap(entitlements).toArray(new String[0])); + SyncopeSession.get().setVersion(version); + } + + /** + * Inner class which implements (custom) Locale DropDownChoice component. + */ + private class LocaleDropDown extends DropDownChoice<Locale> { + + private static final long serialVersionUID = 2349382679992357202L; + + private class LocaleRenderer extends ChoiceRenderer<Locale> { + + private static final long serialVersionUID = -3657529581555164741L; + + @Override + public String getDisplayValue(final Locale locale) { + return locale.getDisplayName(getLocale()); + } + } + + public LocaleDropDown(final String id) { + super(id, SyncopeSession.SUPPORTED_LOCALES); + + setChoiceRenderer(new LocaleRenderer()); + setModel(new IModel<Locale>() { + + private static final long serialVersionUID = -6985170095629312963L; + + @Override + public Locale getObject() { + return getSession().getLocale(); + } + + @Override + public void setObject(final Locale object) { + getSession().setLocale(object); + } + + @Override + public void detach() { + // Empty. + } + }); + + // set default value to English + getModel().setObject(Locale.ENGLISH); + } + + @Override + protected boolean wantOnSelectionChangedNotifications() { + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/Logout.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/Logout.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/Logout.java new file mode 100644 index 0000000..acf313b --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/Logout.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.syncope.client.console.SyncopeSession; +import org.apache.wicket.request.mapper.parameter.PageParameters; + +/** + * Syncope Logout. + */ +public class Logout extends BasePage { + + private static final long serialVersionUID = -2143007520243939450L; + + public Logout(final PageParameters parameters) { + super(parameters); + + SyncopeSession.get().invalidate(); + + setResponsePage(getApplication().getHomePage()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/MembershipModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/MembershipModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/MembershipModalPage.java new file mode 100644 index 0000000..f2e2189 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/MembershipModalPage.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import org.apache.syncope.client.console.commons.Mode; +import org.apache.syncope.client.console.panels.AnnotatedBeanPanel; +import org.apache.syncope.client.console.panels.DerAttrsPanel; +import org.apache.syncope.client.console.panels.PlainAttrsPanel; +import org.apache.syncope.client.console.panels.VirAttrsPanel; +import org.apache.syncope.common.lib.to.MembershipTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.ResourceModel; + +public class MembershipModalPage extends BaseModalPage { + + private static final long serialVersionUID = -4360802478081432549L; + + private final AjaxButton submit; + + public MembershipModalPage(final PageReference pageRef, final ModalWindow window, final MembershipTO membershipTO, + final Mode mode) { + + final Form<MembershipTO> form = new Form<MembershipTO>("MembershipForm"); + + final UserTO userTO = ((UserModalPage) pageRef.getPage()).getUserTO(); + + form.setModel(new CompoundPropertyModel<MembershipTO>(membershipTO)); + + submit = new AjaxButton(SUBMIT, new ResourceModel(SUBMIT)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form form) { + userTO.getMemberships().remove(membershipTO); + userTO.getMemberships().add(membershipTO); + + ((UserModalPage) pageRef.getPage()).setUserTO(userTO); + + window.close(target); + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + feedbackPanel.refresh(target); + } + }; + + form.add(submit); + form.setDefaultButton(submit); + + final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + ((UserModalPage) pageRef.getPage()).setUserTO(userTO); + window.close(target); + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + } + }; + + cancel.setDefaultFormProcessing(false); + form.add(cancel); + + //-------------------------------- + // Attributes panel + //-------------------------------- + form.add(new PlainAttrsPanel("plainAttrs", membershipTO, form, mode)); + form.add(new AnnotatedBeanPanel("systeminformation", membershipTO)); + //-------------------------------- + + //-------------------------------- + // Derived attributes container + //-------------------------------- + form.add(new DerAttrsPanel("derAttrs", membershipTO)); + //-------------------------------- + + //-------------------------------- + // Virtual attributes container + //-------------------------------- + form.add(new VirAttrsPanel("virAttrs", membershipTO, mode == Mode.TEMPLATE)); + //-------------------------------- + + add(form); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationModalPage.java new file mode 100644 index 0000000..782c907 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationModalPage.java @@ -0,0 +1,441 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.panels.LoggerCategoryPanel; +import org.apache.syncope.client.console.panels.RoleSearchPanel; +import org.apache.syncope.client.console.panels.UserSearchPanel; +import org.apache.syncope.client.console.rest.LoggerRestClient; +import org.apache.syncope.client.console.rest.NotificationRestClient; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; +import org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.NotificationTO; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.IntMappingType; +import org.apache.syncope.common.lib.types.TraceLevel; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; +import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.validation.validator.EmailAddressValidator; + +class NotificationModalPage extends BaseModalPage { + + private static final long serialVersionUID = -1975312550059578553L; + + @SpringBean + private NotificationRestClient restClient; + + @SpringBean + private LoggerRestClient loggerRestClient; + + public NotificationModalPage(final PageReference pageRef, final ModalWindow window, + final NotificationTO notificationTO, final boolean createFlag) { + + final Form<NotificationTO> form = + new Form<NotificationTO>(FORM, new CompoundPropertyModel<NotificationTO>(notificationTO)); + + final AjaxTextFieldPanel sender = new AjaxTextFieldPanel("sender", getString("sender"), + new PropertyModel<String>(notificationTO, "sender")); + sender.addRequiredLabel(); + sender.addValidator(EmailAddressValidator.getInstance()); + form.add(sender); + + final AjaxTextFieldPanel subject = new AjaxTextFieldPanel("subject", getString("subject"), + new PropertyModel<String>(notificationTO, "subject")); + subject.addRequiredLabel(); + form.add(subject); + + final AjaxDropDownChoicePanel<String> template = new AjaxDropDownChoicePanel<String>( + "template", getString("template"), + new PropertyModel<String>(notificationTO, "template")); + template.setChoices(confRestClient.getMailTemplates()); + template.addRequiredLabel(); + form.add(template); + + final AjaxDropDownChoicePanel<TraceLevel> traceLevel = new AjaxDropDownChoicePanel<TraceLevel>( + "traceLevel", getString("traceLevel"), + new PropertyModel<TraceLevel>(notificationTO, "traceLevel")); + traceLevel.setChoices(Arrays.asList(TraceLevel.values())); + traceLevel.addRequiredLabel(); + form.add(traceLevel); + + final AjaxCheckBoxPanel isActive = new AjaxCheckBoxPanel("isActive", + getString("isActive"), new PropertyModel<Boolean>(notificationTO, "active")); + if (createFlag) { + isActive.getField().setDefaultModelObject(Boolean.TRUE); + } + form.add(isActive); + + final WebMarkupContainer aboutContainer = new WebMarkupContainer("aboutContainer"); + aboutContainer.setOutputMarkupId(true); + + form.add(aboutContainer); + + final AjaxCheckBoxPanel checkAbout = new AjaxCheckBoxPanel("checkAbout", "checkAbout", new Model<Boolean>( + notificationTO.getUserAbout() == null && notificationTO.getRoleAbout() == null)); + aboutContainer.add(checkAbout); + + final AjaxCheckBoxPanel checkUserAbout = new AjaxCheckBoxPanel("checkUserAbout", "checkUserAbout", + new Model<Boolean>(notificationTO.getUserAbout() != null)); + aboutContainer.add(checkUserAbout); + + final AjaxCheckBoxPanel checkRoleAbout = new AjaxCheckBoxPanel("checkRoleAbout", "checkRoleAbout", + new Model<Boolean>(notificationTO.getRoleAbout() != null)); + aboutContainer.add(checkRoleAbout); + + final UserSearchPanel userAbout = + new UserSearchPanel.Builder("userAbout").fiql(notificationTO.getUserAbout()).build(); + aboutContainer.add(userAbout); + userAbout.setEnabled(checkUserAbout.getModelObject()); + + final RoleSearchPanel roleAbout = + new RoleSearchPanel.Builder("roleAbout").fiql(notificationTO.getRoleAbout()).build(); + aboutContainer.add(roleAbout); + roleAbout.setEnabled(checkRoleAbout.getModelObject()); + + checkAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (checkAbout.getModelObject()) { + checkUserAbout.setModelObject(Boolean.FALSE); + checkRoleAbout.setModelObject(Boolean.FALSE); + userAbout.setEnabled(Boolean.FALSE); + roleAbout.setEnabled(Boolean.FALSE); + } else { + checkAbout.setModelObject(Boolean.TRUE); + } + target.add(aboutContainer); + } + }); + + checkUserAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (checkUserAbout.getModelObject()) { + checkAbout.setModelObject(!checkUserAbout.getModelObject()); + checkRoleAbout.setModelObject(!checkUserAbout.getModelObject()); + roleAbout.setEnabled(Boolean.FALSE); + } else { + checkUserAbout.setModelObject(Boolean.TRUE); + } + userAbout.setEnabled(Boolean.TRUE); + target.add(aboutContainer); + } + }); + + checkRoleAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (checkRoleAbout.getModelObject()) { + checkAbout.setModelObject(Boolean.FALSE); + checkUserAbout.setModelObject(Boolean.FALSE); + userAbout.setEnabled(Boolean.FALSE); + } else { + checkRoleAbout.setModelObject(Boolean.TRUE); + } + roleAbout.setEnabled(Boolean.TRUE); + target.add(aboutContainer); + } + }); + + final AjaxDropDownChoicePanel<IntMappingType> recipientAttrType = new AjaxDropDownChoicePanel<IntMappingType>( + "recipientAttrType", new ResourceModel("recipientAttrType", "recipientAttrType").getObject(), + new PropertyModel<IntMappingType>(notificationTO, "recipientAttrType")); + recipientAttrType.setChoices(new ArrayList<IntMappingType>( + IntMappingType.getAttributeTypes(AttributableType.USER, + EnumSet.of(IntMappingType.UserId, IntMappingType.Password)))); + recipientAttrType.setRequired(true); + form.add(recipientAttrType); + + final AjaxDropDownChoicePanel<String> recipientAttrName = new AjaxDropDownChoicePanel<String>( + "recipientAttrName", new ResourceModel("recipientAttrName", "recipientAttrName").getObject(), + new PropertyModel<String>(notificationTO, "recipientAttrName")); + recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject())); + recipientAttrName.setRequired(true); + form.add(recipientAttrName); + + recipientAttrType.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject())); + target.add(recipientAttrName); + } + }); + + form.add(new LoggerCategoryPanel( + "eventSelection", + loggerRestClient.listEvents(), + new PropertyModel<List<String>>(notificationTO, "events"), + getPageReference(), + "Notification") { + + private static final long serialVersionUID = 6429053774964787735L; + + @Override + protected String[] getListRoles() { + return new String[] {}; + } + + @Override + protected String[] getChangeRoles() { + return new String[] {}; + } + }); + + final WebMarkupContainer recipientsContainer = new WebMarkupContainer("recipientsContainer"); + recipientsContainer.setOutputMarkupId(true); + + form.add(recipientsContainer); + + final AjaxCheckBoxPanel checkStaticRecipients = new AjaxCheckBoxPanel("checkStaticRecipients", + "recipients", new Model<Boolean>(!notificationTO.getStaticRecipients().isEmpty())); + form.add(checkStaticRecipients); + + if (createFlag) { + checkStaticRecipients.getField().setDefaultModelObject(Boolean.FALSE); + } + + final AjaxTextFieldPanel staticRecipientsFieldPanel = + new AjaxTextFieldPanel("panel", "staticRecipients", new Model<String>(null)); + staticRecipientsFieldPanel.addValidator(EmailAddressValidator.getInstance()); + staticRecipientsFieldPanel.setRequired(checkStaticRecipients.getModelObject()); + + if (notificationTO.getStaticRecipients().isEmpty()) { + notificationTO.getStaticRecipients().add(null); + } + + final MultiFieldPanel<String> staticRecipients = new MultiFieldPanel<String>("staticRecipients", + new PropertyModel<List<String>>(notificationTO, "staticRecipients"), staticRecipientsFieldPanel); + staticRecipients.setEnabled(checkStaticRecipients.getModelObject()); + form.add(staticRecipients); + + final AjaxCheckBoxPanel checkRecipients = + new AjaxCheckBoxPanel("checkRecipients", "checkRecipients", + new Model<Boolean>(notificationTO.getRecipients() == null ? false : true)); + recipientsContainer.add(checkRecipients); + + if (createFlag) { + checkRecipients.getField().setDefaultModelObject(Boolean.TRUE); + } + + final UserSearchPanel recipients = + new UserSearchPanel.Builder("recipients").fiql(notificationTO.getRecipients()).build(); + + recipients.setEnabled(checkRecipients.getModelObject()); + recipientsContainer.add(recipients); + + final AjaxCheckBoxPanel selfAsRecipient = new AjaxCheckBoxPanel("selfAsRecipient", + getString("selfAsRecipient"), new PropertyModel<Boolean>(notificationTO, "selfAsRecipient")); + form.add(selfAsRecipient); + + if (createFlag) { + selfAsRecipient.getField().setDefaultModelObject(Boolean.FALSE); + } + + selfAsRecipient.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (!selfAsRecipient.getModelObject() + && !checkRecipients.getModelObject() + && !checkStaticRecipients.getModelObject()) { + + checkRecipients.getField().setDefaultModelObject(Boolean.TRUE); + target.add(checkRecipients); + recipients.setEnabled(checkRecipients.getModelObject()); + target.add(recipients); + target.add(recipientsContainer); + } + } + }); + + checkRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (!checkRecipients.getModelObject() + && !selfAsRecipient.getModelObject() + && !checkStaticRecipients.getModelObject()) { + + checkStaticRecipients.getField().setDefaultModelObject(Boolean.TRUE); + target.add(checkStaticRecipients); + staticRecipients.setEnabled(Boolean.TRUE); + target.add(staticRecipients); + staticRecipientsFieldPanel.setRequired(Boolean.TRUE); + target.add(staticRecipientsFieldPanel); + } + recipients.setEnabled(checkRecipients.getModelObject()); + target.add(recipients); + target.add(recipientsContainer); + } + }); + + checkStaticRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + if (!checkStaticRecipients.getModelObject() + && !selfAsRecipient.getModelObject() + && !checkRecipients.getModelObject()) { + checkRecipients.getField().setDefaultModelObject(Boolean.TRUE); + checkRecipients.setEnabled(Boolean.TRUE); + target.add(checkRecipients); + } + staticRecipients.setEnabled(checkStaticRecipients.getModelObject()); + staticRecipientsFieldPanel.setRequired(checkStaticRecipients.getModelObject()); + recipients.setEnabled(checkRecipients.getModelObject()); + target.add(staticRecipientsFieldPanel); + target.add(staticRecipients); + target.add(recipients); + target.add(recipientsContainer); + } + }); + + AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT))) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + notificationTO.setUserAbout( + !checkAbout.getModelObject() && checkUserAbout.getModelObject() ? userAbout.buildFIQL() : null); + notificationTO.setRoleAbout( + !checkAbout.getModelObject() + && checkRoleAbout.getModelObject() ? roleAbout.buildFIQL() : null); + notificationTO.setRecipients(checkRecipients.getModelObject() ? recipients.buildFIQL() : null); + notificationTO.getStaticRecipients().removeAll(Collections.singleton(null)); + + try { + if (createFlag) { + restClient.create(notificationTO); + } else { + restClient.update(notificationTO); + } + info(getString(Constants.OPERATION_SUCCEEDED)); + + Configuration callerPage = (Configuration) pageRef.getPage(); + callerPage.setModalResult(true); + + window.close(target); + } catch (SyncopeClientException scee) { + error(getString(Constants.ERROR) + ": " + scee.getMessage()); + feedbackPanel.refresh(target); + } + } + + @Override + protected void onError(final AjaxRequestTarget target, final Form<?> form) { + feedbackPanel.refresh(target); + } + }; + + final AjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) { + + private static final long serialVersionUID = -958724007591692537L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) { + window.close(target); + } + }; + + cancel.setDefaultFormProcessing(false); + + String allowedRoles = createFlag + ? xmlRolesReader.getEntitlement("Notification", "create") + : xmlRolesReader.getEntitlement("Notification", "update"); + MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles); + + form.add(submit); + form.setDefaultButton(submit); + + form.add(cancel); + + add(form); + } + + private List<String> getSchemaNames(final IntMappingType type) { + final List<String> result; + + if (type == null) { + result = Collections.<String>emptyList(); + } else { + switch (type) { + case UserPlainSchema: + result = schemaRestClient.getPlainSchemaNames(AttributableType.USER); + break; + + case UserDerivedSchema: + result = schemaRestClient.getDerSchemaNames(AttributableType.USER); + break; + + case UserVirtualSchema: + result = schemaRestClient.getVirSchemaNames(AttributableType.USER); + break; + + case Username: + result = Collections.singletonList("Username"); + break; + + default: + result = Collections.<String>emptyList(); + } + } + + return result; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/2d194636/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationTaskModalPage.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationTaskModalPage.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationTaskModalPage.java new file mode 100644 index 0000000..70f63d6 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/NotificationTaskModalPage.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.syncope.client.console.pages; + +import java.util.ArrayList; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.NotificationTaskTO; +import org.apache.wicket.markup.html.form.ListMultipleChoice; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.model.PropertyModel; + +public class NotificationTaskModalPage extends TaskModalPage { + + private static final long serialVersionUID = -4399606755452034216L; + + public NotificationTaskModalPage(final AbstractTaskTO taskTO) { + super(taskTO); + + final AjaxTextFieldPanel sender = new AjaxTextFieldPanel("sender", getString("sender"), + new PropertyModel<String>(taskTO, "sender")); + sender.setEnabled(false); + profile.add(sender); + + if (taskTO instanceof NotificationTaskTO) { + final ListMultipleChoice<String> recipients = new ListMultipleChoice<>("recipients", + new ArrayList<>(((NotificationTaskTO) taskTO).getRecipients())); + recipients.setMaxRows(5); + recipients.setEnabled(false); + profile.add(recipients); + } + + final AjaxTextFieldPanel subject = new AjaxTextFieldPanel("subject", getString("subject"), + new PropertyModel<String>(taskTO, "subject")); + subject.setEnabled(false); + profile.add(subject); + + final TextArea<String> textBody = new TextArea<String>("textBody", + new PropertyModel<String>(taskTO, "textBody")); + textBody.setEnabled(false); + profile.add(textBody); + + final TextArea<String> htmlBody = new TextArea<String>("htmlBody", + new PropertyModel<String>(taskTO, "htmlBody")); + htmlBody.setEnabled(false); + profile.add(htmlBody); + + final AjaxTextFieldPanel traceLevel = new AjaxTextFieldPanel("traceLevel", getString("traceLevel"), + new PropertyModel<String>(taskTO, "traceLevel")); + traceLevel.setEnabled(false); + profile.add(traceLevel); + } +}
