Return-Path: X-Original-To: apmail-syncope-commits-archive@www.apache.org Delivered-To: apmail-syncope-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 938971877F for ; Mon, 19 Oct 2015 14:37:03 +0000 (UTC) Received: (qmail 86892 invoked by uid 500); 19 Oct 2015 14:37:03 -0000 Delivered-To: apmail-syncope-commits-archive@syncope.apache.org Received: (qmail 86828 invoked by uid 500); 19 Oct 2015 14:37:03 -0000 Mailing-List: contact commits-help@syncope.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@syncope.apache.org Delivered-To: mailing list commits@syncope.apache.org Received: (qmail 86732 invoked by uid 99); 19 Oct 2015 14:37:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Oct 2015 14:37:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C69E3E049D; Mon, 19 Oct 2015 14:37:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ilgrosso@apache.org To: commits@syncope.apache.org Date: Mon, 19 Oct 2015 14:37:06 -0000 Message-Id: <7014f74987a34d599f434e8322a0a43d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/8] syncope git commit: Upgrading surefire, failsafe and checkstyle plugins http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java index e049a28,0000000..7bcfc10 mode 100644,000000..100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java @@@ -1,303 -1,0 +1,303 @@@ +/* + * 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.cli.commands.install; + +import java.io.FileNotFoundException; +import java.io.UnsupportedEncodingException; +import java.net.ConnectException; +import java.net.UnknownHostException; +import java.util.Scanner; +import javax.ws.rs.ProcessingException; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.cli.Command; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.client.cli.commands.AbstractCommand; +import org.apache.syncope.client.cli.commands.LoggerCommand; +import org.apache.syncope.client.cli.util.FileSystemUtils; +import org.apache.syncope.client.cli.util.JasyptUtils; +import org.apache.syncope.common.rest.api.service.SyncopeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(name = "install") +public class InstallCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class); + + private static final String HELP_MESSAGE = "Usage: install [options]\n" + + " Options:\n" + + " --help \n" + + " --setup"; + + private String syncopeAdminUser; + + private String syncopeAdminPassword; + + private String syncopeServerSchema; + + private String syncopeServerHostname = "localhost"; + + private String syncopeServerPort = "8080"; + + private String syncopeServerRestContext = "/syncope/rest/"; + + @Override + public void execute(final Input input) { + LOG.debug("Option: {}", input.getOption()); + LOG.debug("Parameters:"); + for (final String parameter : input.getParameters()) { + LOG.debug(" > " + parameter); + } + + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + switch (Options.fromName(input.getOption())) { + case INSTALL: + final Scanner scanIn = new Scanner(System.in); + + System.out.println(""); + System.out.println("###############################################"); + System.out.println("# #"); + System.out.println("# Welcome to Syncope CLI installation process #"); + System.out.println("# #"); + System.out.println("###############################################"); + System.out.println(""); + + System.out.println("Path to config files of Syncope CLI client will be: " + + InstallConfigFileTemplate.DIR_PATH); + + if (!FileSystemUtils.canWrite(InstallConfigFileTemplate.DIR_PATH)) { + System.out.println("Permission denied on " + InstallConfigFileTemplate.DIR_PATH); + break; + } + System.out.println("- File system permission checked"); + System.out.println(""); + + System.out.println("Syncope server schema [http/https]:"); + String syncopeServerSchemaFromSystemIn = scanIn.nextLine(); + boolean schemaFounded = false; + while (!schemaFounded) { + if (("http".equalsIgnoreCase(syncopeServerSchemaFromSystemIn)) + || ("https".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))) { + syncopeServerSchema = syncopeServerSchemaFromSystemIn; + schemaFounded = true; + } else { + System.out.println("Please use one of below values:"); + System.out.println(" - http"); + System.out.println(" - https"); + syncopeServerSchemaFromSystemIn = scanIn.nextLine(); + } + } + + System.out.println("Syncope server hostname [e.g. " + syncopeServerHostname + "]:"); + String syncopeServerHostnameFromSystemIn = scanIn.nextLine(); + boolean syncopeServerHostnameFounded = false; + while (!syncopeServerHostnameFounded) { + if (StringUtils.isNotBlank(syncopeServerHostnameFromSystemIn)) { + syncopeServerHostname = syncopeServerHostnameFromSystemIn; + syncopeServerHostnameFounded = true; + } else { + System.out.println("Syncope server hostname [e.g. " + syncopeServerHostname + "]:"); + syncopeServerHostnameFromSystemIn = scanIn.nextLine(); + } + } + + System.out.println("Syncope server port [e.g. " + syncopeServerPort + "]:"); + String syncopeServerPortFromSystemIn = scanIn.nextLine(); + boolean syncopeServerPortFounded = false; + while (!syncopeServerPortFounded) { + if (StringUtils.isNotBlank(syncopeServerPortFromSystemIn)) { + syncopeServerPort = syncopeServerPortFromSystemIn; + syncopeServerPortFounded = true; + } else if (!StringUtils.isNumeric(syncopeServerPortFromSystemIn)) { + System.out.println(syncopeServerPortFromSystemIn + " is not a numeric string, try again"); + syncopeServerPortFromSystemIn = scanIn.nextLine(); + } else { + System.out.println("Syncope server port [e.g. " + syncopeServerPort + "]:"); + syncopeServerPortFromSystemIn = scanIn.nextLine(); + } + } + + System.out.println("Syncope server rest context [e.g. " + syncopeServerRestContext + "]:"); + String syncopeServerRestContextFromSystemIn = scanIn.nextLine(); + boolean syncopeServerRestContextFounded = false; + while (!syncopeServerRestContextFounded) { + if (StringUtils.isNotBlank(syncopeServerRestContextFromSystemIn)) { + syncopeServerRestContext = syncopeServerRestContextFromSystemIn; + syncopeServerRestContextFounded = true; + } else { + System.out.println("Syncope server port [e.g. " + syncopeServerRestContext + "]:"); + syncopeServerRestContextFromSystemIn = scanIn.nextLine(); + } + } + + System.out.println("Syncope admin user:"); + String syncopeAdminUserFromSystemIn = scanIn.nextLine(); + boolean syncopeAdminUserFounded = false; + while (!syncopeAdminUserFounded) { + if (StringUtils.isNotBlank(syncopeAdminUserFromSystemIn)) { + syncopeAdminUser = syncopeAdminUserFromSystemIn; + syncopeAdminUserFounded = true; + } else { + System.out.println("Syncope admin user:"); + syncopeAdminUserFromSystemIn = scanIn.nextLine(); + } + } + + System.out.println("Syncope admin password:"); + String syncopeAdminPasswordFromSystemIn = scanIn.nextLine(); + boolean syncopeAdminPasswordFounded = false; + while (!syncopeAdminPasswordFounded) { + if (StringUtils.isNotBlank(syncopeAdminPasswordFromSystemIn)) { + syncopeAdminPassword = syncopeAdminPasswordFromSystemIn; + syncopeAdminPasswordFounded = true; + } else { + System.out.println("Syncope admin user:"); + syncopeAdminPasswordFromSystemIn = scanIn.nextLine(); + } + } + + scanIn.close(); + + final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils(); + + try { + FileSystemUtils.createNewDirectory(InstallConfigFileTemplate.DIR_PATH); + final String contentCliPropertiesFile = InstallConfigFileTemplate.createFile( + syncopeServerSchema, + syncopeServerHostname, + syncopeServerPort, + syncopeServerRestContext, + syncopeAdminUser, + jasyptUtils.encrypt(syncopeAdminPassword)); + FileSystemUtils.createFileWith(InstallConfigFileTemplate.FILE_PATH, contentCliPropertiesFile); + + } catch (final FileNotFoundException | UnsupportedEncodingException ex) { + System.out.println(ex.getMessage()); + } + + try { + final SyncopeService syncopeService = SyncopeServices.get(SyncopeService.class); + System.out.println("Provided parameters checked on Syncope core version: " + + syncopeService.info().getVersion()); + System.out.println(""); + System.out.println("###############################################"); + System.out.println("# #"); + System.out.println("# Installation successful #"); + System.out.println("# now you can use Syncope CLI client #"); + System.out.println("# #"); + System.out.println("###############################################"); + System.out.println(""); + } catch (final ProcessingException ex) { + if (ex.getCause() instanceof UnknownHostException) { + final String unknownHost = ex.getCause().getMessage().split(":")[3]; + System.out.println(""); + System.out.println("Provided host:" + unknownHost); + System.out.println(""); + System.out.println("###############################################"); + System.out.println("# #"); + System.out.println("# Provided unknown host! #"); + System.out.println("# START AGAIN the installation! #"); + System.out.println("# #"); + System.out.println("###############################################"); + System.out.println(""); + } else if (ex.getCause() instanceof ConnectException) { + System.out.println(""); + System.out.println("Provided address :" + SyncopeServices.getAddress()); + System.out.println(""); + System.out.println("###############################################"); + System.out.println("# #"); + System.out.println("# Provided address is unreachable! #"); + System.out.println("# Check it and if it is wrong #"); + System.out.println("# START AGAIN the installation! #"); + System.out.println("# #"); + System.out.println("###############################################"); + System.out.println(""); + } + } catch (final Exception e) { + if (e.getMessage().contains("not authenticated")) { + System.out.println(""); + System.out.println("###############################################"); + System.out.println("# #"); + System.out.println("# Username or password provided are wrong #"); + System.out.println("# START AGAIN the installation! #"); + System.out.println("# #"); + System.out.println("###############################################"); + System.out.println(""); + } else { + System.out.println(""); + System.out.println("###############################################"); + System.out.println("# #"); + System.out.println("# Something wrong #"); + System.out.println("# START AGAIN the installation! #"); + System.out.println("# #"); + System.out.println("###############################################"); + System.out.println(""); + } + } + break; + case HELP: + System.out.println(HELP_MESSAGE); + break; + default: + System.out.println(input.getOption() + " is not a valid option."); + System.out.println(""); + System.out.println(HELP_MESSAGE); + } + } + + @Override + public String getHelpMessage() { + return HELP_MESSAGE; + } + + private enum Options { + + HELP("--help"), + INSTALL("--setup"); + + private final String optionName; + - private Options(final String optionName) { ++ Options(final String optionName) { + this.optionName = optionName; + } + + public String getOptionName() { + return optionName; + } + + public boolean equalsOptionName(final String otherName) { + return (otherName == null) ? false : optionName.equals(otherName); + } + + public static Options fromName(final String name) { + Options optionToReturn = HELP; + for (final Options option : Options.values()) { + if (option.equalsOptionName(name)) { + optionToReturn = option; + } + } + return optionToReturn; + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/console/src/main/java/org/apache/syncope/client/console/commons/SortableAnyProviderComparator.java ---------------------------------------------------------------------- diff --cc client/console/src/main/java/org/apache/syncope/client/console/commons/SortableAnyProviderComparator.java index 99cfaf0,0000000..68ea374 mode 100644,000000..100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/commons/SortableAnyProviderComparator.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/commons/SortableAnyProviderComparator.java @@@ -1,122 -1,0 +1,122 @@@ +/* + * 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.commons; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.syncope.common.lib.to.AnyTO; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.types.SchemaType; +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.AbstractReadOnlyModel; + +public class SortableAnyProviderComparator extends SortableDataProviderComparator { + + private static final long serialVersionUID = 1775967163571699258L; + + private static final Set INLINE_PROPS = new HashSet<>(Arrays.asList( + new String[] { "key", "status", "token", "username" })); + + public SortableAnyProviderComparator(final SortableDataProvider provider) { + super(provider); + } + + @Override + public int compare(final AnyTO any1, final AnyTO any2) { + if (INLINE_PROPS.contains(provider.getSort().getProperty())) { + return super.compare(any1, any2); + } + + return super.compare(new AttrModel(any1), new AttrModel(any2)); + } + + @SuppressWarnings("rawtypes") + private class AttrModel extends AbstractReadOnlyModel { + + private static final long serialVersionUID = -7856686374020091808L; + + private final Map attrs; + + private final Map derAttrs; + + private final Map virAttrs; + - public AttrModel(final AnyTO anyTO) { ++ AttrModel(final AnyTO anyTO) { + super(); + + this.attrs = anyTO.getPlainAttrMap(); + this.derAttrs = anyTO.getDerAttrMap(); + this.virAttrs = anyTO.getVirAttrMap(); + } + + /** + * @see UserAttrColumn constructor + */ + @Override + public Comparable getObject() { + int hashPos = provider.getSort().getProperty().indexOf('#'); + + SchemaType schemaType = null; + final String schema; + if (hashPos == -1) { + schema = provider.getSort().getProperty(); + } else { + String[] splitted = provider.getSort().getProperty().split("#"); + try { + schemaType = SchemaType.valueOf(splitted[0]); + } catch (IllegalArgumentException e) { + // this should never happen + } + schema = provider.getSort().getProperty().substring(hashPos + 1); + } + + final AttrTO attr; + if (schemaType == null) { + attr = this.attrs.get(schema); + } else { + switch (schemaType) { + case PLAIN: + default: + attr = this.attrs.get(schema); + break; + + case DERIVED: + attr = this.derAttrs.get(schema); + break; + + case VIRTUAL: + attr = this.virAttrs.get(schema); + break; + } + } + + Comparable result = null; + + List values = attr == null ? null : attr.getValues(); + if (values != null && !values.isEmpty()) { + result = values.iterator().next(); + } + + return result; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java ---------------------------------------------------------------------- diff --cc client/console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java index 7198c2c,0000000..56b6992 mode 100644,000000..100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/commons/status/Status.java @@@ -1,45 -1,0 +1,45 @@@ +/* + * 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.commons.status; + +public enum Status { + + NOT_YET_SUBMITTED(""), + CREATED("created"), + ACTIVE("active"), + SUSPENDED("inactive"), + UNDEFINED("undefined"), + OBJECT_NOT_FOUND("objectnotfound"); + + public boolean isActive() { + return this == ACTIVE; + } + - private Status(final String name) { ++ Status(final String name) { + this.name = name; + } + + private final String name; + + @Override + public String toString() { + return name; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java ---------------------------------------------------------------------- diff --cc client/console/src/main/java/org/apache/syncope/client/console/pages/Login.java index 23fb25f,0000000..99cd6d3 mode 100644,000000..100644 --- 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 @@@ -1,210 -1,0 +1,210 @@@ +/* + * 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.Locale; +import org.apache.syncope.client.console.SyncopeConsoleApplication; +import org.apache.syncope.client.console.SyncopeConsoleSession; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.panels.NotificationPanel; +import org.apache.syncope.common.lib.SyncopeConstants; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.authentication.IAuthenticationStrategy; +import org.apache.wicket.authroles.authentication.AuthenticatedWebSession; +import org.apache.wicket.markup.html.WebPage; +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.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; + +public class Login extends WebPage { + + private static final long serialVersionUID = 5889157642852559004L; + + @SpringBean(name = "anonymousUser") + private String anonymousUser; + + private final NotificationPanel feedbackPanel; + + private final StatelessForm form; + + private final TextField usernameField; + + private final TextField passwordField; + + private final DropDownChoice languageSelect; + + private final DropDownChoice domainSelect; + + public Login(final PageParameters parameters) { + super(parameters); + setStatelessHint(true); + + feedbackPanel = new NotificationPanel(Constants.FEEDBACK); + add(feedbackPanel); + + form = new StatelessForm<>("login"); + + usernameField = new TextField<>("username", new Model()); + usernameField.setMarkupId("username"); + form.add(usernameField); + + passwordField = new PasswordTextField("password", new Model()); + passwordField.setMarkupId("password"); + form.add(passwordField); + + languageSelect = new LocaleDropDown("language"); + form.add(languageSelect); + + domainSelect = new DomainDropDown("domain"); + if (SyncopeConsoleSession.get().getDomains().size() == 1) { + domainSelect.setOutputMarkupPlaceholderTag(true); + } + form.add(domainSelect); + + AjaxButton submitButton = new AjaxButton("submit", new Model<>(getString("submit"))) { + + private static final long serialVersionUID = 429178684321093953L; + + @Override + protected void onSubmit(final AjaxRequestTarget target, final Form form) { + if (anonymousUser.equals(usernameField.getRawInput())) { + throw new AccessControlException("Illegal username"); + } + + IAuthenticationStrategy strategy = getApplication().getSecuritySettings().getAuthenticationStrategy(); + + if (AuthenticatedWebSession.get().signIn(usernameField.getRawInput(), passwordField.getRawInput())) { + // If login has been called because the user was not yet logged in, than continue to the + // original destination, otherwise to the Home page + continueToOriginalDestination(); + setResponsePage(getApplication().getHomePage()); + } else { + error(getString("login-error")); + feedbackPanel.refresh(target); + } + strategy.remove(); + } + }; + submitButton.setDefaultFormProcessing(false); + form.add(submitButton); + form.setDefaultButton(submitButton); + + add(form); + } + + /** + * Inner class which implements (custom) Locale DropDownChoice component. + */ + private class LocaleDropDown extends DropDownChoice { + + private static final long serialVersionUID = 2349382679992357202L; + + private class LocaleRenderer extends ChoiceRenderer { + + private static final long serialVersionUID = -3657529581555164741L; + + @Override + public String getDisplayValue(final Locale locale) { + return locale.getDisplayName(getLocale()); + } + } + - public LocaleDropDown(final String id) { ++ LocaleDropDown(final String id) { + super(id, SyncopeConsoleApplication.SUPPORTED_LOCALES); + + setChoiceRenderer(new LocaleRenderer()); + setModel(new IModel() { + + 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; + } + } + + /** + * Inner class which implements (custom) Domain DropDownChoice component. + */ + private class DomainDropDown extends DropDownChoice { + + private static final long serialVersionUID = -7401167913360133325L; + - public DomainDropDown(final String id) { ++ DomainDropDown(final String id) { + super(id, SyncopeConsoleSession.get().getDomains()); + + setModel(new IModel() { + + private static final long serialVersionUID = -1124206668056084806L; + + @Override + public String getObject() { + return SyncopeConsoleSession.get().getDomain(); + } + + @Override + public void setObject(final String object) { + SyncopeConsoleSession.get().setDomain(object); + } + + @Override + public void detach() { + // Empty. + } + }); + + // set default value to Master Domain + getModel().setObject(SyncopeConstants.MASTER_DOMAIN); + } + + @Override + protected boolean wantOnSelectionChangedNotifications() { + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java ---------------------------------------------------------------------- diff --cc client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java index b631210,0000000..c66d650 mode 100644,000000..100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/ProvisioningModalPage.java @@@ -1,252 -1,0 +1,252 @@@ +/* + * 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.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.status.AbstractStatusBeanProvider; +import org.apache.syncope.client.console.commons.status.ConnObjectWrapper; +import org.apache.syncope.client.console.commons.status.StatusBean; +import org.apache.syncope.client.console.commons.status.StatusUtils; +import org.apache.syncope.client.console.panels.ActionDataTablePanel; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.common.lib.to.AnyTO; +import org.apache.syncope.common.lib.to.BulkActionResult; +import org.apache.syncope.common.lib.to.ResourceTO; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.common.lib.types.ResourceDeassociationAction; +import org.apache.syncope.common.lib.wrap.AbstractWrappable; +import org.apache.syncope.common.lib.wrap.AnyKey; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.extensions.markup.html.repeater.util.SortParam; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.StringResourceModel; + +public class ProvisioningModalPage extends AbstractStatusModalPage { + + private static final long serialVersionUID = -4285220460543213901L; + + private static final int ROWS_PER_PAGE = 10; + + private final ResourceTO resourceTO; + + private final AnyTypeKind anyTypeKind; + + private final PageReference pageRef; + + private final ModalWindow window; + + private final StatusUtils statusUtils; + + private final String realm = "/"; + + public ProvisioningModalPage( + final PageReference pageRef, + final ModalWindow window, + final ResourceTO resourceTO, + final AnyTypeKind anyTypeKind) { + + super(); + + this.pageRef = pageRef; + this.window = window; + this.resourceTO = resourceTO; + this.anyTypeKind = anyTypeKind; + + statusUtils = new StatusUtils(anyTypeKind == AnyTypeKind.USER ? userRestClient : groupRestClient); + + add(new Label("displayName", StringUtils.EMPTY)); + + final List> columns = new ArrayList<>(); + columns.add(new PropertyColumn( + new StringResourceModel("key", this).setDefaultValue("Attributable key"), + "attributableKey", "attributableKey")); + columns.add(new PropertyColumn( + new StringResourceModel("name", this).setDefaultValue("Attributable name"), + "attributableName", "attributableName")); + columns.add(new PropertyColumn( + new StringResourceModel("resourceName", this).setDefaultValue("Resource name"), + "resourceName", "resourceName")); + columns.add(new PropertyColumn( + new StringResourceModel("connObjectLink", this).setDefaultValue("ConnObjectLink"), + "connObjectLink", "connObjectLink")); + columns.add(new AbstractColumn( + new StringResourceModel("status", this).setDefaultValue(StringUtils.EMPTY)) { + + private static final long serialVersionUID = -3503023501954863131L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public void populateItem( + final Item> cellItem, + final String componentId, + final IModel model) { + cellItem. + add(statusUtils.getStatusImagePanel(componentId, model.getObject().getStatus())); + } + }); + + final ActionDataTablePanel table = new ActionDataTablePanel<>( + "resourceDatatable", + columns, + (ISortableDataProvider) new StatusBeanProvider(), + ROWS_PER_PAGE, + pageRef); + + final String pageId = "Resources"; + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + bulkAssociationAction(target, ResourceDeassociationAction.UNLINK, table, columns); + } catch (Exception e) { + LOG.error("Error unlinkink resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.UNLINK, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + bulkAssociationAction(target, ResourceDeassociationAction.DEPROVISION, table, columns); + } catch (Exception e) { + LOG.error("Error de-provisioning user", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.DEPROVISION, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + bulkAssociationAction(target, ResourceDeassociationAction.UNASSIGN, table, columns); + } catch (Exception e) { + LOG.error("Error unassigning resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.UNASSIGN, pageId); + + table.addCancelButton(window); + + add(table); + } + + private class StatusBeanProvider extends AbstractStatusBeanProvider { + + private static final long serialVersionUID = 4287357360778016173L; + - public StatusBeanProvider() { ++ StatusBeanProvider() { + super("accountLink"); + } + + @SuppressWarnings("unchecked") + @Override + public List getStatusBeans() { + final String fiql = SyncopeClient.getUserSearchConditionBuilder().hasResources(resourceTO.getKey()).query(); + + final List subjects = new ArrayList<>(); + if (anyTypeKind == AnyTypeKind.USER) { + subjects.addAll((List) userRestClient.search( + realm, fiql, 1, ROWS_PER_PAGE, new SortParam<>("key", true), AnyTypeKind.USER.toString())); + } else { + subjects.addAll((List) groupRestClient.search( + realm, fiql, 1, ROWS_PER_PAGE, new SortParam<>("key", true), AnyTypeKind.GROUP.toString())); + } + + final List connObjects = statusUtils.getConnectorObjects( + (List) subjects, Collections.singleton(resourceTO.getKey())); + + final List statusBeans = new ArrayList<>(connObjects.size() + 1); + final LinkedHashMap initialStatusBeanMap = new LinkedHashMap<>(connObjects.size()); + + for (ConnObjectWrapper entry : connObjects) { + StatusBean statusBean = statusUtils.getStatusBean(entry.getAny(), + entry.getResourceName(), + entry.getConnObjectTO(), + anyTypeKind == AnyTypeKind.GROUP); + + initialStatusBeanMap.put(entry.getResourceName(), statusBean); + statusBeans.add(statusBean); + } + + return statusBeans; + } + } + + private void bulkAssociationAction( + final AjaxRequestTarget target, + final ResourceDeassociationAction type, + final ActionDataTablePanel table, + final List> columns) { + + final List beans = new ArrayList<>(table.getModelObject()); + List subjectKeys = new ArrayList<>(); + for (StatusBean bean : beans) { + LOG.debug("Selected bean {}", bean); + subjectKeys.add(AbstractWrappable.getInstance(AnyKey.class, bean.getAnyKey())); + } + + if (beans.isEmpty()) { + window.close(target); + } else { + final BulkActionResult res = resourceRestClient.bulkAssociationAction( + resourceTO.getKey(), anyTypeKind.name(), type, subjectKeys); + + ((BasePage) pageRef.getPage()).setModalResult(true); + + setResponsePage(new BulkActionResultModalPage<>(window, beans, columns, res, "anyKey")); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/console/src/main/java/org/apache/syncope/client/console/pages/StatusModalPage.java ---------------------------------------------------------------------- diff --cc client/console/src/main/java/org/apache/syncope/client/console/pages/StatusModalPage.java index 1357cad,0000000..238f13d mode 100644,000000..100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/pages/StatusModalPage.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/StatusModalPage.java @@@ -1,642 -1,0 +1,642 @@@ +/* + * 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.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.console.commons.Constants; +import org.apache.syncope.client.console.commons.status.AbstractStatusBeanProvider; +import org.apache.syncope.client.console.commons.status.ConnObjectWrapper; +import org.apache.syncope.client.console.commons.status.Status; +import org.apache.syncope.client.console.commons.status.StatusBean; +import org.apache.syncope.client.console.commons.status.StatusUtils; +import org.apache.syncope.client.console.panels.ActionDataTablePanel; +import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxButton; +import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel; +import org.apache.syncope.common.lib.to.AnyTO; +import org.apache.syncope.common.lib.to.BulkActionResult; +import org.apache.syncope.common.lib.to.ResourceTO; +import org.apache.syncope.common.lib.to.GroupTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.ResourceAssociationAction; +import org.apache.wicket.PageReference; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.PasswordTextField; +import org.apache.wicket.markup.html.panel.Fragment; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.model.StringResourceModel; + +public class StatusModalPage extends AbstractStatusModalPage { + + private static final long serialVersionUID = -9148734710505211261L; + + private final AnyTO anyTO; + + private int rowsPerPage = 10; + + private final StatusUtils statusUtils; + + private final boolean statusOnly; + + // -------------------------------- + // password management fields .. + // -------------------------------- + private final ClearIndicatingAjaxButton cancel; + + private final WebMarkupContainer pwdMgt; + + private final Form pwdMgtForm; + + private final AjaxCheckBoxPanel changepwd; + + private final PasswordTextField password; + + private final PasswordTextField confirm; + // -------------------------------- + + private final PageReference pageRef; + + private final ModalWindow window; + + private final ActionDataTablePanel table; + + private final List> columns; + + public StatusModalPage( + final PageReference pageRef, + final ModalWindow window, + final AnyTO attributableTO) { + + this(pageRef, window, attributableTO, false); + } + + public StatusModalPage( + final PageReference pageRef, + final ModalWindow window, + final AnyTO anyTO, + final boolean statusOnly) { + + super(); + + this.pageRef = pageRef; + this.window = window; + this.statusOnly = statusOnly; + this.anyTO = anyTO; + + statusUtils = new StatusUtils(anyTO instanceof UserTO ? userRestClient : groupRestClient); + + add(new Label("displayName", anyTO.getKey() + " " + + (anyTO instanceof UserTO ? ((UserTO) anyTO).getUsername() : ((GroupTO) anyTO).getName()))); + + columns = new ArrayList<>(); + columns.add(new AbstractColumn( + new StringResourceModel("resourceName", this, null), "resourceName") { + + private static final long serialVersionUID = 2054811145491901166L; + + @Override + public void populateItem( + final Item> cellItem, + final String componentId, + final IModel model) { + + cellItem.add(new Label(componentId, model.getObject().getResourceName()) { + + private static final long serialVersionUID = 8432079838783825801L; + + @Override + protected void onComponentTag(final ComponentTag tag) { + if (model.getObject().isLinked()) { + super.onComponentTag(tag); + } else { + tag.put("style", "color: #DDDDDD"); + } + } + }); + } + }); + + columns.add(new PropertyColumn( + new StringResourceModel("accountLink", this, null), "accountLink", "accountLink")); + + columns.add(new AbstractColumn( + new StringResourceModel("status", this, null)) { + + private static final long serialVersionUID = -3503023501954863131L; + + @Override + public String getCssClass() { + return "action"; + } + + @Override + public void populateItem( + final Item> cellItem, + final String componentId, + final IModel model) { + + if (model.getObject().isLinked()) { + cellItem.add(statusUtils.getStatusImagePanel(componentId, model.getObject(). + getStatus())); + } else { + cellItem.add(new Label(componentId, "")); + } + } + }); + + table = new ActionDataTablePanel( + "resourceDatatable", + columns, + (ISortableDataProvider) new AttributableStatusProvider(), + rowsPerPage, + pageRef) { + + private static final long serialVersionUID = 6510391461033818316L; + + @Override + public boolean isElementEnabled(final StatusBean element) { + return !statusOnly || element.getStatus() != Status.OBJECT_NOT_FOUND; + } + }; + table.setOutputMarkupId(true); + + final String pageId = anyTO instanceof GroupTO ? "Groups" : "Users"; + + final Fragment pwdMgtFragment = new Fragment("pwdMgtFields", "pwdMgtFragment", this); + addOrReplace(pwdMgtFragment); + + pwdMgt = new WebMarkupContainer("pwdMgt"); + pwdMgtFragment.add(pwdMgt.setOutputMarkupId(true)); + + pwdMgtForm = new Form("pwdMgtForm"); + pwdMgtForm.setVisible(false).setEnabled(false); + pwdMgt.add(pwdMgtForm); + + password = new PasswordTextField("password", new Model()); + pwdMgtForm.add(password.setRequired(false).setEnabled(false)); + + confirm = new PasswordTextField("confirm", new Model()); + pwdMgtForm.add(confirm.setRequired(false).setEnabled(false)); + + changepwd = new AjaxCheckBoxPanel("changepwd", "changepwd", new Model(false)); + pwdMgtForm.add(changepwd.setModelObject(false)); + pwdMgtForm.add(new Label("changePwdLabel", new ResourceModel("changePwdLabel", "Password propagation"))); + + changepwd.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) { + + private static final long serialVersionUID = -1107858522700306810L; + + @Override + protected void onUpdate(final AjaxRequestTarget target) { + password.setEnabled(changepwd.getModelObject()); + confirm.setEnabled(changepwd.getModelObject()); + target.add(pwdMgt); + } + }); + + cancel = new ClearIndicatingAjaxButton("cancel", new ResourceModel("cancel"), pageRef) { + + private static final long serialVersionUID = -2341391430136818026L; + + @Override + protected void onSubmitInternal(final AjaxRequestTarget target, final Form form) { + // ignore + window.close(target); + } + }.feedbackPanelAutomaticReload(false); + + pwdMgtForm.add(cancel); + + final ClearIndicatingAjaxButton goon = + new ClearIndicatingAjaxButton("continue", new ResourceModel("continue"), pageRef) { + + private static final long serialVersionUID = -2341391430136818027L; + + @Override + protected void onSubmitInternal(final AjaxRequestTarget target, final Form form) { + // none + } + }; + + pwdMgtForm.add(goon); + + if (statusOnly) { + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + userRestClient.reactivate( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + + ((BasePage) pageRef.getPage()).setModalResult(true); + + window.close(target); + } catch (Exception e) { + LOG.error("Error enabling resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.REACTIVATE, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + userRestClient.suspend( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + + if (pageRef.getPage() instanceof BasePage) { + ((BasePage) pageRef.getPage()).setModalResult(true); + } + + window.close(target); + } catch (Exception e) { + LOG.error("Error disabling resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.SUSPEND, pageId); + } else { + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + if (anyTO instanceof UserTO) { + userRestClient.unlink( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } else { + groupRestClient.unlink( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } + + ((BasePage) pageRef.getPage()).setModalResult(true); + window.close(target); + } catch (Exception e) { + LOG.error("Error unlinking resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.UNLINK, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + if (anyTO instanceof UserTO) { + userRestClient.link( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } else { + groupRestClient.link( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } + + ((BasePage) pageRef.getPage()).setModalResult(true); + window.close(target); + } catch (Exception e) { + LOG.error("Error linking resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.LINK, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + BulkActionResult bulkActionResult; + if (anyTO instanceof UserTO) { + bulkActionResult = userRestClient.deprovision( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } else { + bulkActionResult = groupRestClient.deprovision( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } + + ((BasePage) pageRef.getPage()).setModalResult(true); + loadBulkActionResultPage(table.getModelObject(), bulkActionResult); + } catch (Exception e) { + LOG.error("Error de-provisioning user", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.DEPROVISION, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + + if (anyTO instanceof UserTO) { + StatusModalPage.this.passwordManagement( + target, ResourceAssociationAction.PROVISION, table.getModelObject()); + } else { + try { + final BulkActionResult bulkActionResult = groupRestClient.provision( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + + ((BasePage) pageRef.getPage()).setModalResult(true); + loadBulkActionResultPage(table.getModelObject(), bulkActionResult); + } catch (Exception e) { + LOG.error("Error provisioning user", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + } + }.feedbackPanelAutomaticReload(!(anyTO instanceof UserTO)), ActionLink.ActionType.PROVISION, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + try { + final BulkActionResult bulkActionResult; + if (anyTO instanceof UserTO) { + bulkActionResult = userRestClient.unassign( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } else { + bulkActionResult = groupRestClient.unassign( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + } + + ((BasePage) pageRef.getPage()).setModalResult(true); + loadBulkActionResultPage(table.getModelObject(), bulkActionResult); + } catch (Exception e) { + LOG.error("Error unassigning resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }, ActionLink.ActionType.UNASSIGN, pageId); + + table.addAction(new ActionLink() { + + private static final long serialVersionUID = -3722207913631435501L; + + @Override + public void onClick(final AjaxRequestTarget target, final Serializable ignore) { + if (anyTO instanceof UserTO) { + StatusModalPage.this.passwordManagement( + target, ResourceAssociationAction.ASSIGN, table.getModelObject()); + } else { + try { + final BulkActionResult bulkActionResult = groupRestClient.assign( + anyTO.getETagValue(), + anyTO.getKey(), + new ArrayList<>(table.getModelObject())); + + ((BasePage) pageRef.getPage()).setModalResult(true); + loadBulkActionResultPage(table.getModelObject(), bulkActionResult); + } catch (Exception e) { + LOG.error("Error assigning resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + } + }.feedbackPanelAutomaticReload(!(anyTO instanceof UserTO)), ActionLink.ActionType.ASSIGN, pageId); + } + + table.addCancelButton(window); + add(table); + } + + private class AttributableStatusProvider extends AbstractStatusBeanProvider { + + private static final long serialVersionUID = 4586969457669796621L; + - public AttributableStatusProvider() { ++ AttributableStatusProvider() { + super(statusOnly ? "resourceName" : "accountLink"); + } + + @SuppressWarnings("unchecked") + @Override + public List getStatusBeans() { + final List resources = new ArrayList<>(); + for (ResourceTO resourceTO : resourceRestClient.getAll()) { + resources.add(resourceTO.getKey()); + } + + final List connObjects = statusUtils.getConnectorObjects(anyTO); + + final List statusBeans = new ArrayList(connObjects.size() + 1); + + for (ConnObjectWrapper entry : connObjects) { + final StatusBean statusBean = statusUtils.getStatusBean(anyTO, + entry.getResourceName(), + entry.getConnObjectTO(), + anyTO instanceof GroupTO); + + statusBeans.add(statusBean); + resources.remove(entry.getResourceName()); + } + + if (statusOnly) { + final StatusBean syncope = new StatusBean(anyTO, "Syncope"); + + syncope.setConnObjectLink(((UserTO) anyTO).getUsername()); + + Status syncopeStatus = Status.UNDEFINED; + if (((UserTO) anyTO).getStatus() != null) { + try { + syncopeStatus = Status.valueOf(((UserTO) anyTO).getStatus().toUpperCase()); + } catch (IllegalArgumentException e) { + LOG.warn("Unexpected status found: {}", ((UserTO) anyTO).getStatus(), e); + } + } + syncope.setStatus(syncopeStatus); + + statusBeans.add(syncope); + } else { + for (String resource : resources) { + final StatusBean statusBean = statusUtils.getStatusBean(anyTO, + resource, + null, + anyTO instanceof GroupTO); + + statusBean.setLinked(false); + statusBeans.add(statusBean); + } + } + + return statusBeans; + } + } + + private void passwordManagement( + final AjaxRequestTarget target, + final ResourceAssociationAction type, + final Collection selection) { + + final ClearIndicatingAjaxButton goon = + new ClearIndicatingAjaxButton("continue", new ResourceModel("continue", "Continue"), pageRef) { + + private static final long serialVersionUID = -2341391430136818027L; + + @Override + protected void onSubmitInternal(final AjaxRequestTarget target, final Form form) { + try { + if (StringUtils.isNotBlank(password.getModelObject()) + && !password.getModelObject().equals(confirm.getModelObject())) { + throw new Exception(getString("passwordMismatch")); + } + + final BulkActionResult bulkActionResult; + switch (type) { +// case ASSIGN: +// bulkActionResult = userRestClient.assign( +// anyTO.getETagValue(), +// anyTO.getKey(), +// new ArrayList<>(selection), +// changepwd.getModelObject(), +// password.getModelObject()); +// break; +// case PROVISION: +// bulkActionResult = userRestClient.provision( +// anyTO.getETagValue(), +// anyTO.getKey(), +// new ArrayList<>(selection), +// changepwd.getModelObject(), +// password.getModelObject()); +// break; + default: + bulkActionResult = null; + // ignore + } + + ((BasePage) pageRef.getPage()).setModalResult(true); + + if (bulkActionResult != null) { + loadBulkActionResultPage(selection, bulkActionResult); + } else { + + target.add(((BasePage) pageRef.getPage()).getFeedbackPanel()); + window.close(target); + } + } catch (Exception e) { + LOG.error("Error provisioning resources", e); + error(getString(Constants.ERROR) + ": " + e.getMessage()); + feedbackPanel.refresh(target); + } + } + }.feedbackPanelAutomaticReload(false); + + pwdMgtForm.addOrReplace(goon); + + table.setVisible(false); + pwdMgtForm.setVisible(true).setEnabled(true); + + target.add(table); + target.add(pwdMgt); + } + + private void loadBulkActionResultPage( + final Collection selection, final BulkActionResult bulkActionResult) { + final List resources = new ArrayList(selection.size()); + for (StatusBean statusBean : selection) { + resources.add(statusBean.getResourceName()); + } + + final List connObjects = + statusUtils.getConnectorObjects(Collections.singletonList(anyTO), resources); + + final List statusBeans = new ArrayList(connObjects.size()); + + for (ConnObjectWrapper entry : connObjects) { + final StatusBean statusBean = statusUtils.getStatusBean(anyTO, + entry.getResourceName(), + entry.getConnObjectTO(), + anyTO instanceof GroupTO); + + statusBeans.add(statusBean); + } + + setResponsePage(new BulkActionResultModalPage( + window, + statusBeans, + columns, + bulkActionResult, + "resourceName")); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceSecurityPanel.java ---------------------------------------------------------------------- diff --cc client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceSecurityPanel.java index a0a1ddc,0000000..89b856a mode 100644,000000..100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceSecurityPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceSecurityPanel.java @@@ -1,186 -1,0 +1,186 @@@ +/* + * 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.panels; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import org.apache.syncope.client.console.rest.PolicyRestClient; +import org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel; +import org.apache.syncope.common.lib.policy.AbstractPolicyTO; +import org.apache.syncope.common.lib.to.ResourceTO; +import org.apache.syncope.common.lib.types.PolicyType; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.panel.Panel; +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; + +public class ResourceSecurityPanel extends Panel { + + private static final long serialVersionUID = -7982691107029848579L; + + @SpringBean + private PolicyRestClient policyRestClient; + + private IModel> passwordPolicies = null; + + private IModel> accountPolicies = null; + + private IModel> syncPolicies = null; + + public ResourceSecurityPanel(final String id, final ResourceTO resourceTO) { + + super(id); + + setOutputMarkupId(true); + + passwordPolicies = new LoadableDetachableModel>() { + + private static final long serialVersionUID = 5275935387613157437L; + + @Override + protected Map load() { + Map res = new HashMap<>(); + for (AbstractPolicyTO policyTO : policyRestClient.getPolicies(PolicyType.PASSWORD)) { + res.put(policyTO.getKey(), policyTO.getDescription()); + } + return res; + } + }; + + accountPolicies = new LoadableDetachableModel>() { + + private static final long serialVersionUID = -2012833443695917883L; + + @Override + protected Map load() { + Map res = new HashMap<>(); + for (AbstractPolicyTO policyTO : policyRestClient.getPolicies(PolicyType.ACCOUNT)) { + res.put(policyTO.getKey(), policyTO.getDescription()); + } + return res; + } + }; + + syncPolicies = new LoadableDetachableModel>() { + + private static final long serialVersionUID = -2012833443695917883L; + + @Override + protected Map load() { + Map res = new HashMap<>(); + for (AbstractPolicyTO policyTO : policyRestClient.getPolicies(PolicyType.SYNC)) { + res.put(policyTO.getKey(), policyTO.getDescription()); + } + return res; + } + }; + + final WebMarkupContainer securityContainer = new WebMarkupContainer("security"); + + securityContainer.setOutputMarkupId(true); + add(securityContainer); + + // ------------------------------- + // Password policy specification + // ------------------------------- + final AjaxDropDownChoicePanel passwordPolicy = new AjaxDropDownChoicePanel("passwordPolicy", + new ResourceModel("passwordPolicy", "passwordPolicy").getObject(), new PropertyModel(resourceTO, + "passwordPolicy")); + + passwordPolicy.setChoiceRenderer(new PolicyRenderer(PolicyType.PASSWORD)); + + passwordPolicy.setChoices(new ArrayList<>(passwordPolicies.getObject().keySet())); + + ((DropDownChoice) passwordPolicy.getField()).setNullValid(true); + + securityContainer.add(passwordPolicy); + // ------------------------------- + + // ------------------------------- + // Account policy specification + // ------------------------------- + final AjaxDropDownChoicePanel accountPolicy = new AjaxDropDownChoicePanel("accountPolicy", + new ResourceModel("accountPolicy", "accountPolicy").getObject(), new PropertyModel(resourceTO, + "accountPolicy")); + + accountPolicy.setChoiceRenderer(new PolicyRenderer(PolicyType.ACCOUNT)); + + accountPolicy.setChoices(new ArrayList(accountPolicies.getObject().keySet())); + + ((DropDownChoice) accountPolicy.getField()).setNullValid(true); + + securityContainer.add(accountPolicy); + // ------------------------------- + + // ------------------------------- + // Sync policy specification + // ------------------------------- + final AjaxDropDownChoicePanel syncPolicy = new AjaxDropDownChoicePanel("syncPolicy", + new ResourceModel("syncPolicy", "syncPolicy").getObject(), new PropertyModel(resourceTO, + "syncPolicy")); + + syncPolicy.setChoiceRenderer(new PolicyRenderer(PolicyType.SYNC)); + + syncPolicy.setChoices(new ArrayList(syncPolicies.getObject().keySet())); + + ((DropDownChoice) syncPolicy.getField()).setNullValid(true); + + securityContainer.add(syncPolicy); + // ------------------------------- + } + + private class PolicyRenderer extends ChoiceRenderer { + + private static final long serialVersionUID = 8060500161321947000L; + + private PolicyType type; + - public PolicyRenderer(final PolicyType type) { ++ PolicyRenderer(final PolicyType type) { + super(); + this.type = type; + } + + @Override + public Object getDisplayValue(final Long object) { + switch (type) { + case ACCOUNT: + return accountPolicies.getObject().get(object); + case PASSWORD: + return passwordPolicies.getObject().get(object); + case SYNC: + return syncPolicies.getObject().get(object); + default: + return ""; + } + } + + @Override + public String getIdValue(final Long object, final int index) { + return String.valueOf(object != null + ? object + : 0L); + } + }; +}