Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 19fa13849e | |||
| 9ffebf1d1d | |||
| e35a1ae879 | |||
| 9c9cf85f92 | |||
| 1a2302f548 | |||
| 808784889b | |||
| f394254f38 | |||
| 0574d5da82 |
10
.classpath
10
.classpath
@@ -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,17 +18,17 @@
|
||||
<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"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="out/maven/classes"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
||||
4
.island/release.bash
Executable file
4
.island/release.bash
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
mvn versions:set -DnewVersion=$(cat version.txt)
|
||||
|
||||
@@ -84,7 +84,6 @@ Reformat XML file like the pom.xml
|
||||
XMLLINT_INDENT=" " xmllint --format "back/pom.xml" -o "back/pom.xml"
|
||||
```
|
||||
|
||||
|
||||
Enable the pre-commit checker
|
||||
-----------------------------
|
||||
|
||||
@@ -94,6 +93,8 @@ Enable the pre-commit checker
|
||||
|
||||
> **_Note_**: You can change the code in `.git/hooks/pre-commit` by replacing `formatter:verify` with `formatter:format` to auto format the code @ every commit
|
||||
|
||||
|
||||
|
||||
Add Gitea in the dependency for the registry:
|
||||
=============================================
|
||||
|
||||
|
||||
21
pom.xml
21
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>kangaroo-and-rabbit</groupId>
|
||||
<artifactId>archidata</artifactId>
|
||||
<version>0.6.0</version>
|
||||
<version>0.6.1</version>
|
||||
<properties>
|
||||
<maven.compiler.version>3.1</maven.compiler.version>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
@@ -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>
|
||||
|
||||
@@ -22,7 +22,7 @@ public class JacksonCatcher implements ExceptionMapper<JsonProcessingException>
|
||||
}
|
||||
|
||||
private RestErrorResponse build(final Exception exception) {
|
||||
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch Unknown Exception", exception.getMessage());
|
||||
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch JSON Exception", exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -960,7 +960,10 @@ public class DataAccess {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
|
||||
final Condition condition = options.get(Condition.class);
|
||||
Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
condition = new Condition();
|
||||
}
|
||||
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
@@ -979,9 +982,7 @@ public class DataAccess {
|
||||
generateSelectField(querySelect, query, clazz, options, count);
|
||||
querySelect.append(query.toString());
|
||||
query = querySelect;
|
||||
if (condition != null) {
|
||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||
}
|
||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||
final OrderBy orders = options.get(OrderBy.class);
|
||||
if (orders != null) {
|
||||
orders.generateQuerry(query, tableName);
|
||||
@@ -994,9 +995,7 @@ public class DataAccess {
|
||||
// prepare the request:
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
if (condition != null) {
|
||||
condition.injectQuerry(ps, iii);
|
||||
}
|
||||
condition.injectQuerry(ps, iii);
|
||||
if (limit != null) {
|
||||
limit.injectQuerry(ps, iii);
|
||||
}
|
||||
@@ -1066,7 +1065,10 @@ public class DataAccess {
|
||||
|
||||
public static long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
condition = new Condition();
|
||||
}
|
||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
long count = 0;
|
||||
@@ -1077,9 +1079,7 @@ public class DataAccess {
|
||||
query.append("SELECT COUNT(*) AS count FROM `");
|
||||
query.append(tableName);
|
||||
query.append("` ");
|
||||
if (condition != null) {
|
||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||
}
|
||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||
final Limit limit = options.get(Limit.class);
|
||||
if (limit != null) {
|
||||
limit.generateQuerry(query, tableName);
|
||||
@@ -1088,9 +1088,7 @@ public class DataAccess {
|
||||
// prepare the request:
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
if (condition != null) {
|
||||
condition.injectQuerry(ps, iii);
|
||||
}
|
||||
condition.injectQuerry(ps, iii);
|
||||
if (limit != null) {
|
||||
limit.injectQuerry(ps, iii);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToMany.class);
|
||||
static final String SEPARATOR = "-";
|
||||
|
||||
|
||||
/** Convert the list if external id in a string '-' separated
|
||||
* @param ids List of value (null are removed)
|
||||
* @return '-' string separated */
|
||||
@@ -34,12 +34,12 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
final List<Long> tmp = new ArrayList<>(ids);
|
||||
return tmp.stream().map(String::valueOf).collect(Collectors.joining(SEPARATOR));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<?> getAnnotationClass() {
|
||||
return SQLTableExternalForeinKeyAsList.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSQLFieldType(final Field field) throws Exception {
|
||||
final String fieldName = AnnotationTools.getFieldName(field);
|
||||
@@ -51,13 +51,13 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCompatibleField(final Field field) {
|
||||
final SQLTableExternalForeinKeyAsList decorators = field.getDeclaredAnnotation(SQLTableExternalForeinKeyAsList.class);
|
||||
return decorators != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void insertData(final PreparedStatement ps, final Field field, final Object rootObject, final CountInOut iii) throws SQLException, IllegalArgumentException, IllegalAccessException {
|
||||
final Object data = field.get(rootObject);
|
||||
@@ -70,22 +70,22 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
ps.setString(iii.value, dataTmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canInsert(final Field field) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInsertAsync(final Field field) throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canRetrieve(final Field field) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name,
|
||||
@NotNull final CountInOut elemCount, final QueryOptions options) {
|
||||
@@ -95,7 +95,7 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
querrySelect.append(".");
|
||||
querrySelect.append(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fillFromQuerry(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall)
|
||||
throws SQLException, IllegalArgumentException, IllegalAccessException {
|
||||
@@ -103,12 +103,12 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
field.set(data, idList);
|
||||
count.inc();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createTables(final String tableName, final Field field, final StringBuilder mainTableBuilder, final List<String> preActionList, final List<String> postActionList,
|
||||
final boolean createIfNotExist, final boolean createDrop, final int fieldId) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
DataFactory.createTablesSpecificType(tableName, field, mainTableBuilder, preActionList, postActionList, createIfNotExist, createDrop, fieldId, String.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
@Context
|
||||
private ResourceInfo resourceInfo;
|
||||
protected final String applicationName;
|
||||
|
||||
private static final String AUTHENTICATION_SCHEME = "Yota";
|
||||
private static final String AUTHENTICATION_TOKEN_SCHEME = "Zota";
|
||||
|
||||
|
||||
public static final String AUTHENTICATION_SCHEME = "Bearer";
|
||||
public static final String APIKEY = "ApiKey";
|
||||
|
||||
public AuthenticationFilter(final String applicationName) {
|
||||
this.applicationName = applicationName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void filter(final ContainerRequestContext requestContext) throws IOException {
|
||||
/* logger.debug("-----------------------------------------------------"); logger.debug("---- Check if have authorization ----");
|
||||
@@ -58,10 +58,10 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
// Access denied for all
|
||||
if (method.isAnnotationPresent(DenyAll.class)) {
|
||||
LOGGER.debug(" ==> deny all {}", requestContext.getUriInfo().getPath());
|
||||
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).entity("Access blocked !!!").build());
|
||||
abortWithForbidden(requestContext, "Access blocked !!!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Access allowed for all
|
||||
if (method.isAnnotationPresent(PermitAll.class)) {
|
||||
// logger.debug(" ==> permit all " + requestContext.getUriInfo().getPath());
|
||||
@@ -71,28 +71,28 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
// this is a security guard, all the API must define their access level:
|
||||
if (!method.isAnnotationPresent(RolesAllowed.class)) {
|
||||
LOGGER.error(" ==> missing @RolesAllowed {}", requestContext.getUriInfo().getPath());
|
||||
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).entity("Access ILLEGAL !!!").build());
|
||||
abortWithForbidden(requestContext, "Access ILLEGAL !!!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get the Authorization header from the request
|
||||
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
|
||||
String apikeyHeader = requestContext.getHeaderString(APIKEY);
|
||||
// logger.debug("authorizationHeader: {}", authorizationHeader);
|
||||
if (authorizationHeader == null && method.isAnnotationPresent(PermitTokenInURI.class)) {
|
||||
if (authorizationHeader == null && apikeyHeader == null && method.isAnnotationPresent(PermitTokenInURI.class)) {
|
||||
final MultivaluedMap<String, String> quaryparam = requestContext.getUriInfo().getQueryParameters();
|
||||
for (final Entry<String, List<String>> item : quaryparam.entrySet()) {
|
||||
if (item.getKey().equals(HttpHeaders.AUTHORIZATION)) {
|
||||
if (!item.getValue().isEmpty()) {
|
||||
authorizationHeader = item.getValue().get(0);
|
||||
}
|
||||
break;
|
||||
if ((authorizationHeader == null && HttpHeaders.AUTHORIZATION.equals(item.getKey())) && !item.getValue().isEmpty()) {
|
||||
authorizationHeader = item.getValue().get(0);
|
||||
}
|
||||
if ((apikeyHeader == null && APIKEY.equals(item.getKey())) && !item.getValue().isEmpty()) {
|
||||
apikeyHeader = item.getValue().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
// logger.debug("authorizationHeader: {}", authorizationHeader);
|
||||
final boolean isApplicationToken = isApplicationTokenBasedAuthentication(authorizationHeader);
|
||||
final boolean isApplicationToken = apikeyHeader != null;
|
||||
final boolean isJwtToken = isTokenBasedAuthentication(authorizationHeader);
|
||||
// Validate the Authorization header data Model "Yota jwt.to.ken" "Zota tokenId:hash(token)"
|
||||
if (!isApplicationToken && !isJwtToken) {
|
||||
LOGGER.warn("REJECTED unauthorized: {}", requestContext.getUriInfo().getPath());
|
||||
abortWithUnauthorized(requestContext, "REJECTED unauthorized: " + requestContext.getUriInfo().getPath());
|
||||
@@ -100,7 +100,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
}
|
||||
UserByToken userByToken = null;
|
||||
if (isJwtToken) {
|
||||
// Extract the token from the Authorization header (Remove "Yota ")
|
||||
// Extract the token from the Authorization header (Remove "Bearer ")
|
||||
final String token = authorizationHeader.substring(AUTHENTICATION_SCHEME.length()).trim();
|
||||
// logger.debug("token: {}", token);
|
||||
try {
|
||||
@@ -116,9 +116,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Extract the token from the Authorization header (Remove "Zota ")
|
||||
final String token = authorizationHeader.substring(AUTHENTICATION_TOKEN_SCHEME.length()).trim();
|
||||
// logger.debug("token: {}", token);
|
||||
final String token = apikeyHeader.trim();
|
||||
try {
|
||||
userByToken = validateToken(token);
|
||||
} catch (final Exception e) {
|
||||
@@ -131,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();
|
||||
@@ -156,23 +154,16 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
requestContext.setSecurityContext(userContext);
|
||||
// logger.debug("Get local user : {} / {}", user, userByToken);
|
||||
}
|
||||
|
||||
|
||||
private boolean isTokenBasedAuthentication(final String authorizationHeader) {
|
||||
// Check if the Authorization header is valid
|
||||
// It must not be null and must be prefixed with "Bearer" plus a whitespace
|
||||
// The authentication scheme comparison must be case-insensitive
|
||||
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " ");
|
||||
}
|
||||
|
||||
private boolean isApplicationTokenBasedAuthentication(final String authorizationHeader) {
|
||||
// Check if the Authorization header is valid
|
||||
// It must not be null and must be prefixed with "Bearer" plus a whitespace
|
||||
// The authentication scheme comparison must be case-insensitive
|
||||
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_TOKEN_SCHEME.toLowerCase() + " ");
|
||||
}
|
||||
|
||||
|
||||
private void abortWithUnauthorized(final ContainerRequestContext requestContext, final String message) {
|
||||
|
||||
|
||||
// Abort the filter chain with a 401 status code response
|
||||
// The WWW-Authenticate header is sent along with the response
|
||||
LOGGER.warn("abortWithUnauthorized:");
|
||||
@@ -181,12 +172,18 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
requestContext.abortWith(Response.status(ret.status).header(HttpHeaders.WWW_AUTHENTICATE, AUTHENTICATION_SCHEME + " base64(HEADER).base64(CONTENT).base64(KEY)").entity(ret)
|
||||
.type(MediaType.APPLICATION_JSON).build());
|
||||
}
|
||||
|
||||
|
||||
private void abortWithForbidden(final ContainerRequestContext requestContext, final String message) {
|
||||
final RestErrorResponse ret = new RestErrorResponse(Response.Status.FORBIDDEN, "FORBIDDEN", message);
|
||||
LOGGER.error("Error UUID={}", ret.uuid);
|
||||
requestContext.abortWith(Response.status(ret.status).header(HttpHeaders.WWW_AUTHENTICATE, message).entity(ret).type(MediaType.APPLICATION_JSON).build());
|
||||
}
|
||||
|
||||
protected UserByToken validateToken(final String authorization) throws Exception {
|
||||
LOGGER.info("Must be Override by the application implmentation, otherwise it dose not work");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// must be override to be good implementation
|
||||
protected UserByToken validateJwtToken(final String authorization) throws Exception {
|
||||
// logger.debug(" validate token : " + authorization);
|
||||
|
||||
@@ -35,13 +35,13 @@ class MySecurityContext implements SecurityContext {
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return this.sheme.equalsIgnoreCase("https");
|
||||
return "https".equalsIgnoreCase(this.sheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthenticationScheme() {
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
return "Zota";
|
||||
return "Bearer";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.filter.AuthenticationFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -33,7 +34,7 @@ import com.nimbusds.jwt.SignedJWT;
|
||||
|
||||
class TestSigner implements JWSSigner {
|
||||
public static String test_signature = "TEST_SIGNATURE_FOR_LOCAL_TEST_AND_TEST_E2E";
|
||||
|
||||
|
||||
/** Signs the specified {@link JWSObject#getSigningInput input} of a {@link JWSObject JWS object}.
|
||||
*
|
||||
* @param header The JSON Web Signature (JWS) header. Must specify a supported JWS algorithm and must not be {@code null}.
|
||||
@@ -47,13 +48,13 @@ class TestSigner implements JWSSigner {
|
||||
public Base64URL sign(final JWSHeader header, final byte[] signingInput) throws JOSEException {
|
||||
return new Base64URL(test_signature);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<JWSAlgorithm> supportedJWSAlgorithms() {
|
||||
// TODO Auto-generated method stub
|
||||
return Set.of(JWSAlgorithm.RS256);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JCAContext getJCAContext() {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -63,20 +64,20 @@ class TestSigner implements JWSSigner {
|
||||
|
||||
public class JWTWrapper {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(JWTWrapper.class);
|
||||
|
||||
private static RSAKey rsaJWK = null;;
|
||||
|
||||
private static RSAKey rsaJWK = null;
|
||||
private static RSAKey rsaPublicJWK = null;
|
||||
|
||||
|
||||
public static class PublicKey {
|
||||
public String key;
|
||||
|
||||
|
||||
public PublicKey(final String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
||||
public PublicKey() {}
|
||||
}
|
||||
|
||||
|
||||
public static void initLocalTokenRemote(final String ssoUri, final String application) throws IOException, ParseException {
|
||||
// check Token:
|
||||
final URL obj = new URL(ssoUri + "public_key");
|
||||
@@ -89,14 +90,14 @@ public class JWTWrapper {
|
||||
con.setRequestProperty("Accept", "application/json");
|
||||
final String ssoToken = ConfigBaseVariable.ssoToken();
|
||||
if (ssoToken != null) {
|
||||
con.setRequestProperty("Authorization", "Zota " + ssoToken);
|
||||
con.setRequestProperty(AuthenticationFilter.APIKEY, ssoToken);
|
||||
}
|
||||
final int responseCode = con.getResponseCode();
|
||||
|
||||
|
||||
// LOGGER.debug("GET Response Code :: {}", responseCode);
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||
final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
|
||||
|
||||
String inputLine;
|
||||
final StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
@@ -112,7 +113,7 @@ public class JWTWrapper {
|
||||
}
|
||||
LOGGER.debug("GET JWT validator token not worked response code {} from {} ", responseCode, obj);
|
||||
}
|
||||
|
||||
|
||||
public static void initLocalToken(final String baseUUID) throws Exception {
|
||||
// RSA signatures require a public and private RSA key pair, the public key
|
||||
// must be made known to the JWS recipient in order to verify the signatures
|
||||
@@ -136,7 +137,7 @@ public class JWTWrapper {
|
||||
rsaPublicJWK = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void initValidateToken(final String publicKey) {
|
||||
try {
|
||||
rsaPublicJWK = RSAKey.parse(publicKey);
|
||||
@@ -144,16 +145,16 @@ public class JWTWrapper {
|
||||
e.printStackTrace();
|
||||
LOGGER.debug("Can not retrieve public Key !!!!!!!! RSAKey='{}'", publicKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String getPublicKeyJson() {
|
||||
if (rsaPublicJWK == null) {
|
||||
return null;
|
||||
}
|
||||
return rsaPublicJWK.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
public static java.security.interfaces.RSAPublicKey getPublicKeyJava() throws JOSEException {
|
||||
if (rsaPublicJWK == null) {
|
||||
return null;
|
||||
@@ -161,7 +162,7 @@ public class JWTWrapper {
|
||||
// Convert back to std Java interface
|
||||
return rsaPublicJWK.toRSAPublicKey();
|
||||
}
|
||||
|
||||
|
||||
/** Create a token with the provided elements
|
||||
* @param userID UniqueId of the USER (global unique ID)
|
||||
* @param userLogin Login of the user (never change)
|
||||
@@ -178,12 +179,12 @@ public class JWTWrapper {
|
||||
try {
|
||||
// Create RSA-signer with the private key
|
||||
final JWSSigner signer = new RSASSASigner(rsaJWK);
|
||||
|
||||
|
||||
LOGGER.warn("timeOutInMunites= {}", timeOutInMunites);
|
||||
final Date now = new Date();
|
||||
LOGGER.warn("now = {}", now);
|
||||
final Date expiration = new Date(new Date().getTime() - 60 * timeOutInMunites * 1000 /* millisecond */);
|
||||
|
||||
|
||||
LOGGER.warn("expiration= {}", expiration);
|
||||
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID)).claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
|
||||
.expirationTime(expiration); // Do not ask why we need a "-" here ... this have no meaning
|
||||
@@ -194,7 +195,7 @@ public class JWTWrapper {
|
||||
// Prepare JWT with claims set
|
||||
final JWTClaimsSet claimsSet = builder.build();
|
||||
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
|
||||
|
||||
|
||||
// Compute the RSA signature
|
||||
signedJWT.sign(signer);
|
||||
// serialize the output...
|
||||
@@ -204,7 +205,7 @@ public class JWTWrapper {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static JWTClaimsSet validateToken(final String signedToken, final String isuer, final String application) {
|
||||
try {
|
||||
// On the consumer side, parse the JWS and verify its RSA signature
|
||||
@@ -244,14 +245,12 @@ public class JWTWrapper {
|
||||
// LOGGER.debug("JWT token is verified 'alice' =?= '" + signedJWT.getJWTClaimsSet().getSubject() + "'");
|
||||
// LOGGER.debug("JWT token isuer 'https://c2id.com' =?= '" + signedJWT.getJWTClaimsSet().getIssuer() + "'");
|
||||
return signedJWT.getJWTClaimsSet();
|
||||
} catch (final JOSEException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (final ParseException e) {
|
||||
} catch (final JOSEException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String createJwtTestToken(final long userID, final String userLogin, final String isuer, final String application, final Map<String, Map<String, Object>> rights) {
|
||||
if (!ConfigBaseVariable.getTestMode()) {
|
||||
LOGGER.error("Test mode disable !!!!!");
|
||||
@@ -259,10 +258,10 @@ public class JWTWrapper {
|
||||
}
|
||||
try {
|
||||
final int timeOutInMunites = 3600;
|
||||
|
||||
|
||||
final Date now = new Date();
|
||||
final Date expiration = new Date(new Date().getTime() + timeOutInMunites * 1000 /* ms */);
|
||||
|
||||
|
||||
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID)).claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
|
||||
.expirationTime(expiration); // Do not ask why we need a "-" here ... this have no meaning
|
||||
// add right if needed:
|
||||
@@ -272,10 +271,10 @@ public class JWTWrapper {
|
||||
// Prepare JWT with claims set
|
||||
final JWTClaimsSet claimsSet = builder.build();
|
||||
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
|
||||
|
||||
|
||||
// Compute the RSA signature
|
||||
signedJWT.sign(new TestSigner());
|
||||
|
||||
|
||||
// serialize the output...
|
||||
return signedJWT.serialize();
|
||||
} catch (final Exception ex) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RESTApi {
|
||||
final HttpClient client = HttpClient.newHttpClient();
|
||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
||||
if (this.token != null) {
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||
}
|
||||
final HttpRequest request = requestBuilding.GET().build();
|
||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
@@ -111,7 +111,7 @@ public class RESTApi {
|
||||
LOGGER.trace("call {}: {}", model, URI.create(this.baseUrl + urlOffset));
|
||||
LOGGER.trace("DATA: {}", body);
|
||||
if (this.token != null) {
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||
}
|
||||
if (body == null) {
|
||||
body = "";
|
||||
@@ -143,7 +143,7 @@ public class RESTApi {
|
||||
String body = null;
|
||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
||||
if (this.token != null) {
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||
}
|
||||
if (data == null) {
|
||||
body = "";
|
||||
@@ -171,7 +171,7 @@ public class RESTApi {
|
||||
final HttpClient client = HttpClient.newHttpClient();
|
||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
||||
if (this.token != null) {
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||
}
|
||||
final HttpRequest request = requestBuilding.DELETE().build();
|
||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.6.0
|
||||
0.6.1
|
||||
|
||||
Reference in New Issue
Block a user