1
0

use @Slf4j (+logback) for logging instead of System.out/err.println (#165)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/165
Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
Michael Hoennig
2025-03-19 16:21:55 +01:00
parent eb9edf1cb1
commit 4994bac101
13 changed files with 60 additions and 39 deletions

View File

@@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.config;
import io.micrometer.core.annotation.Timed;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.util.LinkedMultiValueMap;
@@ -14,6 +15,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
// HOWTO add logger
@Slf4j
public class RealCasAuthenticator implements CasAuthenticator {
@Value("${hsadminng.cas.server}")
@@ -32,7 +35,8 @@ public class RealCasAuthenticator implements CasAuthenticator {
? fetchServiceTicket(ticket)
: ticket;
final var userName = extractUserName(verifyServiceTicket(serviceTicket));
System.err.println("CAS-user: " + userName);
// HOWTO log some message for a certain log level (trace, debug, info, warn, error)
log.debug("CAS-user: {}", userName);
return userName;
}
@@ -65,9 +69,7 @@ public class RealCasAuthenticator implements CasAuthenticator {
private String extractUserName(final Document verification) {
if (verification.getElementsByTagName("cas:authenticationSuccess").getLength() == 0) {
System.err.println("CAS service ticket could not be validated");
System.err.println(verification);
throwBadCredentialsException("CAS service ticket could not be validated");
throwBadCredentialsException("CAS service ticket could not be verified");
}
return verification.getElementsByTagName("cas:user").item(0).getTextContent();
}

View File

@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
import static net.hostsharing.hsadminng.errors.CustomErrorResponse.*;
@ControllerAdvice
// HOWTO handle exceptions to produce specific http error codes and sensible error messages
public class RestResponseEntityExceptionHandler
extends ResponseEntityExceptionHandler {

View File

@@ -121,10 +121,4 @@ public final class HashGenerator {
}
return withSalt(stringBuilder.toString());
}
public static void main(String[] args) {
System.out.println(
HashGenerator.using(Algorithm.LINUX_YESCRYPT).withRandomSalt().hash("my plaintext domain transfer passphrase")
);
}
}

View File

@@ -125,10 +125,4 @@ public class Dns {
return Result.fromException(exception);
}
}
public static void main(String[] args) {
final var result = new Dns("example.org").fetchRecordsOfType("TXT");
System.out.println(result);
}
}

View File

@@ -1261,15 +1261,11 @@ public class RbacSpec {
m -> isStatic(m.getModifiers()) && m.getName().equals("main")
)
.findFirst()
.orElse(null);
if (mainMethod != null) {
try {
mainMethod.invoke(null, new Object[] { null });
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
System.err.println("WARNING: no main method in: " + c.getName() + " => no RBAC rules generated");
.orElseThrow(() -> new RuntimeException("no main method in: " + c.getName() + " => cannot generate RBAC rules"));
try {
mainMethod.invoke(null, new Object[] { null });
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}

View File

@@ -202,6 +202,5 @@ public class RbacViewMermaidFlowchartGenerator {
.replace("%{flowchart}", flowchart.toString())
.replace("%{case}", forCase == null ? "" : " " + forCase),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
System.out.println("Markdown-File: " + path.toAbsolutePath());
}
}

View File

@@ -49,6 +49,5 @@ public class RbacViewPostgresGenerator {
toString(),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
System.out.println(outputPath.toAbsolutePath());
}
}

View File

@@ -358,9 +358,6 @@ class RolesGrantsAndPermissionsGenerator {
}
private String roleRef(final PostgresTriggerReference rootRefVar, final RbacSpec.RbacRoleDefinition roleDef) {
if (roleDef == null) {
System.out.println("null");
}
if (roleDef.getEntityAlias().isGlobal()) {
return "rbac.global_ADMIN()";
}

View File

@@ -68,8 +68,10 @@ metrics:
server:
requests: true
# HOWTO set logging-levels for certain Java packages (trace, debug, info, warn, error)
logging:
level:
org:
springframework:
security: TRACE
org.springframework.security: info
# HOWTO configure logging, e.g. logging to a separate file, see:
# https://docs.spring.io/spring-boot/reference/features/logging.html