dependency updates

This commit is contained in:
Joern Muehlencord
2021-12-13 22:13:20 +01:00
parent cd2e3b0642
commit 84b8b0545f
23 changed files with 1981 additions and 850 deletions

1154
.editorconfig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -62,7 +62,7 @@ limitations under the License.
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-jdk14</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -42,7 +42,7 @@ public abstract class AbstractController<T extends Serializable> extends CommonA
private final Class<T> entityClass; private final Class<T> entityClass;
public AbstractController(Class<T> clazz) { protected AbstractController(Class<T> clazz) {
this.entityClass = clazz; this.entityClass = clazz;
} }
@ -68,24 +68,21 @@ public abstract class AbstractController<T extends Serializable> extends CommonA
*/ */
@Lock(LockType.READ) @Lock(LockType.READ)
public T find(Object id, String... subGraphItems) { public T find(Object id, String... subGraphItems) {
EntityGraph graph = this.em.createEntityGraph(entityClass); EntityGraph<T> graph = this.em.createEntityGraph(entityClass);
for (String subGraphItem : subGraphItems) { for (String subGraphItem : subGraphItems) {
graph.addSubgraph(subGraphItem); graph.addSubgraph(subGraphItem);
} }
Map hints = new HashMap<>(); Map<String, Object> hints = new HashMap<>();
hints.put("javax.persistence.loadgraph", graph); hints.put("javax.persistence.loadgraph", graph);
T entity = (T) em.find(entityClass, id, hints); return em.find(entityClass, id, hints);
return entity;
} }
@Lock(LockType.READ) @Lock(LockType.READ)
public List<T> find(String queryName, Map<String, Object> parameterMap) throws ControllerException { public List<T> find(String queryName, Map<String, Object> parameterMap) {
Query query = em.createNamedQuery(queryName); Query query = em.createNamedQuery(queryName);
parameterMap.entrySet().forEach((entry) -> { parameterMap.entrySet().forEach(entry -> query.setParameter(entry.getKey(), entry.getValue()));
query.setParameter(entry.getKey(), entry.getValue());
});
return query.getResultList(); return query.getResultList();
} }

View File

@ -15,52 +15,50 @@
*/ */
package de.muehlencord.shared.db; package de.muehlencord.shared.db;
import de.muehlencord.shared.util.DateUtil;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.Date;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Does not work, cannot Spring independent inject current username - implemented in AbstractController manually * Does not work, cannot Spring independent inject current username - implemented in AbstractController manually
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class AuditListener { public class AuditListener {
private static final Logger LOGGER = LoggerFactory.getLogger(AuditListener.class); private static final Logger logger = LoggerFactory.getLogger(AuditListener.class);
// @PrePersist // @PrePersist
public void prePersist(Auditable auditable) { public void prePersist(Auditable auditable) {
Audit audit = auditable.getAudit(); Audit audit = auditable.getAudit();
if (audit == null) { if (audit == null) {
audit = new Audit(); audit = new Audit();
auditable.setAudit(audit); auditable.setAudit(audit);
} }
LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC); LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC);
audit.setCreatedOn(now); audit.setCreatedOn(now);
audit.setLastUpdatedOn(now); audit.setLastUpdatedOn(now);
// audit.setCreatedBy(LoggedUser.get()); // TODO where to get the user from // audit.setCreatedBy(LoggedUser.get()); // TODO where to get the user from
if (LOGGER.isDebugEnabled()) { if (logger.isDebugEnabled()) {
LOGGER.debug("prePersist executed"); logger.debug("prePersist executed");
}
} }
// @PreUpdate }
public void preUpdate(Auditable auditable) {
Audit audit = auditable.getAudit();
LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC); // @PreUpdate
// Date now = DateUtil.getCurrentTimeInUTC(); public void preUpdate(Auditable auditable) {
audit.setLastUpdatedOn(now); Audit audit = auditable.getAudit();
// audit.setUpdatedBy(LoggedUser.get()); // TODO where to get the user from
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("preUpdate executed");
}
// TODO where to get the user from
LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC);
audit.setLastUpdatedOn(now);
if (logger.isDebugEnabled()) {
logger.debug("preUpdate executed");
} }
}
} }

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
Licensed 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.
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c] %m%n" />
</layout>
</appender>
<category name="de.muehlencord">
<priority value="DEBUG"/>
</category>
<category name="com.sun">
<priority value="WARN"/>
</category>
<category name="javax.xml">
<priority value="WARN"/>
</category>
<logger name="org.hibernate">
<level value="info"/>
</logger>
<root>
<level value="DEBUG" />
<appender-ref ref="consoleAppender" />
</root>
</log4j:configuration>

View File

