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

19
pom.xml
View File

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

View File

@ -11,7 +11,7 @@ import jakarta.ws.rs.ext.ExceptionMapper;
public class JacksonCatcher implements ExceptionMapper<JsonProcessingException> { public class JacksonCatcher implements ExceptionMapper<JsonProcessingException> {
private static final Logger LOGGER = LoggerFactory.getLogger(JacksonCatcher.class); private static final Logger LOGGER = LoggerFactory.getLogger(JacksonCatcher.class);
@Override @Override
public Response toResponse(final JsonProcessingException exception) { public Response toResponse(final JsonProcessingException exception) {
LOGGER.warn("Catch exception Input data parsing:"); LOGGER.warn("Catch exception Input data parsing:");
@ -20,9 +20,9 @@ public class JacksonCatcher implements ExceptionMapper<JsonProcessingException>
exception.printStackTrace(); exception.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ret).type(MediaType.APPLICATION_JSON).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ret).type(MediaType.APPLICATION_JSON).build();
} }
private RestErrorResponse build(final Exception exception) { private RestErrorResponse build(final Exception exception) {
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch JSON Exception", exception.getMessage()); 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 { try {
this.connection = DriverManager.getConnection(this.config.getUrl(true), this.config.getLogin(), this.config.getPassword()); this.connection = DriverManager.getConnection(this.config.getUrl(true), this.config.getLogin(), this.config.getPassword());
} catch (final SQLException ex) { } 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 { try {
this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(), this.config.getPassword()); this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(), this.config.getPassword());
} catch (final SQLException ex) { } 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 !!!"); abortWithForbidden(requestContext, "Access blocked !!!");
return; return;
} }
// Access allowed for all // Access allowed for all
if (method.isAnnotationPresent(PermitAll.class)) { if (method.isAnnotationPresent(PermitAll.class)) {
// logger.debug(" ==> permit all " + requestContext.getUriInfo().getPath()); // logger.debug(" ==> permit all " + requestContext.getUriInfo().getPath());
@ -74,7 +74,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
abortWithForbidden(requestContext, "Access ILLEGAL !!!"); abortWithForbidden(requestContext, "Access ILLEGAL !!!");
return; return;
} }
// Get the Authorization header from the request // Get the Authorization header from the request
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION); String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
String apikeyHeader = requestContext.getHeaderString(APIKEY); String apikeyHeader = requestContext.getHeaderString(APIKEY);
@ -129,7 +129,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
abortWithUnauthorized(requestContext, "get a NULL application ..."); abortWithUnauthorized(requestContext, "get a NULL application ...");
return; return;
} }
} }
// create the security context model: // create the security context model:
final String scheme = requestContext.getUriInfo().getRequestUri().getScheme(); final String scheme = requestContext.getUriInfo().getRequestUri().getScheme();
@ -161,7 +161,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
// The authentication scheme comparison must be case-insensitive // The authentication scheme comparison must be case-insensitive
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " "); return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " ");
} }
private void abortWithUnauthorized(final ContainerRequestContext requestContext, final String message) { private void abortWithUnauthorized(final ContainerRequestContext requestContext, final String message) {
// Abort the filter chain with a 401 status code response // 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/ // https://simplapi.wordpress.com/2015/09/19/jersey-jax-rs-securitycontext-in-action/
class MySecurityContext implements SecurityContext { class MySecurityContext implements SecurityContext {
private final GenericContext contextPrincipale; private final GenericContext contextPrincipale;
private final String sheme; private final String sheme;
public MySecurityContext(final UserByToken userByToken, final String sheme) { public MySecurityContext(final UserByToken userByToken, final String sheme) {
this.contextPrincipale = new GenericContext(userByToken); this.contextPrincipale = new GenericContext(userByToken);
this.sheme = sheme; this.sheme = sheme;
} }
@Override @Override
public Principal getUserPrincipal() { public Principal getUserPrincipal() {
return this.contextPrincipale; return this.contextPrincipale;
} }
@Override @Override
public boolean isUserInRole(final String role) { public boolean isUserInRole(final String role) {
if (this.contextPrincipale.userByToken != null) { if (this.contextPrincipale.userByToken != null) {
@ -32,12 +32,12 @@ class MySecurityContext implements SecurityContext {
} }
return false; return false;
} }
@Override @Override
public boolean isSecure() { public boolean isSecure() {
return "https".equalsIgnoreCase(this.sheme); return "https".equalsIgnoreCase(this.sheme);
} }
@Override @Override
public String getAuthenticationScheme() { public String getAuthenticationScheme() {
if (this.contextPrincipale.userByToken != null) { if (this.contextPrincipale.userByToken != null) {
@ -45,5 +45,5 @@ class MySecurityContext implements SecurityContext {
} }
return null; return null;
} }
} }

View File

@ -14,6 +14,9 @@ public class ConfigBaseVariable {
static public String ssoAdress; static public String ssoAdress;
static public String ssoToken; static public String ssoToken;
static public String testMode; static public String testMode;
static public String eMailFrom;
static public String eMailLogin;
static public String eMailPassword;
// For test only // For test only
public static void clearAllValue() { public static void clearAllValue() {
@ -30,6 +33,9 @@ public class ConfigBaseVariable {
ssoAdress = System.getenv("SSO_ADDRESS"); ssoAdress = System.getenv("SSO_ADDRESS");
ssoToken = System.getenv("SSO_TOKEN"); ssoToken = System.getenv("SSO_TOKEN");
testMode = System.getenv("TEST_MODE"); testMode = System.getenv("TEST_MODE");
eMailFrom = System.getenv("EMAIL_FROM");
eMailLogin = System.getenv("EMAIL_LOGIN");
eMailPassword = System.getenv("EMAIL_PASSWORD");
} }
static { static {
@ -120,4 +126,15 @@ public class ConfigBaseVariable {
} }
return Boolean.parseBoolean(testMode); 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 fi
} }
__run "1/1" "Check JAVA code format" "mvn formatter:verify" __run "1/1" "Check JAVA code format" "mvn formatter:validate"