You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by ma...@apache.org on 2015/10/28 10:28:36 UTC
syncope git commit: Fixed SYNCOPE-589
Repository: syncope
Updated Branches:
refs/heads/master 47b9f64bd -> 74e867e8c
Fixed SYNCOPE-589
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/74e867e8
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/74e867e8
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/74e867e8
Branch: refs/heads/master
Commit: 74e867e8ccde9d184b7986b8329907ef51e4372b
Parents: 47b9f64
Author: massi <ma...@tirasa.net>
Authored: Wed Oct 28 10:27:58 2015 +0100
Committer: massi <ma...@tirasa.net>
Committed: Wed Oct 28 10:27:58 2015 +0100
----------------------------------------------------------------------
.../cli/commands/role/AbstractRoleCommand.java | 27 +++++
.../client/cli/commands/role/RoleCommand.java | 109 +++++++++++++++++++
.../client/cli/commands/role/RoleDelete.java | 57 ++++++++++
.../client/cli/commands/role/RoleList.java | 32 ++++++
.../client/cli/commands/role/RoleRead.java | 61 +++++++++++
.../cli/commands/role/RoleResultManager.java | 57 ++++++++++
.../commands/role/RoleSyncopeOperations.java | 42 +++++++
.../client/cli/commands/user/UserRead.java | 7 +-
8 files changed, 389 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
new file mode 100644
index 0000000..b4709a0
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
@@ -0,0 +1,27 @@
+/*
+ * 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.role;
+
+public class AbstractRoleCommand {
+
+ protected RoleSyncopeOperations roleSyncopeOperations = new RoleSyncopeOperations();
+
+ protected RoleResultManager roleResultManager = new RoleResultManager();
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleCommand.java
new file mode 100644
index 0000000..bb2f988
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleCommand.java
@@ -0,0 +1,109 @@
+/*
+ * 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.role;
+
+import java.util.ArrayList;
+import java.util.List;
+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.commands.AbstractCommand;
+
+@Command(name = "role")
+public class RoleCommand extends AbstractCommand {
+
+ private static final String HELP_MESSAGE = "Usage: role [options]\n"
+ + " Options:\n"
+ + " --help \n"
+ + " --list \n"
+ + " --read \n"
+ + " Syntax: --read {ROLE-ID} {ROLE-ID} [...]"
+ + " --delete \n"
+ + " Syntax: --delete {ROLE-ID} {ROLE-ID} [...]";
+
+ @Override
+ public void execute(final Input input) {
+ if (StringUtils.isBlank(input.getOption())) {
+ input.setOption(RoleOptions.HELP.getOptionName());
+ }
+
+ switch (RoleOptions.fromName(input.getOption())) {
+ case LIST:
+ new RoleList().list();
+ break;
+ case READ:
+ new RoleRead(input).read();
+ break;
+ case DELETE:
+ new RoleDelete(input).delete();
+ break;
+ case HELP:
+ System.out.println(HELP_MESSAGE);
+ break;
+ default:
+ new RoleResultManager().defaultError(input.getOption(), HELP_MESSAGE);
+ }
+ }
+
+ @Override
+ public String getHelpMessage() {
+ return HELP_MESSAGE;
+ }
+
+ private enum RoleOptions {
+
+ HELP("--help"),
+ LIST("--list"),
+ READ("--read"),
+ DELETE("--delete");
+
+ private final String optionName;
+
+ RoleOptions(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 RoleOptions fromName(final String name) {
+ RoleOptions optionToReturn = HELP;
+ for (final RoleOptions option : RoleOptions.values()) {
+ if (option.equalsOptionName(name)) {
+ optionToReturn = option;
+ }
+ }
+ return optionToReturn;
+ }
+
+ public static List<String> toList() {
+ final List<String> options = new ArrayList<>();
+ for (final RoleOptions value : values()) {
+ options.add(value.getOptionName());
+ }
+ return options;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
new file mode 100644
index 0000000..50ac248
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
@@ -0,0 +1,57 @@
+/*
+ * 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.role;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class RoleDelete extends AbstractRoleCommand {
+
+ private static final String DELETE_HELP_MESSAGE = "role --delete {ROLE-ID} {ROLE-ID} [...]";
+
+ private final Input input;
+
+ public RoleDelete(final Input input) {
+ this.input = input;
+ }
+
+ public void delete() {
+ if (input.getParameters().length >= 1) {
+ for (final String parameter : input.getParameters()) {
+ try {
+ roleSyncopeOperations.delete(parameter);
+ roleResultManager.deletedMessage("role", parameter);
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ roleResultManager.notFoundError("Role", parameter);
+ } else {
+ roleResultManager.generic("Error: " + ex.getMessage());
+ }
+ break;
+ } catch (final NumberFormatException ex) {
+ roleResultManager.numberFormatException("user", parameter);
+ }
+ }
+ } else {
+ roleResultManager.commandOptionError(DELETE_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleList.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleList.java
new file mode 100644
index 0000000..e87b1c2
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleList.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.cli.commands.role;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class RoleList extends AbstractRoleCommand {
+
+ public void list() {
+ try {
+ roleResultManager.toView(roleSyncopeOperations.list());
+ } catch (final SyncopeClientException ex) {
+ roleResultManager.generic(ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleRead.java
new file mode 100644
index 0000000..2a0393f
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleRead.java
@@ -0,0 +1,61 @@
+/*
+ * 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.role;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.RoleTO;
+
+public class RoleRead extends AbstractRoleCommand {
+
+ private static final String READ_HELP_MESSAGE = "role --read {ROLE-ID} {ROLE-ID} [...]";
+
+ private final Input input;
+
+ public RoleRead(final Input input) {
+ this.input = input;
+ }
+
+ public void read() {
+ if (input.getParameters().length >= 1) {
+ final List<RoleTO> roleTOs = new ArrayList<>();
+ for (final String parameter : input.getParameters()) {
+ try {
+ roleTOs.add(roleSyncopeOperations.read(parameter));
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ roleResultManager.notFoundError("Role", parameter);
+ } else {
+ roleResultManager.generic("Error: " + ex.getMessage());
+ }
+ break;
+ } catch (final NumberFormatException ex) {
+ roleResultManager.numberFormatException("user", parameter);
+ }
+ }
+ roleResultManager.toView(roleTOs);
+ } else {
+ roleResultManager.commandOptionError(READ_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleResultManager.java
new file mode 100644
index 0000000..a672d53
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleResultManager.java
@@ -0,0 +1,57 @@
+/*
+ * 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.role;
+
+import java.util.List;
+import java.util.Set;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+import org.apache.syncope.common.lib.to.RoleTO;
+
+public class RoleResultManager extends CommonsResultManager {
+
+ public void toView(final List<RoleTO> roleTOs) {
+ for (final RoleTO roleTO : roleTOs) {
+ printRole(roleTO);
+ }
+ System.out.println("");
+ }
+
+ private void printRole(final RoleTO roleTO) {
+ System.out.println(" > ROLE ID: " + roleTO.getKey());
+ System.out.println(" name: " + roleTO.getName());
+ System.out.println(" REALMS: ");
+ printRealms(roleTO.getRealms());
+ System.out.println(" ENTITLEMENTS:");
+ printEntitlements(roleTO.getEntitlements());
+ System.out.println(" dynamic membership condition: " + roleTO.getDynMembershipCond());
+ System.out.println("");
+ }
+
+ private void printRealms(final List<String> realms) {
+ for (final String realm : realms) {
+ System.out.println(" - " + realm);
+ }
+ }
+
+ private void printEntitlements(final Set<String> entitlements) {
+ for (final String entitlement : entitlements) {
+ System.out.println(" - " + entitlement);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleSyncopeOperations.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleSyncopeOperations.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleSyncopeOperations.java
new file mode 100644
index 0000000..c24c3e9
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleSyncopeOperations.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.cli.commands.role;
+
+import java.util.List;
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.common.lib.to.RoleTO;
+import org.apache.syncope.common.rest.api.service.RoleService;
+
+public class RoleSyncopeOperations {
+
+ private final RoleService roleService = SyncopeServices.get(RoleService.class);
+
+ public List<RoleTO> list() {
+ return roleService.list();
+ }
+
+ public RoleTO read(final String roleId) {
+ return roleService.read(Long.valueOf(roleId));
+ }
+
+ public void delete(final String roleId) {
+ roleService.delete(Long.valueOf(roleId));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/74e867e8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserRead.java
index ae94409..8fd9144 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserRead.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserRead.java
@@ -18,7 +18,8 @@
*/
package org.apache.syncope.client.cli.commands.user;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.List;
import javax.xml.ws.WebServiceException;
import org.apache.syncope.client.cli.Input;
import org.apache.syncope.common.lib.SyncopeClientException;
@@ -36,13 +37,13 @@ public class UserRead extends AbstractUserCommand {
public void read() {
if (input.getParameters().length >= 1) {
- final LinkedList<UserTO> userTOs = new LinkedList<>();
+ final List<UserTO> userTOs = new ArrayList<>();
for (final String parameter : input.getParameters()) {
try {
userTOs.add(userSyncopeOperations.read(parameter));
} catch (final SyncopeClientException | WebServiceException ex) {
if (ex.getMessage().startsWith("NotFound")) {
- userResultManager.notFoundError("Logger", parameter);
+ userResultManager.notFoundError("User", parameter);
} else {
userResultManager.generic("Error: " + ex.getMessage());
}