@ -60,14 +60,14 @@ public class APIErrorResponse {
this.rootCause = rootCauseMessage; this.rootCause = rootCauseMessage;
} }
public APIErrorResponse(Exception exception, Locale locale) { public APIErrorResponse(Exception exception) {
this.status = Response.Status.INTERNAL_SERVER_ERROR; this.status = Response.Status.INTERNAL_SERVER_ERROR;
this.errorCode = "0"; this.errorCode = "0";
this.message = exception.getLocalizedMessage(); this.message = exception.getLocalizedMessage();
this.rootCause = null; this.rootCause = null;
} }
public APIErrorResponse(Exception exception, Locale locale, Throwable th) { public APIErrorResponse(Exception exception, Throwable th) {
this.status = Response.Status.INTERNAL_SERVER_ERROR; this.status = Response.Status.INTERNAL_SERVER_ERROR;
this.errorCode = "0"; this.errorCode = "0";
this.message = exception.getLocalizedMessage(); this.message = exception.getLocalizedMessage();

View File

@ -31,7 +31,7 @@ public class APIException extends RuntimeException {
public static final String HTTP_HEADER_X_ROOT_CAUSE = "X-Root-Cause"; public static final String HTTP_HEADER_X_ROOT_CAUSE = "X-Root-Cause";
private static final long serialVersionUID = -4356132354448841938L; private static final long serialVersionUID = -4356132354448841938L;
private final Response httpResponse; private final transient Response httpResponse;
public APIException(APIError apiError, Locale locale) { public APIException(APIError apiError, Locale locale) {
httpResponse = createHttpResponse(new APIErrorResponse(apiError, locale)); httpResponse = createHttpResponse(new APIErrorResponse(apiError, locale));
@ -49,8 +49,8 @@ public class APIException extends RuntimeException {
httpResponse = createHttpResponse(new APIErrorResponse(apiError, new Locale(locale), rootCause)); httpResponse = createHttpResponse(new APIErrorResponse(apiError, new Locale(locale), rootCause));
} }
public APIException(Exception exception, Locale locale) { public APIException(Exception exception) {
httpResponse = createHttpResponse(new APIErrorResponse(exception, locale)); httpResponse = createHttpResponse(new APIErrorResponse(exception));
} }
public Response getHttpResponse() { public Response getHttpResponse() {

View File

@ -25,46 +25,41 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class APIExceptionInterceptor { public class APIExceptionInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(APIExceptionInterceptor.class); private static final Logger logger = LoggerFactory.getLogger(APIExceptionInterceptor.class);
@Inject @Inject
Locale locale; Locale locale;
@AroundInvoke @AroundInvoke
public Object handleException(InvocationContext context) { public Object handleException(InvocationContext context) {
Object proceedResponse; Object proceedResponse;
try { try {
// continue to execute context // continue to execute context
// if an exception is thrown during processing, this is passed in to the catch block below // if an exception is thrown during processing, this is passed in to the catch block below
proceedResponse = context.proceed(); proceedResponse = context.proceed();
} catch (Exception ex) { } catch (Exception ex) {
if (LOGGER.isDebugEnabled()) { logger.debug(ex.getMessage(), ex);
LOGGER.debug(ex.getMessage()); Response errorResponse;
LOGGER.debug("Detailed stacktrace", new Object[]{ex}); if (ex instanceof APIException) {
} errorResponse = ((APIException) ex).getHttpResponse();
} else if (ex.getCause() instanceof APIException) {
Response errorResponse; errorResponse = ((APIException) ex.getCause()).getHttpResponse();
if (ex instanceof APIException) { } else if (ex instanceof ConstraintViolationException) {
errorResponse = ((APIException) ex).getHttpResponse(); // this exception is handled via the ConstraintViolationMapper
} else if (ex.getCause() instanceof APIException) { throw (ConstraintViolationException) ex;
errorResponse = ((APIException) ex.getCause()).getHttpResponse(); } else if (ex.getCause() instanceof ConstraintViolationException) {
} else if (ex instanceof ConstraintViolationException) { // this exception is handled via the ConstraintViolationMapper
// this exception is handled via the ConstraintViolationMapper throw (ConstraintViolationException) ex.getCause();
throw (ConstraintViolationException) ex; } else {
} else if (ex.getCause() instanceof ConstraintViolationException) { errorResponse = new APIException(ex).getHttpResponse();
// this exception is handled via the ConstraintViolationMapper }
throw (ConstraintViolationException) ex.getCause(); return errorResponse;
} else {
errorResponse = new APIException(ex, locale).getHttpResponse();
}
return errorResponse;
}
return proceedResponse;
} }
return proceedResponse;
}
} }

View File

@ -1,4 +1,3 @@
<!-- <!--
Copyright 2019 Joern Muehlencord (joern@muehlencord.de). Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
@ -14,72 +13,73 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>shared-network</artifactId>
<groupId>de.muehlencord.shared</groupId> <build>
<artifactId>shared-network</artifactId> <finalName>${project.artifactId}</finalName>
</build>
<dependencies>
<dependency>
<artifactId>junit-jupiter-engine</artifactId>
<groupId>org.junit.jupiter</groupId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>shared-util</artifactId>
<groupId>de.muehlencord.shared</groupId>
<type>jar</type>
</dependency>
<dependency>
<artifactId>javax.mail</artifactId>
<groupId>com.sun.mail</groupId>
</dependency>
<dependency>
<artifactId>ews-java-api</artifactId>
<groupId>com.microsoft.ews-java-api</groupId>
</dependency>
<dependency>
<artifactId>commons-net</artifactId>
<groupId>commons-net</groupId>
<scope>compile</scope>
</dependency>
<dependency>
<artifactId>jaxws-api</artifactId>
<groupId>javax.xml.ws</groupId>
<scope>test</scope>
<version>2.3.1</version>
</dependency>
</dependencies>
<groupId>de.muehlencord.shared</groupId>
<modelVersion>4.0.0</modelVersion>
<name>shared-network</name>
<packaging>jar</packaging>
<parent>
<artifactId>shared</artifactId>
<groupId>de.muehlencord</groupId>
<version>1.2-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
<packaging>jar</packaging> </parent>
<name>shared-network</name> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent> <url>http://maven.apache.org</url>
<artifactId>shared</artifactId>
<groupId>de.muehlencord</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<url>http://maven.apache.org</url> <version>1.2-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-util</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>

View File

@ -19,74 +19,77 @@ import static java.lang.Long.valueOf;
import static java.lang.Math.floor; import static java.lang.Math.floor;
import static java.lang.Math.log; import static java.lang.Math.log;
import static java.lang.Math.pow; import static java.lang.Math.pow;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class CidrTool { public class CidrTool {
public static List<String> rangeToCidrList(String startIp, String endIp) { private static final int[] CIDR2MASK = new int[]{0x00000000, 0x80000000,
long start = ipToLong(startIp); 0xC0000000, 0xE0000000, 0xF0000000, 0xF8000000, 0xFC000000,
long end = ipToLong(endIp); 0xFE000000, 0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000, 0xFFFFF800,
0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0,
0xFFFFFFE0, 0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE,
0xFFFFFFFF};
ArrayList<String> pairs = new ArrayList<>(); private CidrTool() {
while (end >= start) { // hide constructor
byte maxsize = 32; }
while (maxsize > 0) {
long mask = CIDR2MASK[ maxsize - 1];
long maskedBase = start & mask;
if (maskedBase != start) { public static List<String> rangeToCidrList(String startIp, String endIp) {
break; long start = ipToLong(startIp);
} long end = ipToLong(endIp);
maxsize--; ArrayList<String> pairs = new ArrayList<>();
} while (end >= start) {
double x = log(end - start + 1) / log(2); byte maxsize = 32;
byte maxdiff = (byte) (32 - floor(x)); while (maxsize > 0) {
if (maxsize < maxdiff) { long mask = CIDR2MASK[maxsize - 1];
maxsize = maxdiff; long maskedBase = start & mask;
}
String ip = longToIP(start);
pairs.add(ip + "/" + maxsize);
start += pow(2, (32 - maxsize));
}
return pairs;
}
if (maskedBase != start) {
private static final int[] CIDR2MASK = new int[]{0x00000000, 0x80000000, break;
0xC0000000, 0xE0000000, 0xF0000000, 0xF8000000, 0xFC000000,
0xFE000000, 0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000, 0xFFFFF800,
0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0,
0xFFFFFFE0, 0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE,
0xFFFFFFFF};
private static long ipToLong(String strIP) {
long[] ip = new long[4];
String[] ipSec = strIP.split("\\.");
for (int k = 0; k < 4; k++) {
ip[k] = valueOf(ipSec[k]);
} }
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3]; maxsize--;
}
double x = log(end - start + 1D) / log(2);
byte maxdiff = (byte) (32 - floor(x));
if (maxsize < maxdiff) {
maxsize = maxdiff;
}
String ip = longToIP(start);
pairs.add(ip + "/" + maxsize);
start += pow(2, (32 - maxsize));
}
return pairs;
}
private static long ipToLong(String strIP) {
long[] ip = new long[4];
String[] ipSec = strIP.split("\\.");
for (int k = 0; k < 4; k++) {
ip[k] = valueOf(ipSec[k]);
} }
private static String longToIP(long longIP) { return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
StringBuilder sb = new StringBuilder(""); }
sb.append(String.valueOf(longIP >>> 24));
sb.append(".");
sb.append(String.valueOf((longIP & 0x00FFFFFF) >>> 16));
sb.append(".");
sb.append(String.valueOf((longIP & 0x0000FFFF) >>> 8));
sb.append(".");
sb.append(String.valueOf(longIP & 0x000000FF));
return sb.toString(); private static String longToIP(long longIP) {
} StringBuilder sb = new StringBuilder("");
sb.append(String.valueOf(longIP >>> 24));
sb.append(".");
sb.append(String.valueOf((longIP & 0x00FFFFFF) >>> 16));
sb.append(".");
sb.append(String.valueOf((longIP & 0x0000FFFF) >>> 8));
sb.append(".");
sb.append(String.valueOf(longIP & 0x000000FF));
return sb.toString();
}
} }

View File

@ -17,6 +17,7 @@ package de.muehlencord.shared.network.whois;
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList; import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords; import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
import java.text.ParseException; import java.text.ParseException;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -31,7 +32,12 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
/** /**
* logger object * logger object
*/ */
private final static Logger LOGGER = LoggerFactory.getLogger(DefaultWhoisParser.class); private static final Logger logger = LoggerFactory.getLogger(ArinWhoisParser.class);
private static final String START_STRING = "# start";
private static final String END_STRING = "# end";
private static final String NET_RANGE = "NetRange:";
private static final String ORG_NAME = "OrgName:";
/** /**
* information to be returned * information to be returned
*/ */
@ -41,19 +47,19 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
public WhoisInformation parseWhoIsString(String whoisString) throws WhoisException { public WhoisInformation parseWhoIsString(String whoisString) throws WhoisException {
whoisInformation = new WhoisInformation(); whoisInformation = new WhoisInformation();
whoisInformation.setResponseString(whoisString); whoisInformation.setResponseString(whoisString);
if (whoisString.contains("# start")) { // multiple values if (whoisString.contains(START_STRING)) {
String multipleWhoisString = whoisString; String multipleWhoisString = whoisString;
while (multipleWhoisString.contains("# start")) { while (multipleWhoisString.contains(START_STRING)) {
String whoisPartString; String whoisPartString;
try { try {
whoisPartString = getValueBetweenKeywords(multipleWhoisString, "# start", "# end"); whoisPartString = getValueBetweenKeywords(multipleWhoisString, START_STRING, END_STRING);
} catch (ParseException ex) { } catch (ParseException ex) {
throw new WhoisException("Error while reading whois part elements. Reason: " + ex.getMessage(), ex); throw new WhoisException("Error while reading whois part elements. Reason: " + ex.getMessage(), ex);
} }
analyse(whoisPartString); analyse(whoisPartString);
multipleWhoisString = multipleWhoisString.substring(multipleWhoisString.indexOf("# end") + 4); multipleWhoisString = multipleWhoisString.substring(multipleWhoisString.indexOf(END_STRING) + 4);
} }
} else { } else {
@ -78,11 +84,11 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
} }
private void analyseBlock(String block) throws WhoisException { private void analyseBlock(String block) throws WhoisException {
LOGGER.debug("Start analysing block"); logger.debug("Start analysing block");
LOGGER.debug("\n---\n" + block + "\n---\n"); logger.debug("\n---\n{}\n---\n", block);
if ((block == null) || (block.equals("")) || (!block.contains(" "))) { if ((block == null) || (!block.contains(" "))) {
LOGGER.debug("Skippig empty block"); logger.debug("Skipping empty block");
return; return;
} }
@ -98,23 +104,24 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
switch (startString) { switch (startString) {
case "NetRange:": case NET_RANGE:
if (valueMap.containsKey("NetRange:")) { if (valueMap.containsKey(NET_RANGE)) {
String netRange = valueMap.get("NetRange:"); String netRange = valueMap.get(NET_RANGE);
// convert inetnum to CDIR // convert inetnum to CDIR
String[] ipAddresses = netRange.split(" "); // TODO - what happens if not 3 parts are found // TODO - what happens if not 3 parts are found
String[] ipAddresses = netRange.split(" ");
// FIXME add CDIR notation support // FIXME add CDIR notation support
String startIpAddress = ipAddresses[0]; String startIpAddress = ipAddresses[0];
String endIPAddress = ipAddresses[2]; String endIPAddress = ipAddresses[2];
whoisInformation.addNetwork(rangeToCidrList(startIpAddress, endIPAddress)); whoisInformation.addNetwork(rangeToCidrList(startIpAddress, endIPAddress));
LOGGER.info("Network:" + whoisInformation.getNetwork().toString()); logger.info("Network: {}", whoisInformation.getNetwork());
} else { } else {
throw new WhoisException("Cannot identify netrange value"); throw new WhoisException("Cannot identify netrange value");
} }
break; break;
case "OrgName:": case ORG_NAME:
String orgName = getValue("OrgName:", valueMap); String orgName = getValue(ORG_NAME, valueMap);
String orgId = getValue("OrgId:", valueMap); String orgId = getValue("OrgId:", valueMap);
String country = getValue("Country:", valueMap); String country = getValue("Country:", valueMap);
@ -125,23 +132,23 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
orgId = orgName; orgId = orgName;
} }
whoisInformation.setNetworkInformation(new NetworkInformation(orgName, orgId, country)); whoisInformation.setNetworkInformation(new NetworkInformation(orgName, orgId, country));
LOGGER.info("Networkinformation:" + whoisInformation.getNetworkInformation().toString()); logger.info("Networkinformation: {}", whoisInformation.getNetworkInformation());
break; break;
case "OrgAbuseHandle:": case "OrgAbuseHandle:":
// TODO add abuse handler // TODO add abuse handler
LOGGER.info("Skipping OrgAbuseHandle block"); logger.info("Skipping OrgAbuseHandle block");
break; break;
case "OrgTechHandle:": case "OrgTechHandle:":
// admin person of network server belongs to // admin person of network server belongs to
LOGGER.info("Skipping OrgTechHandle block"); logger.info("Skipping OrgTechHandle block");
break; break;
case "#": case "#":
LOGGER.info("Skipping comment block"); logger.info("Skipping comment block");
break; break;
default: default:
LOGGER.info("Unknown block found"); logger.info("Unknown block found");
} }
} }
} }

View File

@ -16,6 +16,7 @@
package de.muehlencord.shared.network.whois; package de.muehlencord.shared.network.whois;
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList; import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -29,7 +30,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
/** /**
* logger object * logger object
*/ */
private final static Logger LOGGER = LoggerFactory.getLogger(DefaultWhoisParser.class); private static final Logger logger = LoggerFactory.getLogger(DefaultWhoisParser.class);
/** /**
* information to be returned * information to be returned
*/ */
@ -56,11 +57,11 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
} }
private void analyseBlock(String block) throws WhoisException { private void analyseBlock(String block) throws WhoisException {
LOGGER.debug("Start analysing block"); logger.debug("Start analysing block");
LOGGER.debug("\n---\n" + block + "\n---\n"); logger.debug("\n---\n{}\n---\n", block);
if ((block == null) || (block.equals("")) || (!block.contains(" "))) { if ((block == null) || (!block.contains(" "))) {
LOGGER.debug("Skippig empty block"); logger.debug("Skipping empty block");
return; return;
} }
@ -76,9 +77,8 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
case "inetnum:": case "inetnum:":
String inetnum = getValue("inetnum:", valueMap); String inetnum = getValue("inetnum:", valueMap);
String country = getValue("country:", valueMap); String country = getValue("country:", valueMap);
String netname = getValue("descr:", valueMap); String netname = getValue("netname:", valueMap);
String descr = getValue("netname:", valueMap); String descr = getValue("descr:", valueMap);
String parent = getValue("parent:", valueMap);
if ((inetnum == null) || (country == null)) { if ((inetnum == null) || (country == null)) {
throw new WhoisException("Cannot identify inetnum and/or country value"); throw new WhoisException("Cannot identify inetnum and/or country value");
@ -86,7 +86,8 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
if (inetnum.contains(" ")) { if (inetnum.contains(" ")) {
// convert inetnum to CDIR // convert inetnum to CDIR
String[] ipAddresses = inetnum.split(" "); // TODO - what happens if not 3 parts are found // TODO - what happens if not 3 parts are found
String[] ipAddresses = inetnum.split(" ");
// FIXME add CDIR notation support // FIXME add CDIR notation support
String startIpAddress = ipAddresses[0]; String startIpAddress = ipAddresses[0];
String endIPAddress = ipAddresses[2]; String endIPAddress = ipAddresses[2];
@ -95,15 +96,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
whoisInformation.addNetwork(inetnum); whoisInformation.addNetwork(inetnum);
} }
/* logger.info("Network: {}", whoisInformation.getNetwork());
if (parent != null) {
whoisInformation.addRootNetwork(parent);
LOGGER.info("Root network by parent" + whoisInformation.getRootNetwork().toString());
break;
}
*/
LOGGER.info("Network:" + whoisInformation.getNetwork().toString());
whoisInformation.setNetworkInformation(new NetworkInformation(netname, descr, country)); whoisInformation.setNetworkInformation(new NetworkInformation(netname, descr, country));
break; break;
@ -111,26 +104,26 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
// get information on level-2 network // get information on level-2 network
String route = getValue("route:", valueMap); String route = getValue("route:", valueMap);
whoisInformation.addRootNetwork(route); whoisInformation.addRootNetwork(route);
LOGGER.info("Root network " + whoisInformation.getRootNetwork().toString()); logger.info("Root network: {}", whoisInformation.getRootNetwork());
break; break;
case "role:": case "role:":
// admin company of network server belongs to // admin company of network server belongs to
LOGGER.info("Skipping role block"); logger.info("Skipping role block");
break; break;
case "person:": case "person:":
// admin person of network server belongs to // admin person of network server belongs to
LOGGER.info("Skipping person block"); logger.info("Skipping person block");
break; break;
case "% Information": case "% Information":
case "% Note:": case "% Note:":
case "% This": case "% This":
case "%": case "%":
LOGGER.info("Skipping comment block"); logger.info("Skipping comment block");
break; break;
default: default:
LOGGER.info("Unknown block found"); logger.info("Unknown block found");
LOGGER.error(block); logger.error(block);
} }
} }
} }

