[java-identity-provider] 03/03: IDP-1595 Start to build command line utility for plugins

Rod Widdowson rdw at steadingsoftware.com
Thu Jul 30 10:40:14 UTC 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=819f42581806827a4ae4b5e010d89cc0b0004cb8

commit 819f42581806827a4ae4b5e010d89cc0b0004cb8
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 30 11:36:58 2020 +0100

    IDP-1595  Start to build command line utility for plugins
    
    https://issues.shibboleth.net/jira/browse/IDP-1595
    
    Infrastructure only right now.  The function consists of list the
    contents of the %{idp.home}/conf
---
 .../main/resources/conf/admin/plugin-installer.xml |  15 ++
 idp-distribution/src/main/resources/bin/plugin.bat |   4 +
 idp-distribution/src/main/resources/bin/plugin.sh  |   7 +
 idp-installer/pom.xml                              |  11 ++
 .../installer/plugin/PluginInstallerArguments.java |  27 ++++
 .../idp/installer/plugin/PluginInstallerCLI.java   | 151 +++++++++++++++++++++
 .../idp/installer/plugin/package-info.java         |  21 +++
 .../idp/installer/plugin/patchResources.xml        |  22 +++
 8 files changed, 258 insertions(+)

diff --git a/idp-conf/src/main/resources/conf/admin/plugin-installer.xml b/idp-conf/src/main/resources/conf/admin/plugin-installer.xml
new file mode 100644
index 000000000..168c74771
--- /dev/null
+++ b/idp-conf/src/main/resources/conf/admin/plugin-installer.xml
@@ -0,0 +1,15 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:context="http://www.springframework.org/schema/context"
+    xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
+    xmlns:c="http://www.springframework.org/schema/c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+                        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+
+    default-init-method="initialize"
+    default-destroy-method="destroy">
+
+    <!-- 
+    <bean id=" MyHttpClient" parent="shibboleth.HttpClientFactory"/>
+    --> 
+</beans>
\ No newline at end of file
diff --git a/idp-distribution/src/main/resources/bin/plugin.bat b/idp-distribution/src/main/resources/bin/plugin.bat
new file mode 100644
index 000000000..3cfd34200
--- /dev/null
+++ b/idp-distribution/src/main/resources/bin/plugin.bat
@@ -0,0 +1,4 @@
+ at echo off
+setlocal
+
+"%~dp0\runclass.bat" net.shibboleth.idp.installer.plugin.PluginInstallerCLI "%~dp0\..\conf\admin\plugin-installer.xml" %*
diff --git a/idp-distribution/src/main/resources/bin/plugin.sh b/idp-distribution/src/main/resources/bin/plugin.sh
new file mode 100644
index 000000000..4753c4068
--- /dev/null
+++ b/idp-distribution/src/main/resources/bin/plugin.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+declare LOCATION
+
+LOCATION=$(dirname $0)
+
+$LOCATION/runclass.sh net.shibboleth.idp.installer.plugin.PluginInstallerCLI $LOCATION/../conf/admin/plugin-installer.xml "$@"
diff --git a/idp-installer/pom.xml b/idp-installer/pom.xml
index f36378999..88b883e23 100644
--- a/idp-installer/pom.xml
+++ b/idp-installer/pom.xml
@@ -49,6 +49,17 @@
             <artifactId>idp-saml-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>idp-profile-spring</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>net.shibboleth.ext</groupId>
