syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [1/2] syncope git commit: refactoring to manage the command line parameters without external library, SYNCOPE-158
Date Wed, 14 Oct 2015 13:08:16 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 2f137b211 -> 4a28d6c83


refactoring to manage the command line parameters without external library, SYNCOPE-158


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/729cf5b3
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/729cf5b3
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/729cf5b3

Branch: refs/heads/master
Commit: 729cf5b3206435a2526e92cea759f249e964ce9d
Parents: 009a87e
Author: massi <massimiliano.perrone@tirasa.net>
Authored: Wed Oct 14 15:07:25 2015 +0200
Committer: massi <massimiliano.perrone@tirasa.net>
Committed: Wed Oct 14 15:07:25 2015 +0200

----------------------------------------------------------------------
 client/cli/pom.xml                              |  15 ++-
 .../apache/syncope/client/cli/ArgsManager.java  |  50 +++++++
 .../syncope/client/cli/AvailableServices.java   |  31 +++++
 .../org/apache/syncope/client/cli/Command.java  |  32 +++++
 .../syncope/client/cli/CommandClassScanner.java |  29 ++++
 .../client/cli/ComponentClassScanner.java       |  44 ++++++
 .../org/apache/syncope/client/cli/Input.java    | 134 +++++++++++++++++++
 .../apache/syncope/client/cli/SyncopeAdm.java   |  86 +++---------
 .../syncope/client/cli/SyncopeServices.java     |  32 ++++-
 .../client/cli/util/FileSystemUtils.java        |  48 +++++++
 .../syncope/client/cli/util/JasyptUtils.java    |  49 +++++++
 .../cli/validators/DebugLevelValidator.java     |  60 ---------
 .../src/main/resources/configuration.properties |  18 +++
 client/cli/src/main/resources/log4j2.xml        |  24 +++-
 .../cli/src/main/resources/syncope.properties   |  19 ---
 pom.xml                                         |   7 -
 16 files changed, 508 insertions(+), 170 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/pom.xml
----------------------------------------------------------------------
diff --git a/client/cli/pom.xml b/client/cli/pom.xml
index 36ee452..d68c6a1 100644
--- a/client/cli/pom.xml
+++ b/client/cli/pom.xml
@@ -40,10 +40,6 @@ under the License.
   </properties>
   
   <dependencies>
-    <dependency>
-      <groupId>com.beust</groupId>
-      <artifactId>jcommander</artifactId>
-    </dependency>
     
     <dependency>
       <groupId>org.apache.syncope.client</groupId>
@@ -52,6 +48,15 @@ under the License.
     </dependency>
     
     <dependency>
+      <groupId>org.jasypt</groupId>
+      <artifactId>jasypt</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+    </dependency>
+    
+    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
@@ -117,7 +122,7 @@ under the License.
               <transformers>
                 <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                   <manifestEntries>
-                    <Main-Class>org.apache.syncope.cli.SyncopeAdm</Main-Class>
+                    <Main-Class>org.apache.syncope.client.cli.SyncopeAdm</Main-Class>
                   </manifestEntries>
                 </transformer>
                 <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/ArgsManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/ArgsManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/ArgsManager.java