View File

@ -0,0 +1,28 @@
package de.muehlencord.shared.network.whois;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import de.muehlencord.shared.network.BaseTest;
import org.junit.jupiter.api.Test;
/**
* test the default implementation
*
* @author Joern Muehlencord, 2021-09-22
* @since 1.2.0
*/
class DefaultWhoisParserTest extends BaseTest {
@Test
void parseWhoIsString() throws Exception {
String whoisInformation = this.readContentFromFile("90.63.251.1.txt");
DefaultWhoisParser parser = new DefaultWhoisParser();
WhoisInformation information = parser.parseWhoIsString(whoisInformation);
assertNotNull (information);
information.validate();
System.out.println ("parseWhoIsString");
System.out.println (information.getNetworkInformation().toString());
System.out.println (information.getNetwork().toString());
System.out.println (information.getRootNetwork().toString());
}
}

View File

@ -0,0 +1,53 @@
% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf
% Note: this output has been filtered.
% To receive output for a database update, use the "-B" flag.
% Information related to '90.63.251.0 - 90.63.251.255'
% Abuse contact for '90.63.251.0 - 90.63.251.255' is 'gestionip.ft@orange.com'
inetnum: 90.63.251.0 - 90.63.251.255
netname: IP2000-ADSL-BAS
descr: LNAUB658 Aubervilliers Bloc 1
country: FR
admin-c: WITR1-RIPE
tech-c: WITR1-RIPE
status: ASSIGNED PA
remarks: for hacking, spamming or security problems send mail to
remarks: abuse@orange.fr
mnt-by: FT-BRX
created: 2015-10-09T11:39:49Z
last-modified: 2019-10-07T13:05:05Z
source: RIPE
role: Wanadoo France Technical Role
address: FRANCE TELECOM/SCR
address: 48 rue Camille Desmoulins
address: 92791 ISSY LES MOULINEAUX CEDEX 9
address: FR
phone: +33 1 58 88 50 00
abuse-mailbox: abuse@orange.fr
admin-c: BRX1-RIPE
tech-c: BRX1-RIPE
nic-hdl: WITR1-RIPE
mnt-by: FT-BRX
created: 2001-12-04T17:57:08Z
last-modified: 2013-07-16T14:09:50Z
source: RIPE # Filtered
% Information related to '90.63.192.0/18AS3215'
route: 90.63.192.0/18
descr: France Telecom IP2000-ADSL-BAS
origin: AS3215
mnt-by: FT-BRX
created: 2012-12-11T10:12:42Z
last-modified: 2012-12-11T10:12:42Z
source: RIPE
% This query was served by the RIPE Database Query Service version 1.101 (ANGUS)

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
Licensed 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.
-->
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c] %m%n" />
</layout>
</appender>
<category name="de.muehlencord">
<priority value="DEBUG"/>
</category>
<category name="com.sun">
<priority value="WARN"/>
</category>
<category name="javax.xml">
<priority value="WARN"/>
</category>
<logger name="org.hibernate">
<level value="INFO"/>
</logger>
<root>
<level value="DEBUG" />
<appender-ref ref="consoleAppender" />
</root>
</log4j:configuration>

