From 578ad0d6bc408edf9e6c875156054374f5fd8337 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Mon, 22 Mar 2021 18:40:26 +0100 Subject: change to EGIZ codestyle --- .../moa/spss/util/ExternalURIVerifier.java | 196 ++++++++++----------- 1 file changed, 98 insertions(+), 98 deletions(-) (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/ExternalURIVerifier.java') diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/ExternalURIVerifier.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/ExternalURIVerifier.java index 859e7e9..be40a9e 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/ExternalURIVerifier.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/util/ExternalURIVerifier.java @@ -12,103 +12,103 @@ import at.gv.egovernment.moaspss.logging.LogMsg; import at.gv.egovernment.moaspss.logging.Logger; public class ExternalURIVerifier { - - public static void verify(String host, int port) throws MOAApplicationException { - - - if (host == null) - return; - if (host.equalsIgnoreCase("")) - return; - - try { - ConfigurationProvider config = ConfigurationProvider.getInstance(); - - boolean allowExternalUris = config.getAllowExternalUris(); - List blacklist = config.getBlackListedUris(); - List whitelist = config.getWhiteListedUris(); - - InetAddress hostInetAddress = InetAddress.getByName(host); - String ip = hostInetAddress.getHostAddress(); - - - if (allowExternalUris) { - // external URIs are allowed - check blacklist - Iterator it = blacklist.iterator(); - while (it.hasNext()) { - String[] array = (String[])it.next(); - String bhost = array[0]; - String bport = array[1]; - if (bport == null || port == -1) { - // check only host - if (ip.startsWith(bhost)) { - Logger.debug(new LogMsg("Blacklist check: " + host + " (" + ip + ") blacklisted")); - throw new MOAApplicationException("4002", new Object[]{host + "(" + ip + ")"}); - } - } - else { - // check host and port - int iport = new Integer(bport).intValue(); - if (ip.startsWith(bhost) && (iport == port)) { - Logger.debug(new LogMsg("Blacklist check: " + host + ":" + port + " (" + ip + ":" + port + " blacklisted")); - throw new MOAApplicationException("4002", new Object[]{host + ":" + port + " (" + ip + ":" + port + ")"}); - } - - } - } - } - else { - // external uris are forbidden - check whitelist - Iterator it = whitelist.iterator(); - boolean allowed = false; - while (it.hasNext()) { - String[] array = (String[])it.next(); - String bhost = array[0]; - String bport = array[1]; - if (bport == null || port == -1) { - // check only host - if (ip.startsWith(bhost)) { - Logger.debug(new LogMsg("Whitelist check: " + host + " (" + ip + ") whitelisted")); - allowed = true; - //throw new MOAApplicationException("4002", new Object[]{host + "(" + ip + ")"}); - } - } - else { - // check host and port - int iport = new Integer(bport).intValue(); - if (ip.startsWith(bhost) && (iport == port)) { - Logger.debug(new LogMsg("Whitelist check: " + host + ":" + port + " (" + ip + ":" + port + " whitelisted")); - //throw new MOAApplicationException("4002", new Object[]{host + ":" + port + " (" + ip + ":" + port + ")"}); - allowed = true; - } - - } - } - - if (!allowed) { - if (port != -1) { - Logger.debug(new LogMsg("No external URIs allowed (" + host + ")")); - throw new MOAApplicationException("4001", new Object[]{host + "(" + ip + ")"}); - } - else { - Logger.debug(new LogMsg("No external URIs allowed (" + host + ":" + port + ")")); - throw new MOAApplicationException("4001", new Object[]{host + ":" + port + " (" + ip + ":" + port + ")"}); - } - - } - - } - - Logger.debug(new LogMsg("URI allowed: " + ip + ":" + port)); - - } catch (ConfigurationException e) { - throw new MOAApplicationException("config.10", null); - } catch (UnknownHostException e) { - throw new MOAApplicationException("4003", new Object[]{host}); - } - - - - } + + public static void verify(String host, int port) throws MOAApplicationException { + + if (host == null) { + return; + } + if (host.equalsIgnoreCase("")) { + return; + } + + try { + final ConfigurationProvider config = ConfigurationProvider.getInstance(); + + final boolean allowExternalUris = config.getAllowExternalUris(); + final List blacklist = config.getBlackListedUris(); + final List whitelist = config.getWhiteListedUris(); + + final InetAddress hostInetAddress = InetAddress.getByName(host); + final String ip = hostInetAddress.getHostAddress(); + + if (allowExternalUris) { + // external URIs are allowed - check blacklist + final Iterator it = blacklist.iterator(); + while (it.hasNext()) { + final String[] array = (String[]) it.next(); + final String bhost = array[0]; + final String bport = array[1]; + if (bport == null || port == -1) { + // check only host + if (ip.startsWith(bhost)) { + Logger.debug(new LogMsg("Blacklist check: " + host + " (" + ip + ") blacklisted")); + throw new MOAApplicationException("4002", new Object[] { host + "(" + ip + ")" }); + } + } else { + // check host and port + final int iport = new Integer(bport).intValue(); + if (ip.startsWith(bhost) && iport == port) { + Logger.debug(new LogMsg("Blacklist check: " + host + ":" + port + " (" + ip + ":" + port + + " blacklisted")); + throw new MOAApplicationException("4002", new Object[] { host + ":" + port + " (" + ip + ":" + + port + ")" }); + } + + } + } + } else { + // external uris are forbidden - check whitelist + final Iterator it = whitelist.iterator(); + boolean allowed = false; + while (it.hasNext()) { + final String[] array = (String[]) it.next(); + final String bhost = array[0]; + final String bport = array[1]; + if (bport == null || port == -1) { + // check only host + if (ip.startsWith(bhost)) { + Logger.debug(new LogMsg("Whitelist check: " + host + " (" + ip + ") whitelisted")); + allowed = true; + // throw new MOAApplicationException("4002", new Object[]{host + "(" + ip + + // ")"}); + } + } else { + // check host and port + final int iport = new Integer(bport).intValue(); + if (ip.startsWith(bhost) && iport == port) { + Logger.debug(new LogMsg("Whitelist check: " + host + ":" + port + " (" + ip + ":" + port + + " whitelisted")); + // throw new MOAApplicationException("4002", new Object[]{host + ":" + port + " + // (" + ip + ":" + port + ")"}); + allowed = true; + } + + } + } + + if (!allowed) { + if (port != -1) { + Logger.debug(new LogMsg("No external URIs allowed (" + host + ")")); + throw new MOAApplicationException("4001", new Object[] { host + "(" + ip + ")" }); + } else { + Logger.debug(new LogMsg("No external URIs allowed (" + host + ":" + port + ")")); + throw new MOAApplicationException("4001", new Object[] { host + ":" + port + " (" + ip + ":" + + port + ")" }); + } + + } + + } + + Logger.debug(new LogMsg("URI allowed: " + ip + ":" + port)); + + } catch (final ConfigurationException e) { + throw new MOAApplicationException("config.10", null); + } catch (final UnknownHostException e) { + throw new MOAApplicationException("4003", new Object[] { host }); + } + + } } -- cgit v1.2.3