+            <artifactId>spring-extensions</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>net.shibboleth.utilities</groupId>
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
new file mode 100644
index 000000000..8c81e1e3b
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.idp.installer.plugin;
+
+import net.shibboleth.ext.spring.cli.AbstractCommandLineArguments;
+
+/**
+ * Arguments for Plugin Installer CLI.
+ */
+public class PluginInstallerArguments extends AbstractCommandLineArguments {
+
+}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
new file mode 100644
index 000000000..23383e4f0
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.idp.installer.plugin;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+import net.shibboleth.ext.spring.cli.AbstractCommandLine;
+import net.shibboleth.idp.Version;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/**
+ * Command line for Plugin Installation.
+ */
+public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstallerArguments> {
+
+    /** Class logger. */
+    @Nullable private Logger log;
+    
+    /** Where the IdP is installed to. */
+    @Nullable private Path idpHome;
+    
+    /**
+     * Constrained Constructor.
+     */
+    private PluginInstallerCLI() {
+    }
+
+    /** Set where the IdP is installed to.
+     * @param home where
+     */
+    protected void setIdpHome(@Nullable final String home) {
+        if (home == null) {
+            getLogger().error("net.shibboleth.idp.cli.idp.home propert not send.  Could not find IdP Home directory");
+            return;
+        }
+        idpHome = Path.of(home);
+        
+        if (!Files.exists(idpHome) || !Files.isDirectory(idpHome)) {
+            getLogger().error("IdP Home Directory {} did not exist or was not a directory", idpHome);
+            idpHome = null;
+        }
+    }
+    
+    /** Return where the IdP is installed to.
+     * @return the home directory.
+     */
+    @Nullable protected Path getIdpHome() {
+        return idpHome;
+    }
+
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull protected Logger getLogger() {
+        if (log == null) {
+            log = LoggerFactory.getLogger(PluginInstallerCLI.class);
+        }
+        return log;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected Class<PluginInstallerArguments> getArgumentClass() {
+        return PluginInstallerArguments.class;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected String getVersion() {
+        return Version.getVersion();
+    }
+    
+    /** {@inheritDoc} */
+    protected List<Resource> getAdditionalSpringResources() {
+        return List.of(
+                new ClassPathResource("net/shibboleth/idp/installer/plugin/patchResources.xml"),
+                new FileSystemResource(idpHome.resolve("conf").resolve("global.xml")));
+    }
+    
+    /** {@inheritDoc} */
+    protected int doRun(final PluginInstallerArguments args) {
+        getLogger().warn("Starting");
+        final int ret = super.doRun(args);
+        if (ret != RC_OK) {
+            return ret;
+        }
+        try {
+            Files.walkFileTree(getIdpHome().resolve("conf"), new SimpleFileVisitor<Path>() {
+                @Override 
+                public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
+                    getLogger().warn("File {}",file);
+                    return FileVisitResult.CONTINUE;
+                }
+                @Override 
+                public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
+                    getLogger().warn("Dire {}",dir);
+                    return FileVisitResult.CONTINUE;
+                }
+            });
+        } catch (final IOException e) {
+            getLogger().error("oops", e);
+            return RC_IO;
+        } 
+        return ret;
+    }
+    
+    /**
+     * CLI entry point.
+     * @param args arguments
+     */
+    public static void main(@Nonnull final String[] args) {
+        final PluginInstallerCLI cli = new PluginInstallerCLI();
+        cli.setIdpHome(StringSupport.trimOrNull(System.getProperty("net.shibboleth.idp.cli.idp.home")));
+        if (cli.getIdpHome() == null) {
+            System.exit(RC_INIT);
+        } else {
+            System.exit(cli.run(args));
+        }
+    }
+
+}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/package-info.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/package-info.java
new file mode 100644
index 000000000..e55aa839e
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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.
+ */
+/**
+ * Public Classes for handling plugins.
+ */
+package net.shibboleth.idp.installer.plugin;
+
diff --git a/idp-installer/src/main/resources/net/shibboleth/idp/installer/plugin/patchResources.xml b/idp-installer/src/main/resources/net/shibboleth/idp/installer/plugin/patchResources.xml
new file mode 100644
index 000000000..5b7e54264
--- /dev/null
+++ b/idp-installer/src/main/resources/net/shibboleth/idp/installer/plugin/patchResources.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xmlns:p="http://www.springframework.org/schema/p"
+       xmlns:c="http://www.springframework.org/schema/c"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+
+       default-init-method="initialize"
+       default-destroy-method="destroy">
+
+    <bean id="shibboleth.HttpClientFactory" abstract="true"
+        class="net.shibboleth.idp.profile.spring.relyingparty.metadata.HttpClientFactoryBean" />
+    <bean id="shibboleth.FileCachingHttpClientFactory" abstract="true"
+        class="net.shibboleth.idp.profile.spring.relyingparty.metadata.FileCachingHttpClientFactoryBean" />
+    <bean id="shibboleth.MemoryCachingHttpClientFactory" abstract="true"
+        class="net.shibboleth.idp.profile.spring.relyingparty.metadata.InMemoryCachingHttpClientFactoryBean" />
+    
+</beans>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list