View File

@ -15,41 +15,42 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>shared-poi-util</artifactId>
<groupId>de.muehlencord.shared</groupId> <dependencies>
<artifactId>shared-poi-util</artifactId> <dependency>
<artifactId>poi-ooxml</artifactId>
<groupId>org.apache.poi</groupId>
</dependency>
<dependency>
<artifactId>shared-util</artifactId>
<groupId>de.muehlencord.shared</groupId>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
<scope>provided</scope>
</dependency>
</dependencies>
<groupId>de.muehlencord.shared</groupId>
<modelVersion>4.0.0</modelVersion>
<name>shared-poi-util</name>
<packaging>jar</packaging>
<parent>
<artifactId>shared</artifactId>
<groupId>de.muehlencord</groupId>
<version>1.2-SNAPSHOT</version> <version>1.2-SNAPSHOT</version>
<packaging>jar</packaging> </parent>
<parent>
<groupId>de.muehlencord</groupId>
<artifactId>shared</artifactId>
<version>1.2-SNAPSHOT</version>
</parent>
<name>shared-poi-util</name>
<dependencies> <version>1.2-SNAPSHOT</version>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-util</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project> </project>

742
pom.xml
View File

@ -15,393 +15,397 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>de.muehlencord</groupId> <artifactId>shared</artifactId>
<artifactId>shared</artifactId> <build>
<version>1.2-SNAPSHOT</version> <pluginManagement>
<packaging>pom</packaging> <plugins>
<name>shared</name> <!-- build archive -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<showDeprecation>true</showDeprecation>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<version>3.8.1</version>
</plugin>
<modules> <!-- build maven ejb artifacts -->
<module>configuration</module> <plugin>
<module>network</module> <artifactId>maven-ejb-plugin</artifactId>
<module>util</module> <groupId>org.apache.maven.plugins</groupId>
<module>jeeutil</module> <version>3.0.1</version>
<module>shiro-faces</module> </plugin>
<module>poi-util</module>
<module>db</module>
</modules>
<scm> <!-- create new releases -->
<connection>scm:git:https://jomu.timelord.de/git/jomu/shared/</connection> <plugin>
<developerConnection>scm:git:https://jomu.timelord.de/git/jomu/shared/</developerConnection> <artifactId>maven-release-plugin</artifactId>
<url>https://jomu.timelord.de/git/jomu/shared/</url> <version>2.5.3</version>
<tag>HEAD</tag> </plugin>
</scm>
<issueManagement> <!-- control junit tests from maven build -->
<system>Gitea</system> <plugin>
<url>https://jomu.timelord.de/git/jomu/shared/issues</url> <artifactId>maven-surefire-plugin</artifactId>
</issueManagement> <groupId>org.apache.maven.plugins</groupId>
<version>2.22.2</version>
<licenses> </plugin>
<license> </plugins>
<name>Apache License, Version 2.0</name> </pluginManagement>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>Joern Muehlencord</name>
<email>joern@muehlencord.de</email>
</developer>
</developers>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<properties>
<!-- project setup -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-db</artifactId>
<version>1.2-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-shiro-faces</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-util</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-jeeutil</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.11.3</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.23.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>com.github.adminfaces</groupId>
<artifactId>admin-template</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>io.fusionauth</groupId>
<artifactId>fusionauth-jwt</artifactId>
<version>4.1.0</version>
</dependency>
<!-- Dev Tools -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<version>1.18.16</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<profiles> <plugins>
<profile> <plugin>
<id>release</id> <artifactId>maven-compiler-plugin</artifactId>
<build> <groupId>org.apache.maven.plugins</groupId>
<plugins> </plugin>
<!-- deploy artifacts to maven repository --> <plugin>
<plugin> <artifactId>maven-release-plugin</artifactId>
<groupId>org.sonatype.plugins</groupId> <configuration>
<artifactId>nexus-staging-maven-plugin</artifactId> <tagNameFormat>v@{project.version}</tagNameFormat>
<version>1.6.8</version> </configuration>
<extensions>true</extensions> <version>2.5.3</version>
<configuration> </plugin>
<serverId>ossrh</serverId> <plugin>
<nexusUrl>https://oss.sonatype.org/</nexusUrl> <artifactId>maven-surefire-plugin</artifactId>
<autoReleaseAfterClose>true</autoReleaseAfterClose> <groupId>org.apache.maven.plugins</groupId>
</configuration> </plugin>
</plugin> </plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>shared-db</artifactId>
<groupId>de.muehlencord.shared</groupId>
<type>ejb</type>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>shared-shiro-faces</artifactId>
<groupId>de.muehlencord.shared</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>shared-util</artifactId>
<groupId>de.muehlencord.shared</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>shared-jeeutil</artifactId>
<groupId>de.muehlencord.shared</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
<version>1.15</version>
</dependency>
<dependency>
<artifactId>commons-net</artifactId>
<groupId>commons-net</groupId>
<version>3.8.0</version>
</dependency>
<dependency>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
<version>3.12.0</version>
</dependency>
<dependency>
<artifactId>commons-io</artifactId>
<groupId>commons-io</groupId>
<version>2.11.0</version>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
<version>${slf4j.version}</version>
</dependency>
<!-- ensure sources are build so they are also uploaded --> <dependency>
<plugin> <artifactId>javax.mail</artifactId>
<groupId>org.apache.maven.plugins</groupId> <groupId>com.sun.mail</groupId>
<artifactId>maven-source-plugin</artifactId> <version>1.6.2</version>
<version>3.1.0</version> </dependency>
<executions> <dependency>
<execution> <artifactId>ews-java-api</artifactId>
<id>attach-sources</id> <groupId>com.microsoft.ews-java-api</groupId>
<goals> <version>2.0</version>
<goal>jar-no-fork</goal> </dependency>
</goals> <dependency>
</execution> <artifactId>gson</artifactId>
</executions> <groupId>com.google.code.gson</groupId>
</plugin> <version>2.8.9</version>
</dependency>
<dependency>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<type>jar</type>
<version>${jackson.version}</version>
</dependency>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<type>jar</type>
<version>${jackson.version}</version>
</dependency>
<dependency>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<artifactId>shiro-core</artifactId>
<groupId>org.apache.shiro</groupId>
<version>1.7.1</version>
</dependency>
<dependency>
<artifactId>shiro-web</artifactId>
<groupId>org.apache.shiro</groupId>
<version>1.7.1</version>
</dependency>
<dependency>
<artifactId>javaee-api</artifactId>
<groupId>javax</groupId>
<version>8.0.1</version>
</dependency>
<dependency>
<artifactId>javaee-web-api</artifactId>
<groupId>javax</groupId>
<scope>provided</scope>
<version>8.0.1</version>
</dependency>
<dependency>
<artifactId>scrypt</artifactId>
<groupId>com.lambdaworks</groupId>
<version>1.4.0</version>
</dependency>
<dependency>
<artifactId>bcprov-jdk15on</artifactId>
<groupId>org.bouncycastle</groupId>
<version>1.68</version>
</dependency>
<!-- ensure java doc is built --> <dependency>
<plugin> <artifactId>hibernate-core</artifactId>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.hibernate</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <type>jar</type>
<version>3.1.1</version> <version>5.4.23.Final</version>
<executions> </dependency>
<execution> <dependency>
<id>attach-javadocs</id> <artifactId>primefaces</artifactId>
<goals> <groupId>org.primefaces</groupId>
<goal>jar</goal> <version>10.0.0</version>
</goals> </dependency>
</execution> <dependency>
</executions> <artifactId>admin-template</artifactId>
</plugin> <groupId>com.github.adminfaces</groupId>
<version>1.3.0</version>
</dependency>
<dependency>
<artifactId>omnifaces</artifactId>
<groupId>org.omnifaces</groupId>
<version>3.4.1</version>
</dependency>
<dependency>
<artifactId>poi-ooxml</artifactId>
<groupId>org.apache.poi</groupId>
<version>5.0.0</version>
</dependency>
<dependency>
<artifactId>fusionauth-jwt</artifactId>
<groupId>io.fusionauth</groupId>
<version>4.1.0</version>
</dependency>
<!-- create license file --> <!-- Dev Tools -->
<plugin> <dependency>
<groupId>org.codehaus.mojo</groupId> <artifactId>lombok</artifactId>
<artifactId>license-maven-plugin</artifactId> <groupId>org.projectlombok</groupId>
<version>1.14</version> <scope>provided</scope>
<executions> <version>1.18.22</version>
<execution> </dependency>
<id>download-licenses</id>
<phase>generate-resources</phase>
<goals>
<goal>download-licenses</goal>
<goal>add-third-party</goal>
</goals>
<configuration>
<licensesOutputDirectory>${licenses.dir}</licensesOutputDirectory>
<outputDirectory>${licenses.dir}</outputDirectory>
<licenseMerges>
<licenseMerge>The Apache Software License, Version 2.0|Apache 2|Apache License, Version 2.0|Apache Public License 2.0</licenseMerge>
</licenseMerges>
</configuration>
</execution>
</executions>
</plugin>
<!-- sign jar archives --> <!-- Testing -->
<plugin> <dependency>
<groupId>org.apache.maven.plugins</groupId> <artifactId>junit-jupiter-engine</artifactId>
<artifactId>maven-gpg-plugin</artifactId> <groupId>org.junit.jupiter</groupId>
<version>1.6</version> <scope>test</scope>
<executions> <version>5.8.1</version>
<execution> </dependency>
<id>sign-artifacts</id> </dependencies>
<phase>verify</phase> </dependencyManagement>
<goals> <developers>
<goal>sign</goal> <developer>
</goals> <email>joern@muehlencord.de</email>
</execution> <name>Joern Muehlencord</name>
</executions> </developer>
<configuration> </developers>
<keyname>993245E2EC7608BB</keyname> <distributionManagement>
</configuration> <repository>
</plugin> <id>ossrh</id>
</plugins> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</build> </repository>
</profile> <snapshotRepository>
</profiles> <id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<groupId>de.muehlencord</groupId>
<build> <issueManagement>
<pluginManagement> <system>Gitea</system>
<plugins> <url>https://jomu.timelord.de/git/jomu/shared/issues</url>
<!-- build archive --> </issueManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<!-- build maven ejb artifacts --> <licenses>
<plugin> <license>
<groupId>org.apache.maven.plugins</groupId> <distribution>repo</distribution>
<artifactId>maven-ejb-plugin</artifactId> <name>Apache License, Version 2.0</name>
<version>3.0.1</version> <url>http://www.apache.org/licenses/LICENSE-2.0</url>
</plugin> </license>
</licenses>
<!-- create new releases --> <modelVersion>4.0.0</modelVersion>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
<!-- control junit tests from maven build --> <modules>
<plugin> <module>configuration</module>
<groupId>org.apache.maven.plugins</groupId> <module>network</module>
<artifactId>maven-surefire-plugin</artifactId> <module>util</module>
<version>2.22.2</version> <module>jeeutil</module>
</plugin> <module>shiro-faces</module>
</plugins> <module>poi-util</module>
</pluginManagement> <module>db</module>
</modules>
<name>shared</name>
<packaging>pom</packaging>
<profiles>
<profile>
<build>
<plugins> <plugins>
<plugin> <!-- deploy artifacts to maven repository -->
<groupId>org.apache.maven.plugins</groupId> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>nexus-staging-maven-plugin</artifactId>
</plugin> <configuration>
<plugin> <autoReleaseAfterClose>true</autoReleaseAfterClose>
<artifactId>maven-release-plugin</artifactId> <nexusUrl>https://oss.sonatype.org/</nexusUrl>
<version>2.5.3</version> <serverId>ossrh</serverId>
</configuration>
<extensions>true</extensions>
<groupId>org.sonatype.plugins</groupId>
<version>1.6.8</version>
</plugin>
<!-- ensure sources are build so they are also uploaded -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
<id>attach-sources</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>3.1.0</version>
</plugin>
<!-- ensure java doc is built -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<id>attach-javadocs</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>3.1.1</version>
</plugin>
<!-- create license file -->
<plugin>
<artifactId>license-maven-plugin</artifactId>
<executions>
<execution>
<configuration> <configuration>
<tagNameFormat>v@{project.version}</tagNameFormat> <licenseMerges>
<licenseMerge>The Apache Software License, Version 2.0|Apache 2|Apache License, Version 2.0|Apache Public License 2.0</licenseMerge>
</licenseMerges>
<licensesOutputDirectory>${licenses.dir}</licensesOutputDirectory>
<outputDirectory>${licenses.dir}</outputDirectory>
</configuration> </configuration>
</plugin> <goals>
<plugin> <goal>download-licenses</goal>
<groupId>org.apache.maven.plugins</groupId> <goal>add-third-party</goal>
<artifactId>maven-surefire-plugin</artifactId> </goals>
</plugin> <id>download-licenses</id>
<phase>generate-resources</phase>
</execution>
</executions>
<groupId>org.codehaus.mojo</groupId>
<version>1.14</version>
</plugin>
<!-- sign jar archives -->
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<keyname>993245E2EC7608BB</keyname>
</configuration>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
<id>sign-artifacts</id>
<phase>verify</phase>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>1.6</version>
</plugin>
</plugins> </plugins>
</build> </build>
<id>release</id>
</profile>
</profiles>
<properties>
<!-- project setup -->
<jackson.version>2.13.0</jackson.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>1.7.32</slf4j.version>
</properties>
<scm>
<connection>scm:git:https://jomu.timelord.de/git/jomu/shared/</connection>
<developerConnection>scm:git:https://jomu.timelord.de/git/jomu/shared/</developerConnection>
<tag>HEAD</tag>
<url>https://jomu.timelord.de/git/jomu/shared/</url>
</scm>
<version>1.2-SNAPSHOT</version>
</project> </project>

