From 5cca5bacb14e284b6017ed293da7e3ee473bd5a8 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Thu, 3 Apr 2014 08:23:08 +0200 Subject: parse ConfigTool version from MANIFEST.MF --- id/ConfigWebTool/pom.xml | 29 ++++++++------ .../moa/id/configuration/Constants.java | 4 +- .../config/ConfigurationProvider.java | 46 ++++++++++++++++++++++ .../src/main/webapp/jsp/snippets/footer.jsp | 2 +- 4 files changed, 67 insertions(+), 14 deletions(-) diff --git a/id/ConfigWebTool/pom.xml b/id/ConfigWebTool/pom.xml index 36fe03457..57aa5c794 100644 --- a/id/ConfigWebTool/pom.xml +++ b/id/ConfigWebTool/pom.xml @@ -139,18 +139,23 @@ jar compile - - + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + + + ${project.version} + + + + + + + diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java index 513f046f1..69ac58d15 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/Constants.java @@ -22,13 +22,15 @@ *******************************************************************************/ package at.gv.egovernment.moa.id.configuration; -import java.util.Collection; import java.util.Hashtable; import java.util.Map; import edu.emory.mathcs.backport.java.util.Collections; public class Constants { + + public static final String DEFAULT_VERSION = "1.x"; + public static final String FILEPREFIX = "file:"; public static final String SERVLET_PVP2ASSERTION = "pvp2login.action"; diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java index e4cf5367d..e65163946 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/config/ConfigurationProvider.java @@ -29,12 +29,15 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.util.Properties; import java.util.Timer; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import javax.servlet.http.HttpServletRequest; @@ -51,6 +54,7 @@ import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.auth.pvp2.MetaDataVerificationFilter; import at.gv.egovernment.moa.id.configuration.exception.ConfigurationException; import at.gv.egovernment.moa.id.configuration.utils.UserRequestCleaner; +import at.gv.egovernment.moa.id.protocols.pvp2x.config.PVPConfiguration; import at.gv.egovernment.moa.util.MiscUtil; @@ -445,6 +449,9 @@ public class ConfigurationProvider { return props.getProperty("general.mail.admin.adress"); } + public String getConfigToolVersion() { + return parseVersionFromManifest(); + } private void initalPVP2Login() throws ConfigurationException { try { @@ -480,6 +487,45 @@ public class ConfigurationProvider { } catch (Exception e) { log.warn("PVP2 authentification can not be initialized."); throw new ConfigurationException("PVP2 authentification can not be initialized.", e); + } + } + + private String parseVersionFromManifest() { + + + + try { + Class clazz = ConfigurationProvider.class; + String className = clazz.getSimpleName() + ".class"; + String classPath = clazz.getResource(className).toString(); + + if (classPath.startsWith("jar")) { + log.info("MOA-ID-Configuration Version can NOT parsed from Manifest. Set blank Version"); + return Constants.DEFAULT_VERSION; + + } + + String manifestPath = classPath.substring(0, classPath.lastIndexOf("WEB-INF/classes/") + "WEB-INF/classes/".length()) + + "../../META-INF/MANIFEST.MF"; + + Manifest manifest = new Manifest(new URL(manifestPath).openStream());; + + Attributes attributes = manifest.getMainAttributes(); + String version = attributes.getValue("version"); + + if (MiscUtil.isNotEmpty(version)) + return version; + + else { + log.info("MOA-ID-Configuration Version not found in Manifest. Set blank Version"); + return Constants.DEFAULT_VERSION; + + } + + } catch (Throwable e) { + log.info("MOA-ID Version can NOT parsed from Manifest. Set blank Version"); + + return Constants.DEFAULT_VERSION; } diff --git a/id/ConfigWebTool/src/main/webapp/jsp/snippets/footer.jsp b/id/ConfigWebTool/src/main/webapp/jsp/snippets/footer.jsp index 3f00984f2..e78319181 100644 --- a/id/ConfigWebTool/src/main/webapp/jsp/snippets/footer.jsp +++ b/id/ConfigWebTool/src/main/webapp/jsp/snippets/footer.jsp @@ -4,6 +4,6 @@ \ No newline at end of file -- cgit v1.2.3