[DEV] add email properties

This commit is contained in:
Edouard DUPIN 2024-01-17 20:19:10 +01:00
parent f394254f38
commit 808784889b
8 changed files with 53 additions and 25 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="out/maven/classes" path="src">
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="out/maven/test-classes" path="test/src">
<classpathentry kind="src" output="target/test-classes" path="test/src">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
@ -18,7 +18,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="out/maven/test-classes" path="test/resources">
<classpathentry excluding="**" kind="src" output="target/test-classes" path="test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -30,5 +30,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="out/maven/classes"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

19
pom.xml
View File

@ -158,9 +158,20 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.1</version>
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.23.0</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory>
@ -241,7 +252,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<version>3.3.1</version>
<configuration>
<configLocation>CheckStyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
@ -253,7 +264,7 @@
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.12.2</version>
<version>2.23.0</version>
<configuration>
<encoding>UTF-8</encoding>
<lineEnding>LF</lineEnding>

View File

@ -11,7 +11,7 @@ import jakarta.ws.rs.ext.ExceptionMapper;
public class JacksonCatcher implements ExceptionMapper<JsonProcessingException> {
private static final Logger LOGGER = LoggerFactory.getLogger(JacksonCatcher.class);
@Override
public Response toResponse(final JsonProcessingException exception) {
LOGGER.warn("Catch exception Input data parsing:");
@ -20,9 +20,9 @@ public class JacksonCatcher implements ExceptionMapper<JsonProcessingException>
exception.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ret).type(MediaType.APPLICATION_JSON).build();
}
private RestErrorResponse build(final Exception exception) {
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch JSON Exception", exception.getMessage());
}
}

View File

@ -52,7 +52,7 @@ public class DBEntry implements Closeable {
try {
this.connection = DriverManager.getConnection(this.config.getUrl(true), this.config.getLogin(), this.config.getPassword());
} catch (final SQLException ex) {
throw new IOException("Connection db fail: " + ex.getMessage());
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
}
}
@ -61,7 +61,7 @@ public class DBEntry implements Closeable {
try {
this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(), this.config.getPassword());
} catch (final SQLException ex) {
throw new IOException("Connection db fail: " + ex.getMessage());
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
}
}

View File

@ -61,7 +61,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
abortWithForbidden(requestContext, "Access blocked !!!");
return;
}
// Access allowed for all
if (method.isAnnotationPresent(PermitAll.class)) {
// logger.debug(" ==> permit all " + requestContext.getUriInfo().getPath());
@ -74,7 +74,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
abortWithForbidden(requestContext, "Access ILLEGAL !!!");
return;
}
// Get the Authorization header from the request
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
String apikeyHeader = requestContext.getHeaderString(APIKEY);
@ -129,7 +129,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
abortWithUnauthorized(requestContext, "get a NULL application ...");
return;
}
}
// create the security context model:
final String scheme = requestContext.getUriInfo().getRequestUri().getScheme();
@ -161,7 +161,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
// The authentication scheme comparison must be case-insensitive
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " ");
}
private void abortWithUnauthorized(final ContainerRequestContext requestContext, final String message) {
// Abort the filter chain with a 401 status code response

View File

@ -8,20 +8,20 @@ import jakarta.ws.rs.core.SecurityContext;
// https://simplapi.wordpress.com/2015/09/19/jersey-jax-rs-securitycontext-in-action/
class MySecurityContext implements SecurityContext {
private final GenericContext contextPrincipale;
private final String sheme;
public MySecurityContext(final UserByToken userByToken, final String sheme) {
this.contextPrincipale = new GenericContext(userByToken);
this.sheme = sheme;
}
@Override
public Principal getUserPrincipal() {
return this.contextPrincipale;
}
@Override
public boolean isUserInRole(final String role) {
if (this.contextPrincipale.userByToken != null) {
@ -32,12 +32,12 @@ class MySecurityContext implements SecurityContext {
}
return false;
}
@Override
public boolean isSecure() {
return "https".equalsIgnoreCase(this.sheme);
}
@Override
public String getAuthenticationScheme() {
if (this.contextPrincipale.userByToken != null) {
@ -45,5 +45,5 @@ class MySecurityContext implements SecurityContext {
}
return null;
}
}

View File

@ -14,6 +14,9 @@ public class ConfigBaseVariable {
static public String ssoAdress;
static public String ssoToken;
static public String testMode;
static public String eMailFrom;
static public String eMailLogin;
static public String eMailPassword;
// For test only
public static void clearAllValue() {
@ -30,6 +33,9 @@ public class ConfigBaseVariable {
ssoAdress = System.getenv("SSO_ADDRESS");
ssoToken = System.getenv("SSO_TOKEN");
testMode = System.getenv("TEST_MODE");
eMailFrom = System.getenv("EMAIL_FROM");
eMailLogin = System.getenv("EMAIL_LOGIN");
eMailPassword = System.getenv("EMAIL_PASSWORD");
}
static {
@ -120,4 +126,15 @@ public class ConfigBaseVariable {
}
return Boolean.parseBoolean(testMode);
}
public record EMailConfig(String from, String login, String password) {
};
public static EMailConfig getEMailConfig() {
if (eMailFrom == null || eMailLogin == null || eMailPassword == null) {
return null;
}
return new EMailConfig(eMailFrom, eMailLogin, eMailPassword);
}
}

View File

@ -23,5 +23,5 @@ function __run() #(step, name, cmd)
fi
}
__run "1/1" "Check JAVA code format" "mvn formatter:verify"
__run "1/1" "Check JAVA code format" "mvn formatter:validate"