View File

@ -28,7 +28,7 @@ public abstract class AbstractAccessControlTag extends AbstractTag {
protected TagAttribute attribute; protected TagAttribute attribute;
public AbstractAccessControlTag(TagConfig config) { protected AbstractAccessControlTag(TagConfig config) {
super(config); super(config);
} }

View File

@ -19,42 +19,41 @@ import java.io.IOException;
import javax.faces.component.UIComponent; import javax.faces.component.UIComponent;
import javax.faces.view.facelets.FaceletContext; import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.TagConfig; import javax.faces.view.facelets.TagConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public abstract class AbstractAuthenticationTag extends AbstractTag { public abstract class AbstractAuthenticationTag extends AbstractTag {
protected AbstractAuthenticationTag(TagConfig config) { private static final Logger logger = LoggerFactory.getLogger(AbstractAuthenticationTag.class);
super(config);
protected AbstractAuthenticationTag(TagConfig config) {
super(config);
}
protected abstract boolean isAuthenticated();
protected boolean applyTagHandler() {
if (isAuthenticated()) {
if (logger.isTraceEnabled()) {
logger.trace("Authentication verified, tag will be evaluated");
}
return true;
} else {
if (logger.isTraceEnabled()) {
logger.trace("Authentifaction verification failed, tag will not be evaluated");
}
return false;
} }
}
protected abstract boolean isAuthenticated(); @Override
public void apply(FaceletContext fc, UIComponent uic) throws IOException {
protected boolean applyTagHandler() { if (applyTagHandler()) {
if (isAuthenticated()) { this.nextHandler.apply(fc, uic);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Authentication verified, tag will be evaluated");
}
return true;
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace ("Authentifaction verification failed, tag will not be evaluated");
}
return false;
}
} }
}
@Override
public void apply(FaceletContext fc, UIComponent uic) throws IOException {
if (applyTagHandler()) {
this.nextHandler.apply(fc, uic);
}
}
} }

