From 60c53021df660563d0be52b307f8dbbcbbbca22c Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Tue, 27 Oct 2020 18:56:19 +0100 Subject: fix language tags for Guacamole 1.2.0, workaround for greyed out continue button, add build logging Build revision and timestamp are logged on start and sent as http request headers on connection to the sat server. (Bwlp-Plugin-Build-Revision and Bwlp-Plugin-Build-Timestamp) This build now requires guacamole >=1.2.0 --- pom.xml | 42 ++++++++++++++++++++- .../bwlp_guac/BwlpAuthenticationProvider.java | 44 +++++++++++++++++----- .../de/bwlehrpool/bwlp_guac/ConnectionManager.java | 13 ++++--- src/main/resources/continue-patch.html | 5 +++ src/main/resources/guac-manifest.json | 7 +++- src/main/resources/translations/de.json | 3 +- src/main/resources/translations/en.json | 3 +- 7 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/continue-patch.html diff --git a/pom.xml b/pom.xml index 288cd6b..20cde4c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,12 +11,37 @@ bwlp-guac http://maven.apache.org + + scm:git:git://git.openslx.org/bwlp/bwlp-guacamole-ext.git + + UTF-8 + yyyy.MM.dd HH:mm + + org.codehaus.mojo + buildnumber-maven-plugin + 1.4 + + + validate + + create + create-timestamp + + + + + false + false + revision.timestamp + + + org.apache.maven.plugins maven-compiler-plugin @@ -27,6 +52,21 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.0.0 + + + + ${maven.build.timestamp} + ${buildNumber} + ${revision.timestamp} + + + + + com.keithbranton.mojo @@ -110,7 +150,7 @@ org.apache.guacamole guacamole-ext - 1.1.0 + 1.2.0 javax.servlet diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java index f73de84..3043339 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/BwlpAuthenticationProvider.java @@ -1,23 +1,45 @@ package de.bwlehrpool.bwlp_guac; +import java.net.URL; +import java.net.URLClassLoader; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.*; - import org.apache.guacamole.GuacamoleException; import org.apache.guacamole.net.auth.*; -import org.apache.guacamole.net.auth.credentials.GuacamoleCredentialsException; +import org.apache.guacamole.language.TranslatableGuacamoleCredentialsException; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.servlet.http.HttpServletRequest; - import org.apache.guacamole.form.Field; -import org.apache.guacamole.net.auth.credentials.GuacamoleInsufficientCredentialsException; +import org.apache.guacamole.language.TranslatableGuacamoleInsufficientCredentialsException; import org.apache.guacamole.net.auth.credentials.CredentialsInfo; public class BwlpAuthenticationProvider implements AuthenticationProvider { - Logger LOGGER = LoggerFactory.getLogger(BwlpAuthenticationProvider.class); + static Logger LOGGER = LoggerFactory.getLogger(BwlpAuthenticationProvider.class); + + static Properties MANIFEST = new Properties(); + + static { + URLClassLoader cl = (URLClassLoader) BwlpAuthenticationProvider.class.getClassLoader(); + URL url = cl.findResource("META-INF/MANIFEST.MF"); + try { + MANIFEST.load(url.openStream()); + LOGGER.info("Plugin build revision: " + MANIFEST.getProperty("Build-Revision")); + + String timestamp = MANIFEST.getProperty("Build-Revision-Timestamp"); + DateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm"); + long milliSeconds= Long.parseLong(timestamp); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(milliSeconds); + LOGGER.info("Plugin build timestamp: " + formatter.format(calendar.getTime())); + } catch (Exception e) { + System.out.println("unable to read manifest " + e.getMessage()); + } + } public String getIdentifier() { return "de.bwlehrpool.bwgpul"; @@ -58,6 +80,8 @@ public class BwlpAuthenticationProvider implements AuthenticationProvider { public UserContext redecorate(UserContext decorated, UserContext context, AuthenticatedUser authenticatedUser, Credentials credentials) throws GuacamoleException { + LOGGER.info(MANIFEST.getProperty("Build-Revision")); + String username = Util.getUsername(authenticatedUser); if (username == null) { LOGGER.warn("redecorate: Ignoring user without name"); @@ -97,8 +121,9 @@ public class BwlpAuthenticationProvider implements AuthenticationProvider { String groupJson = request.getParameter("group"); if (groupJson == null) { - throw new GuacamoleInsufficientCredentialsException( - "GROUP_SELECTION.TITLE", new CredentialsInfo( + LOGGER.warn("test 1"); + throw new TranslatableGuacamoleInsufficientCredentialsException( + "GROUP_SELECTION.TITLE", "GROUP_SELECTION.TITLE", new CredentialsInfo( Collections.singletonList(new GroupField()) )); } @@ -130,8 +155,9 @@ public class BwlpAuthenticationProvider implements AuthenticationProvider { } if (tryAgain) { - throw new GuacamoleCredentialsException( - message, new CredentialsInfo( + LOGGER.warn("test 2"); + throw new TranslatableGuacamoleCredentialsException( + message, message, new CredentialsInfo( Collections.singletonList(new GroupField()) )); } diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java index db8ff07..1f7d928 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java @@ -30,7 +30,8 @@ import javax.net.ssl.X509TrustManager; import org.apache.guacamole.form.Field; import org.apache.guacamole.net.auth.credentials.CredentialsInfo; import org.apache.guacamole.net.auth.credentials.GuacamoleCredentialsException; -import org.apache.guacamole.net.auth.credentials.GuacamoleInsufficientCredentialsException; +import org.apache.guacamole.language.TranslatableGuacamoleCredentialsException; +import org.apache.guacamole.language.TranslatableGuacamoleInsufficientCredentialsException; import org.codehaus.jackson.map.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -135,8 +136,8 @@ public class ConnectionManager { JsonGroup group = groupPool.get(groupid); if (group == null) { // Request the user to select a group - throw new GuacamoleInsufficientCredentialsException( - "GROUP_SELECTION.TITLE", new CredentialsInfo( + throw new TranslatableGuacamoleInsufficientCredentialsException( + "GROUP_SELECTION.TITLE", "GROUP_SELECTION.TITLE", new CredentialsInfo( Collections.singletonList(new GroupField()) )); } @@ -164,8 +165,8 @@ public class ConnectionManager { } if (freeClient == null) { // Request the user to select another Group - throw new GuacamoleCredentialsException( - "GROUP_SELECTION.NO_FREE_ERROR", new CredentialsInfo( + throw new TranslatableGuacamoleCredentialsException( + "GROUP_SELECTION.NO_FREE_ERROR", "GROUP_SELECTION.NO_FREE_ERROR", new CredentialsInfo( Collections.singletonList(new GroupField()) )); } @@ -217,6 +218,8 @@ public class ConnectionManager { ((HttpsURLConnection) con).setHostnameVerifier(ignorer); ((HttpsURLConnection) con).setSSLSocketFactory(sockFac); } + con.setRequestProperty("Bwlp-Plugin-Build-Revision", BwlpAuthenticationProvider.MANIFEST.getProperty("Build-Revision")); + con.setRequestProperty("Bwlp-Plugin-Build-Timestamp", BwlpAuthenticationProvider.MANIFEST.getProperty("Build-Revision-Timestamp")); try (BufferedInputStream in = new BufferedInputStream(con.getInputStream())) { byte dataBuffer[] = new byte[2048]; int bytesRead; diff --git a/src/main/resources/continue-patch.html b/src/main/resources/continue-patch.html new file mode 100644 index 0000000..85204b6 --- /dev/null +++ b/src/main/resources/continue-patch.html @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/src/main/resources/guac-manifest.json b/src/main/resources/guac-manifest.json index 565984d..fb4bfb4 100644 --- a/src/main/resources/guac-manifest.json +++ b/src/main/resources/guac-manifest.json @@ -6,7 +6,12 @@ "largeIcon" : "images/Logo_bwLehrpool_symbol.png", "authProviders": ["de.bwlehrpool.bwlp_guac.BwlpAuthenticationProvider"], "listeners" : ["de.bwlehrpool.bwlp_guac.TunnelListener"], - "html" : [ "login-logo.html", "selection-logo.html", "secondary-logo.html" ], + "html" : [ + "login-logo.html", + "selection-logo.html", + "secondary-logo.html", + "continue-patch.html" + ], "translations" : [ "translations/en.json", "translations/de.json" diff --git a/src/main/resources/translations/de.json b/src/main/resources/translations/de.json index e4212e4..e574f3c 100644 --- a/src/main/resources/translations/de.json +++ b/src/main/resources/translations/de.json @@ -12,6 +12,7 @@ "PASSWORD_PROTECTED": "Passwortgeschützt", "LOG_OUT": "Ausloggen", "PASSWORD_ERROR": "Falsches Passwort!", - "NO_FREE_ERROR": "Keinen freien Client gefunden. Wähle einen anderen Raum aus." + "NO_FREE_ERROR": "Keinen freien Client gefunden. Wähle einen anderen Raum aus.", + "CONTINUE": "Weiter" } } \ No newline at end of file diff --git a/src/main/resources/translations/en.json b/src/main/resources/translations/en.json index 96d9b2c..2b0c0d6 100644 --- a/src/main/resources/translations/en.json +++ b/src/main/resources/translations/en.json @@ -12,6 +12,7 @@ "PASSWORD_PROTECTED": "Password protected", "LOG_OUT": "Log out", "PASSWORD_ERROR": "Wrong password!", - "NO_FREE_ERROR": "No free client. Select another Location." + "NO_FREE_ERROR": "No free client. Select another Location.", + "CONTINUE": "Continue" } } \ No newline at end of file -- cgit v1.2.3-55-g7522