From 0447841f3a08890bf746625d0f17976adada6ac8 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 3 Mar 2015 19:02:48 +0100 Subject: bwIDM - Shibboleth login working for Freiburg's SP - more to come rework GUI classes to work with GuiManager: use GuiManager.show() and GuiManager.openPopup() only! static openlinks class (models/links.java deleted). There are keywords to open links, e.g. OpenLinks.openWebpage("faq"). Please see the class. --- .../src/main/java/thrift/ThriftManager.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'dozentenmodul/src/main/java/thrift/ThriftManager.java') diff --git a/dozentenmodul/src/main/java/thrift/ThriftManager.java b/dozentenmodul/src/main/java/thrift/ThriftManager.java index 716c4439..cc085ecd 100644 --- a/dozentenmodul/src/main/java/thrift/ThriftManager.java +++ b/dozentenmodul/src/main/java/thrift/ThriftManager.java @@ -1,5 +1,8 @@ package thrift; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.log4j.Logger; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; @@ -43,6 +46,15 @@ public class ThriftManager { private static final int SATELLITE_PORT = 9090; private static final int SATELLITE_TIMEOUT = 10000; + /** + * IP Validation Regex + */ + private static final String IP_VALID_PATTERN = + "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; + /** * Protected constructor to avoid external instantiation */ @@ -106,6 +118,7 @@ public class ThriftManager { final TProtocol protocol = new TBinaryProtocol(transport); // now we are ready to create the client, according to ClientType! _satClient.set(new Server.Client(protocol)); + LOGGER.info("Satellite '" + SATELLITE_IP + "' reachable. Client initialised."); } return true; } @@ -119,7 +132,22 @@ public class ThriftManager { LOGGER.error("Given IP for satellite is empty."); return false; } + // validate + Matcher matcher = Pattern.compile(IP_VALID_PATTERN).matcher(ip); + if (!matcher.matches()) { + LOGGER.error("Given form of IP is invalid: " + ip); + return false; + } + // finally set it SATELLITE_IP = ip; + + // last check: try to connect + if (!init(ClientType.SATELLITE, SATELLITE_IP, SATELLITE_PORT, SATELLITE_TIMEOUT)) { + // init failed + LOGGER.error("Could not initialise new client to satellite: " + SATELLITE_IP); + return false; + } + // TODO final last: get version from server return true; } /** -- cgit v1.2.3-55-g7522