View File

@ -19,8 +19,6 @@ import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler; import javax.faces.view.facelets.TagHandler;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -28,9 +26,7 @@ import org.slf4j.LoggerFactory;
*/ */
public abstract class AbstractTag extends TagHandler { public abstract class AbstractTag extends TagHandler {
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTag.class); protected AbstractTag(TagConfig config) {
public AbstractTag(TagConfig config) {
super(config); super(config);
} }

View File

@ -24,29 +24,28 @@ import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class StreamUtils { public interface StreamUtils {
public static <T> Collector<T, ?, T> singletonCollector() { default <T> Collector<T, ?, T> singletonCollector() {
return getCollectorFunction(getListTSingleFunction()); return getCollectorFunction(getListTSingleFunction());
} }
private static <T> Collector<T, ?, T> getCollectorFunction(Function<List<T>, T> listTFunction) { default <T> Collector<T, ?, T> getCollectorFunction(Function<List<T>, T> listTFunction) {
return Collectors.collectingAndThen(Collectors.toList(), listTFunction); return Collectors.collectingAndThen(Collectors.toList(), listTFunction);
} }
private static <T> Function<List<T>, T> getListTSingleFunction() { default <T> Function<List<T>, T> getListTSingleFunction() {
return list -> { return list -> {
if (list == null) { if (list == null) {
throw new IllegalStateException("List must not be null"); throw new IllegalStateException("List must not be null");
} }
if (list.size() != 1) { if (list.size() != 1) {
throw new IllegalStateException("List contains not exactly one element (size=" + list.size() + ")"); throw new IllegalStateException("List contains not exactly one element (size=" + list.size() + ")");
} }
return list.get(0); return list.get(0);
}; };
} }
} }

View File

@ -21,7 +21,7 @@ package de.muehlencord.shared.util;
*/ */
public class StringEncodingException extends Exception { public class StringEncodingException extends Exception {
protected final static String DEFAULT_MSG = "An encoding exception occurred"; protected static final String DEFAULT_MSG = "An encoding exception occurred";
/** /**
* Creates a new instance of * Creates a new instance of

View File

@ -15,38 +15,38 @@
*/ */
package de.muehlencord.shared.util; package de.muehlencord.shared.util;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** /**
*
* @author Joern Muehlencord (joern@muehlencord.de) * @author Joern Muehlencord (joern@muehlencord.de)
*/ */
public class StringEncodingExceptionTest { class StringEncodingExceptionTest {
@Test @Test
public void testDefaultConstructor() { void testDefaultConstructor() {
StringEncodingException ex = new StringEncodingException(); StringEncodingException ex = new StringEncodingException();
assertTrue (ex.getMessage().equals (StringEncodingException.DEFAULT_MSG)); assertEquals(StringEncodingException.DEFAULT_MSG, ex.getMessage());
} }
@Test @Test
public void testMessageConstructor() { void testMessageConstructor() {
String msg = "Test message"; String msg = "Test message";
StringEncodingException ex = new StringEncodingException(msg); StringEncodingException ex = new StringEncodingException(msg);
assertTrue (ex.getMessage().equals (msg)); assertEquals(ex.getMessage(), msg);
} }
@Test @Test
public void testRootcauseConstructor() { void testRootcauseConstructor() {
String msg = "Test message"; String msg = "Test message";
StringEncodingException rootCause = new StringEncodingException(); StringEncodingException rootCause = new StringEncodingException();
StringEncodingException ex = new StringEncodingException(msg, rootCause); StringEncodingException ex = new StringEncodingException(msg, rootCause);
assertTrue (ex.getMessage().equals (msg)); assertEquals(ex.getMessage(), msg);
assertTrue (ex.getCause().equals (rootCause)); assertEquals(ex.getCause(), rootCause);
} }
} }