new file mode 100644
index 0000000..f323dce
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/ArgsManager.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import java.io.File;
+import org.apache.syncope.client.cli.commands.install.InstallConfigFileTemplate;
+
+public final class ArgsManager {
+
+    public static void validator(final String[] args) throws IllegalArgumentException {
+        if (args.length == 0) {
+            throw new IllegalArgumentException();
+        } else if (!"install".equalsIgnoreCase(args[0])) {
+            final File configFile = new File(InstallConfigFileTemplate.FILE_PATH);
+            if (!configFile.exists()) {
+                throw new IllegalArgumentException(
+                        "It seems you need to setup the CLI client before. Run install --setup.");
+            }
+        }
+    }
+
+    public static String[] operands(final String[] args) {
+        final String[] operands = new String[args.length - 1];
+        for (int i = 1; i < args.length; i++) {
+            operands[i - 1] = args[i];
+        }
+        return operands;
+    }
+
+    private ArgsManager() {
+        // private constructor for static utility class
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/AvailableServices.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/AvailableServices.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/AvailableServices.java
new file mode 100644
index 0000000..7d326a8
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/AvailableServices.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+public enum AvailableServices {
+
+    logger,
+    config,
+    notification,
+    report,
+    policy,
+    entitlement,
+    schema;
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/Command.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/Command.java b/client/cli/src/main/java/org/apache/syncope/client/cli/Command.java
new file mode 100644
index 0000000..2c36dd8
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/Command.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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = ElementType.TYPE)
+public @interface Command {
+
+    String name();
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/CommandClassScanner.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/CommandClassScanner.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/CommandClassScanner.java
new file mode 100644
index 0000000..e19f024
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/CommandClassScanner.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+import org.springframework.core.type.filter.AnnotationTypeFilter;
+
+public class CommandClassScanner extends ComponentClassScanner {
+
+    public CommandClassScanner() {
+        super();
+        addIncludeFilter(new AnnotationTypeFilter(Command.class));
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/ComponentClassScanner.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/ComponentClassScanner.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/ComponentClassScanner.java
new file mode 100644
index 0000000..c344596
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/ComponentClassScanner.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.util.ClassUtils;
+
+public abstract class ComponentClassScanner<T> extends ClassPathScanningCandidateComponentProvider
{
+
+    public ComponentClassScanner() {
+        super(false);
+    }
+
+    @SuppressWarnings("unchecked")
+    public final List<Class<? extends T>> getComponentClasses() throws IllegalArgumentException
{
+        final String basePackage = "org.apache.syncope.client.cli.commands";
+        List<Class<? extends T>> classes = new ArrayList<>();
+        for (final BeanDefinition candidate : findCandidateComponents(basePackage)) {
+            final Class cls = ClassUtils.
+                    resolveClassName(candidate.getBeanClassName(), ClassUtils.getDefaultClassLoader());
+            classes.add((Class) cls);
+        }
+        return classes;
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java b/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
new file mode 100644
index 0000000..a7092e7
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/Input.java
@@ -0,0 +1,134 @@
+/*
+ * 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;
+
+import java.util.List;
+import org.apache.syncope.client.cli.commands.AbstractCommand;
+
+public class Input {
+
+    private boolean ssl = false;
+
+    private String host = "localhost";
+
+    private String port = "9080";
+
+    private String username = "admin";
+
+    private String password = "password";
+
+    private final AbstractCommand command;
+
+    private String option;
+
+    private final String[] parameters;
+
+    public Input(final String[] args)
+            throws InstantiationException, IllegalAccessException, IllegalArgumentException
{
+
+        command = fromArgs(args[0]);
+
+        if (args.length > 1) {
+            option = args[1];
+        }
+
+        if (args.length > 2) {
+            parameters = new String[args.length - 2];
+            for (int i = 0; i < parameters.length; i++) {
+                parameters[i] = args[i + 2];
+            }
+        } else {
+            parameters = new String[0];
+        }
+    }
+
+    public AbstractCommand getCommand() {
+        return command;
+    }
+
+    public void setOption(final String option) {
+        this.option = option;
+    }
+
+    public String getOption() {
+        return option;
+    }
+
+    public String[] getParameters() {
+        return parameters;
+    }
+
+    public String firstParameter() {
+        return parameters[0];
+    }
+    
+    public String lastParameter() {
+        return parameters[parameters.length - 1];
+    }
+
+    public PairParameter toPairParameter(final String parameter) throws IllegalArgumentException
{
+        if (!parameter.contains("=")) {
+            throw new IllegalArgumentException("Parameter syntax error!");
+        }
+        final String[] pairParameterArray = parameter.split("=");
+        return new PairParameter(pairParameterArray[0], pairParameterArray[1]);
+    }
+
+    private AbstractCommand fromArgs(final String arg)
+            throws InstantiationException, IllegalAccessException, IllegalArgumentException
{
+
+        final CommandClassScanner ccs = new CommandClassScanner();
+        final List<Class<? extends AbstractCommand>> commands = ccs.getComponentClasses();
+
+        Class<? extends AbstractCommand> commandClass = null;
+        for (Class<? extends AbstractCommand> cmd : commands) {
+            if (arg.equals(cmd.getAnnotation(Command.class).name())) {
+                commandClass = cmd;
+            }
+        }
+
+        if (commandClass == null) {
+            throw new IllegalArgumentException();
+        }
+
+        return commandClass.newInstance();
+
+    }
+
+    public class PairParameter {
+
+        private final String key;
+
+        private final String value;
+
+        public PairParameter(final String key, final String value) {
+            this.key = key;
+            this.value = value;
+        }
+
+        public String getKey() {
+            return key;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
index c7e94ff..2f762e7 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
@@ -18,13 +18,7 @@
  */
 package org.apache.syncope.client.cli;
 
-import com.beust.jcommander.JCommander;
-import com.beust.jcommander.ParameterException;
-import org.apache.syncope.client.cli.commands.ConfigurationCommand;
-import org.apache.syncope.client.cli.commands.LoggerCommand;
-import org.apache.syncope.client.cli.commands.NotificationCommand;
-import org.apache.syncope.client.cli.commands.PolicyCommand;
-import org.apache.syncope.client.cli.commands.ReportCommand;
+import org.apache.syncope.client.cli.commands.AbstractCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,80 +33,32 @@ public final class SyncopeAdm {
             + "    notification --help \n"
             + "    report --help \n"
             + "    policy --help \n"
-            + "    entitlement --help \n";
-
-    private static final JCommander JCOMMANDER = new JCommander();
-
-    private static LoggerCommand LOGGER_COMMAND;
-
-    private static ConfigurationCommand CONFIGURATION_COMMAND;
-
-    private static NotificationCommand NOTIFICATION_COMMAND;
-
-    private static ReportCommand REPORT_COMMAND;
-
-    private static PolicyCommand POLICY_COMMAND;
+            + "    entitlement --help \n"
+            + "    schema --help \n";
 
     public static void main(final String[] args) {
         LOG.debug("Starting with args \n");
 
-        for (final String arg : args) {
-            LOG.debug("Arg: {}", arg);
-        }
-
-        instantiateCommands();
-
-        if (args.length == 0) {
+        try {
+            ArgsManager.validator(args);
+            final Input input = new Input(args);
+            final AbstractCommand command = input.getCommand();
+            command.execute(input);
+        } catch (final IllegalAccessException | InstantiationException e) {
+            LOG.error("Error in main", e);
+            e.printStackTrace();
             System.out.println(HELP_MESSAGE);
-        } else {
-            try {
-                JCOMMANDER.parse(args);
-            } catch (final ParameterException ioe) {
+        } catch (final IllegalArgumentException ex) {
+            LOG.error("Error in main", ex);
+            if (ex.getMessage().startsWith("It seems you need to setup")) {
+                System.out.println(ex.getMessage());
+            } else {
                 System.out.println(HELP_MESSAGE);
-                LOG.error("Parameter exception", ioe);
             }
-            executeCommand();
         }
 
     }
 
-    private static void instantiateCommands() {
-        LOG.debug("Init JCommander");
-        LOGGER_COMMAND = new LoggerCommand();
-        JCOMMANDER.addCommand(LOGGER_COMMAND);
-        LOG.debug("Added LoggerCommand");
-        CONFIGURATION_COMMAND = new ConfigurationCommand();
-        JCOMMANDER.addCommand(CONFIGURATION_COMMAND);
-        LOG.debug("Added ConfigurationCommand");
-        NOTIFICATION_COMMAND = new NotificationCommand();
-        JCOMMANDER.addCommand(NOTIFICATION_COMMAND);
-        LOG.debug("Added NotificationCommand");
-        REPORT_COMMAND = new ReportCommand();
-        JCOMMANDER.addCommand(REPORT_COMMAND);
-        LOG.debug("Added ReportCommand");
-        POLICY_COMMAND = new PolicyCommand();
-        JCOMMANDER.addCommand(POLICY_COMMAND);
-        LOG.debug("Added PolicyCommand");
-    }
-
-    private static void executeCommand() {
-        final String command = JCOMMANDER.getParsedCommand();
-
-        LOG.debug("Called command {}", command);
-
-        if ("logger".equalsIgnoreCase(command)) {
-            LOGGER_COMMAND.execute();
-        } else if ("config".equalsIgnoreCase(command)) {
-            CONFIGURATION_COMMAND.execute();
-        } else if ("notification".equalsIgnoreCase(command)) {
-            NOTIFICATION_COMMAND.execute();
-        } else if ("report".equalsIgnoreCase(command)) {
-            REPORT_COMMAND.execute();
-        } else if ("policy".equalsIgnoreCase(command)) {
-            POLICY_COMMAND.execute();
-        }
-    }
-
     private SyncopeAdm() {
         // private constructor for static utility class
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
index cde37b8..0fc5b33 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
@@ -18,7 +18,11 @@
  */
 package org.apache.syncope.client.cli;
 
-import java.util.ResourceBundle;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import org.apache.syncope.client.cli.commands.install.InstallConfigFileTemplate;
+import org.apache.syncope.client.cli.util.JasyptUtils;
 import org.apache.syncope.client.lib.SyncopeClient;
 import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
 import org.slf4j.Logger;
@@ -28,15 +32,29 @@ public final class SyncopeServices {
 
     private static final Logger LOG = LoggerFactory.getLogger(SyncopeServices.class);
 
-    private static final ResourceBundle SYNCOPE_PROPS = ResourceBundle.getBundle("syncope");
-
-    private static final SyncopeClient CLIENT = new SyncopeClientFactoryBean()
-            .setAddress(SYNCOPE_PROPS.getString("syncope.rest.services"))
-            .create(SYNCOPE_PROPS.getString("syncope.user"), SYNCOPE_PROPS.getString("syncope.password"));
+    private static String SYNCOPE_ADDRESS;
 
     public static <T> T get(final Class<T> claz) {
+        final Properties properties = new Properties();
+        try {
+            properties.load(new FileInputStream(InstallConfigFileTemplate.FILE_PATH));
+        } catch (final IOException e) {
+            LOG.error("Error opening properties file", e);
+        }
+
+        final String syncopeAdminPassword = JasyptUtils.getJasyptUtils().decrypt(properties.getProperty(
+                "syncope.admin.password"));
+        SYNCOPE_ADDRESS = properties.getProperty("syncope.rest.services");
+        final SyncopeClient syncopeClient = new SyncopeClientFactoryBean()
+                .setAddress(SYNCOPE_ADDRESS)
+                .create(properties.getProperty("syncope.admin.user"), syncopeAdminPassword);
+
         LOG.debug("Creting service for {}", claz.getName());
-        return CLIENT.getService(claz);
+        return syncopeClient.getService(claz);
+    }
+
+    public static String getAddress() {
+        return SYNCOPE_ADDRESS;
     }
 
     private SyncopeServices() {

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
new file mode 100644
index 0000000..355e69c
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/util/FileSystemUtils.java
@@ -0,0 +1,48 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+
+public final class FileSystemUtils {
+
+    public static void createNewDirectory(final String directoryToCreate) {
+        final File directory = new File(directoryToCreate);
+        directory.mkdirs();
+    }
+
+    public static void createFileWith(final String filePath, final String content)
+            throws FileNotFoundException, UnsupportedEncodingException {
+        try (PrintWriter writer = new PrintWriter(filePath, "UTF-8")) {
+            writer.println(content);
+        }
+    }
+
+    public static boolean canWrite(final String path) {
+        final File installationDirectory = new File(path);
+        return installationDirectory.canWrite();
+    }
+    
+    private FileSystemUtils() {
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
new file mode 100644
index 0000000..4e4551c
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/util/JasyptUtils.java
@@ -0,0 +1,49 @@
+/*
+ * 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.util;
+
+import org.jasypt.util.text.StrongTextEncryptor;
+
+public final class JasyptUtils {
+
+    private final StrongTextEncryptor textEncryptor;
+
+    private static JasyptUtils JASYPT_UTILS = null;
+
+    public static JasyptUtils getJasyptUtils() {
+        if (JASYPT_UTILS == null) {
+            JASYPT_UTILS = new JasyptUtils();
+        }
+        return JASYPT_UTILS;
+    }
+
+    private JasyptUtils() {
+        textEncryptor = new StrongTextEncryptor();
+        textEncryptor.setPassword("Ka9s8yadaisj9mud87ssdaifansy");
+    }
+
+    public String encrypt(final String password) {
+        return textEncryptor.encrypt(password);
+    }
+
+    public String decrypt(final String encryptedString) {
+        return textEncryptor.decrypt(encryptedString);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java
deleted file mode 100644
index 1ce85f8..0000000
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.validators;
-
-import com.beust.jcommander.IParameterValidator;
-
-public class DebugLevelValidator implements IParameterValidator {
-
-    @Override
-    public void validate(final String name, final String value) {
-        if (!Levels.contains(value)) {
-            final StringBuilder exceptionMessage = new StringBuilder();
-            exceptionMessage.append("Parameter ")
-                    .append(name)
-                    .append(" should be :\n");
-            for (final Levels l : Levels.values()) {
-                exceptionMessage.append(l).append("\n");
-            }
-            System.out.println(">>>> " + exceptionMessage.toString());
-        }
-    }
-
-    private enum Levels {
-
-        OFF,
-        FATAL,
-        ERROR,
-        WARN,
-        INFO,
-        DEBUG,
-        TRACE,
-        ALL;
-
-        public static boolean contains(final String name) {
-            for (final Levels c : Levels.values()) {
-                if (c.name().equals(name)) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/resources/configuration.properties
----------------------------------------------------------------------
diff --git a/client/cli/src/main/resources/configuration.properties b/client/cli/src/main/resources/configuration.properties
new file mode 100644
index 0000000..245a781
--- /dev/null
+++ b/client/cli/src/main/resources/configuration.properties
@@ -0,0 +1,18 @@
+# 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.
+cli.installation.directory=/var/tmp/syncope/conf/
+cli.installation.filename=cli.properties

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/resources/log4j2.xml
----------------------------------------------------------------------
diff --git a/client/cli/src/main/resources/log4j2.xml b/client/cli/src/main/resources/log4j2.xml
index 0688f6b..fce9c8b 100644
--- a/client/cli/src/main/resources/log4j2.xml
+++ b/client/cli/src/main/resources/log4j2.xml
@@ -41,15 +41,35 @@ under the License.
       <appender-ref ref="main"/>
     </asyncLogger>
     
-    <asyncLogger name="org.apache.syncope.cli" additivity="false" level="DEBUG">
+    <asyncLogger name="org.apache.cxf" additivity="false" level="OFF">
+      <appender-ref ref="main"/>
+    </asyncLogger>
+    
+    <asyncLogger name="org.apache.cxf.interceptor" additivity="false" level="OFF">
+      <appender-ref ref="main"/>
+    </asyncLogger>
+    
+    <asyncLogger name="org.apache.http" additivity="false" level="OFF">
+      <appender-ref ref="main"/>
+    </asyncLogger>
+    
+    <asyncLogger name="org.springframework" additivity="false" level="OFF">
+      <appender-ref ref="main"/>
+    </asyncLogger>
+    
+    <asyncLogger name="org.apache.syncope.cli" additivity="false" level="OFF">
       <appender-ref ref="main"/>
     </asyncLogger>
     
     <asyncLogger name="org.apache.syncope.client" additivity="false" level="OFF">
       <appender-ref ref="main"/>
     </asyncLogger>
+    
+    <asyncLogger name="org.apache.syncope.common" additivity="false" level="OFF">
+      <appender-ref ref="main"/>
+    </asyncLogger>
 
-    <root level="DEBUG">
+    <root level="OFF">
       <appender-ref ref="main"/>
     </root>
   

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/client/cli/src/main/resources/syncope.properties
----------------------------------------------------------------------
diff --git a/client/cli/src/main/resources/syncope.properties b/client/cli/src/main/resources/syncope.properties
deleted file mode 100644
index 9f84a72..0000000
--- a/client/cli/src/main/resources/syncope.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-# 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.
-syncope.rest.services=http://localhost:9080/syncope/rest/
-syncope.user=admin
-syncope.password=password

http://git-wip-us.apache.org/repos/asf/syncope/blob/729cf5b3/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f99066d..f12e9b5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -999,13 +999,6 @@ under the License.
         <artifactId>jquery-cookie</artifactId>
         <version>${jquery-cookie.version}</version>
       </dependency>
-
-            
-      <dependency>
-        <groupId>com.beust</groupId>
-        <artifactId>jcommander</artifactId>
-        <version>1.47</version>
-      </dependency>
       
       <dependency>
         <groupId>org.codehaus.izpack</groupId>


Mime
View raw message