[STYLE] fix style
This commit is contained in:
parent
de08bcfab5
commit
3fa48fc839
25
pom.xml
25
pom.xml
@ -56,29 +56,28 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!-- Decode webP images -->
|
<!-- Decode webP images -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio-webp</artifactId>
|
<artifactId>imageio-webp</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Decode JPEG image -->
|
<!-- Decode JPEG image -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio-jpeg</artifactId>
|
<artifactId>imageio-jpeg</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Encode file in webp -->
|
<!-- Encode file in webp -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.gotson</groupId>
|
<groupId>com.github.gotson</groupId>
|
||||||
<artifactId>webp-imageio</artifactId>
|
<artifactId>webp-imageio</artifactId>
|
||||||
<version>0.2.2</version>
|
<version>0.2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Detect type of a file with mime type -->
|
<!-- Detect type of a file with mime type -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tika</groupId>
|
<groupId>org.apache.tika</groupId>
|
||||||
<artifactId>tika-core</artifactId>
|
<artifactId>tika-core</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
|
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
@ -64,18 +64,18 @@ public class DataResource {
|
|||||||
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
||||||
/** Upload some datas */
|
/** Upload some datas */
|
||||||
private static long tmpFolderId = 1;
|
private static long tmpFolderId = 1;
|
||||||
|
|
||||||
private static void createFolder(final String path) throws IOException {
|
private static void createFolder(final String path) throws IOException {
|
||||||
if (!Files.exists(java.nio.file.Path.of(path))) {
|
if (!Files.exists(java.nio.file.Path.of(path))) {
|
||||||
// Log.print("Create folder: " + path);
|
// Log.print("Create folder: " + path);
|
||||||
Files.createDirectories(java.nio.file.Path.of(path));
|
Files.createDirectories(java.nio.file.Path.of(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getTmpDataId() {
|
public static long getTmpDataId() {
|
||||||
return tmpFolderId++;
|
return tmpFolderId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTmpFileInData(final long tmpFolderId) {
|
public static String getTmpFileInData(final long tmpFolderId) {
|
||||||
final String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId;
|
final String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId;
|
||||||
try {
|
try {
|
||||||
@ -85,7 +85,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileDataOld(final long tmpFolderId) {
|
public static String getFileDataOld(final long tmpFolderId) {
|
||||||
final String filePath = ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator
|
final String filePath = ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator
|
||||||
+ "data";
|
+ "data";
|
||||||
@ -96,7 +96,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileData(final UUID uuid) {
|
public static String getFileData(final UUID uuid) {
|
||||||
final String stringUUID = uuid.toString();
|
final String stringUUID = uuid.toString();
|
||||||
final String part1 = stringUUID.substring(0, 2);
|
final String part1 = stringUUID.substring(0, 2);
|
||||||
@ -113,11 +113,11 @@ public class DataResource {
|
|||||||
filePath += part3;
|
filePath += part3;
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileMetaData(final UUID uuid) {
|
public static String getFileMetaData(final UUID uuid) {
|
||||||
return getFileData(uuid) + ".json";
|
return getFileData(uuid) + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data getWithSha512(final String sha512) {
|
public static Data getWithSha512(final String sha512) {
|
||||||
LOGGER.info("find sha512 = {}", sha512);
|
LOGGER.info("find sha512 = {}", sha512);
|
||||||
try {
|
try {
|
||||||
@ -128,7 +128,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data getWithId(final long id) {
|
public static Data getWithId(final long id) {
|
||||||
LOGGER.info("find id = {}", id);
|
LOGGER.info("find id = {}", id);
|
||||||
try {
|
try {
|
||||||
@ -139,7 +139,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// determine mime type:
|
// determine mime type:
|
||||||
@ -159,7 +159,7 @@ public class DataResource {
|
|||||||
injectedData.sha512 = sha512;
|
injectedData.sha512 = sha512;
|
||||||
final String tmpPath = getTmpFileInData(tmpUID);
|
final String tmpPath = getTmpFileInData(tmpUID);
|
||||||
injectedData.size = Files.size(Paths.get(tmpPath));
|
injectedData.size = Files.size(Paths.get(tmpPath));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
injectedData = DataAccess.insert(injectedData);
|
injectedData = DataAccess.insert(injectedData);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@ -173,7 +173,7 @@ public class DataResource {
|
|||||||
LOGGER.info("Move done");
|
LOGGER.info("Move done");
|
||||||
return injectedData;
|
return injectedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void modeFileOldModelToNewModel(final long id, final UUID uuid) throws IOException {
|
public static void modeFileOldModelToNewModel(final long id, final UUID uuid) throws IOException {
|
||||||
String mediaCurentPath = getFileDataOld(id);
|
String mediaCurentPath = getFileDataOld(id);
|
||||||
String mediaDestPath = getFileData(uuid);
|
String mediaDestPath = getFileData(uuid);
|
||||||
@ -192,12 +192,12 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
LOGGER.info("Move done");
|
LOGGER.info("Move done");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String saveTemporaryFile(final InputStream uploadedInputStream, final long idData)
|
public static String saveTemporaryFile(final InputStream uploadedInputStream, final long idData)
|
||||||
throws FailException {
|
throws FailException {
|
||||||
return saveFile(uploadedInputStream, DataResource.getTmpFileInData(idData));
|
return saveFile(uploadedInputStream, DataResource.getTmpFileInData(idData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeTemporaryFile(final long idData) {
|
public static void removeTemporaryFile(final long idData) {
|
||||||
final String filepath = DataResource.getTmpFileInData(idData);
|
final String filepath = DataResource.getTmpFileInData(idData);
|
||||||
if (Files.exists(Paths.get(filepath))) {
|
if (Files.exists(Paths.get(filepath))) {
|
||||||
@ -209,7 +209,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save uploaded file to a defined location on the server
|
// save uploaded file to a defined location on the server
|
||||||
static String saveFile(final InputStream uploadedInputStream, final String serverLocation) throws FailException {
|
static String saveFile(final InputStream uploadedInputStream, final String serverLocation) throws FailException {
|
||||||
String out = "";
|
String out = "";
|
||||||
@ -243,7 +243,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String bytesToHex(final byte[] bytes) {
|
public static String bytesToHex(final byte[] bytes) {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (final byte b : bytes) {
|
for (final byte b : bytes) {
|
||||||
@ -251,7 +251,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Data getSmall(final UUID id) {
|
public Data getSmall(final UUID id) {
|
||||||
try {
|
try {
|
||||||
return DataAccess.get(Data.class, id);
|
return DataAccess.get(Data.class, id);
|
||||||
@ -261,7 +261,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/upload/")
|
@Path("/upload/")
|
||||||
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
@ -286,7 +286,7 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
saveFile(fileInputStream, filePath);
|
saveFile(fileInputStream, filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{uuid}")
|
@Path("{uuid}")
|
||||||
@PermitTokenInURI
|
@PermitTokenInURI
|
||||||
@ -313,7 +313,7 @@ public class DataResource {
|
|||||||
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
|
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("thumbnail/{uuid}")
|
@Path("thumbnail/{uuid}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@ -400,7 +400,7 @@ public class DataResource {
|
|||||||
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
|
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{uuid}/{name}")
|
@Path("{uuid}/{name}")
|
||||||
@PermitTokenInURI
|
@PermitTokenInURI
|
||||||
@ -424,7 +424,7 @@ public class DataResource {
|
|||||||
return buildStream(getFileData(uuid), range,
|
return buildStream(getFileData(uuid), range,
|
||||||
value.mimeType == null ? "application/octet-stream" : value.mimeType);
|
value.mimeType == null ? "application/octet-stream" : value.mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adapted from http://stackoverflow.com/questions/12768812/video-streaming-to-ipad-does-not-work-with-tapestry5/12829541#12829541
|
/** Adapted from http://stackoverflow.com/questions/12768812/video-streaming-to-ipad-does-not-work-with-tapestry5/12829541#12829541
|
||||||
*
|
*
|
||||||
* @param range range header
|
* @param range range header
|
||||||
@ -463,12 +463,12 @@ public class DataResource {
|
|||||||
out.type(mimeType);
|
out.type(mimeType);
|
||||||
}
|
}
|
||||||
return out.build();
|
return out.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] ranges = range.split("=")[1].split("-");
|
final String[] ranges = range.split("=")[1].split("-");
|
||||||
final long from = Long.parseLong(ranges[0]);
|
final long from = Long.parseLong(ranges[0]);
|
||||||
|
|
||||||
// logger.info("request range : {}", ranges.length);
|
// logger.info("request range : {}", ranges.length);
|
||||||
// Chunk media if the range upper bound is unspecified. Chrome, Opera sends "bytes=0-"
|
// Chunk media if the range upper bound is unspecified. Chrome, Opera sends "bytes=0-"
|
||||||
long to = CHUNK_SIZE + from;
|
long to = CHUNK_SIZE + from;
|
||||||
@ -481,7 +481,7 @@ public class DataResource {
|
|||||||
// logger.info("responseRange: {}", responseRange);
|
// logger.info("responseRange: {}", responseRange);
|
||||||
try (final RandomAccessFile raf = new RandomAccessFile(file, "r")) {
|
try (final RandomAccessFile raf = new RandomAccessFile(file, "r")) {
|
||||||
raf.seek(from);
|
raf.seek(from);
|
||||||
|
|
||||||
final long len = to - from + 1;
|
final long len = to - from + 1;
|
||||||
final MediaStreamer streamer = new MediaStreamer(len, raf);
|
final MediaStreamer streamer = new MediaStreamer(len, raf);
|
||||||
final Response.ResponseBuilder out = Response.ok(streamer).status(Response.Status.PARTIAL_CONTENT)
|
final Response.ResponseBuilder out = Response.ok(streamer).status(Response.Status.PARTIAL_CONTENT)
|
||||||
@ -498,9 +498,9 @@ public class DataResource {
|
|||||||
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to access to the required file.", ex);
|
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to access to the required file.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void undelete(final Long id) throws Exception {
|
public static void undelete(final Long id) throws Exception {
|
||||||
DataAccess.unsetDelete(Data.class, id);
|
DataAccess.unsetDelete(Data.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import jakarta.ws.rs.core.Response.Status;
|
|||||||
//@Produces(MediaType.APPLICATION_JSON)
|
//@Produces(MediaType.APPLICATION_JSON)
|
||||||
public class ProxyResource {
|
public class ProxyResource {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProxyResource.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProxyResource.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
public Response getImageFromUrl(@QueryParam("url") final String url) {
|
public Response getImageFromUrl(@QueryParam("url") final String url) {
|
||||||
|
@ -27,7 +27,7 @@ public class RestErrorResponse {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Column(length = 0)
|
@Column(length = 0)
|
||||||
final public String statusMessage;
|
final public String statusMessage;
|
||||||
|
|
||||||
public RestErrorResponse(final Response.Status status, final String time, final String error,
|
public RestErrorResponse(final Response.Status status, final String time, final String error,
|
||||||
final String message) {
|
final String message) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
@ -36,7 +36,7 @@ public class RestErrorResponse {
|
|||||||
this.status = status.getStatusCode();
|
this.status = status.getStatusCode();
|
||||||
this.statusMessage = status.getReasonPhrase();
|
this.statusMessage = status.getReasonPhrase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestErrorResponse(final Response.Status status, final String error, final String message) {
|
public RestErrorResponse(final Response.Status status, final String error, final String message) {
|
||||||
this.time = Instant.now().toString();
|
this.time = Instant.now().toString();
|
||||||
this.name = error;
|
this.name = error;
|
||||||
@ -44,7 +44,7 @@ public class RestErrorResponse {
|
|||||||
this.status = status.getStatusCode();
|
this.status = status.getStatusCode();
|
||||||
this.statusMessage = status.getReasonPhrase();
|
this.statusMessage = status.getReasonPhrase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestErrorResponse(final Response.Status status) {
|
public RestErrorResponse(final Response.Status status) {
|
||||||
this.name = "generic";
|
this.name = "generic";
|
||||||
this.message = "";
|
this.message = "";
|
||||||
@ -52,5 +52,5 @@ public class RestErrorResponse {
|
|||||||
this.status = status.getStatusCode();
|
this.status = status.getStatusCode();
|
||||||
this.statusMessage = status.getReasonPhrase();
|
this.statusMessage = status.getReasonPhrase();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import org.kar.archidata.externalRestApi.typescript.TsClassElementGroup;
|
|||||||
public class TsGenerateApi {
|
public class TsGenerateApi {
|
||||||
/**
|
/**
|
||||||
* Generate a full API tree for Typescript in a specific folder.
|
* Generate a full API tree for Typescript in a specific folder.
|
||||||
* This generate a folder containing a full API with "model" filder and "api" folder.
|
* This generate a folder containing a full API with "model" folder and "api" folder.
|
||||||
* The generation depend of Zod and can be strict compile.
|
* The generation depend of Zod and can be strict compile.
|
||||||
* @param api Data model to generate the api
|
* @param api Data model to generate the api
|
||||||
* @param pathPackage Path to store the api.
|
* @param pathPackage Path to store the api.
|
||||||
|
@ -35,7 +35,7 @@ import com.nimbusds.jwt.SignedJWT;
|
|||||||
|
|
||||||
class TestSigner implements JWSSigner {
|
class TestSigner implements JWSSigner {
|
||||||
public static String test_signature = "TEST_SIGNATURE_FOR_LOCAL_TEST_AND_TEST_E2E";
|
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}.
|
/** 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}.
|
* @param header The JSON Web Signature (JWS) header. Must specify a supported JWS algorithm and must not be {@code null}.
|
||||||
@ -49,13 +49,13 @@ class TestSigner implements JWSSigner {
|
|||||||
public Base64URL sign(final JWSHeader header, final byte[] signingInput) throws JOSEException {
|
public Base64URL sign(final JWSHeader header, final byte[] signingInput) throws JOSEException {
|
||||||
return new Base64URL(test_signature);
|
return new Base64URL(test_signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<JWSAlgorithm> supportedJWSAlgorithms() {
|
public Set<JWSAlgorithm> supportedJWSAlgorithms() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return Set.of(JWSAlgorithm.RS256);
|
return Set.of(JWSAlgorithm.RS256);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JCAContext getJCAContext() {
|
public JCAContext getJCAContext() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
@ -65,20 +65,20 @@ class TestSigner implements JWSSigner {
|
|||||||
|
|
||||||
public class JWTWrapper {
|
public class JWTWrapper {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(JWTWrapper.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(JWTWrapper.class);
|
||||||
|
|
||||||
private static RSAKey rsaJWK = null;
|
private static RSAKey rsaJWK = null;
|
||||||
private static RSAKey rsaPublicJWK = null;
|
private static RSAKey rsaPublicJWK = null;
|
||||||
|
|
||||||
public static class PublicKey {
|
public static class PublicKey {
|
||||||
public String key;
|
public String key;
|
||||||
|
|
||||||
public PublicKey(final String key) {
|
public PublicKey(final String key) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublicKey() {}
|
public PublicKey() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initLocalTokenRemote(final String ssoUri, final String application)
|
public static void initLocalTokenRemote(final String ssoUri, final String application)
|
||||||
throws IOException, ParseException {
|
throws IOException, ParseException {
|
||||||
// check Token:
|
// check Token:
|
||||||
@ -95,11 +95,11 @@ public class JWTWrapper {
|
|||||||
con.setRequestProperty(AuthenticationFilter.APIKEY, ssoToken);
|
con.setRequestProperty(AuthenticationFilter.APIKEY, ssoToken);
|
||||||
}
|
}
|
||||||
final int responseCode = con.getResponseCode();
|
final int responseCode = con.getResponseCode();
|
||||||
|
|
||||||
// LOGGER.debug("GET Response Code :: {}", responseCode);
|
// LOGGER.debug("GET Response Code :: {}", responseCode);
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||||
final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
|
||||||
String inputLine;
|
String inputLine;
|
||||||
final StringBuffer response = new StringBuffer();
|
final StringBuffer response = new StringBuffer();
|
||||||
while ((inputLine = in.readLine()) != null) {
|
while ((inputLine = in.readLine()) != null) {
|
||||||
@ -115,7 +115,7 @@ public class JWTWrapper {
|
|||||||
}
|
}
|
||||||
LOGGER.debug("GET JWT validator token not worked response code {} from {} ", responseCode, obj);
|
LOGGER.debug("GET JWT validator token not worked response code {} from {} ", responseCode, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initLocalToken(final String baseUUID) throws Exception {
|
public static void initLocalToken(final String baseUUID) throws Exception {
|
||||||
// RSA signatures require a public and private RSA key pair, the public key
|
// 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
|
// must be made known to the JWS recipient in order to verify the signatures
|
||||||
@ -139,7 +139,7 @@ public class JWTWrapper {
|
|||||||
rsaPublicJWK = null;
|
rsaPublicJWK = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initValidateToken(final String publicKey) {
|
public static void initValidateToken(final String publicKey) {
|
||||||
try {
|
try {
|
||||||
rsaPublicJWK = RSAKey.parse(publicKey);
|
rsaPublicJWK = RSAKey.parse(publicKey);
|
||||||
@ -147,16 +147,16 @@ public class JWTWrapper {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LOGGER.debug("Can not retrieve public Key !!!!!!!! RSAKey='{}'", publicKey);
|
LOGGER.debug("Can not retrieve public Key !!!!!!!! RSAKey='{}'", publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPublicKeyJson() {
|
public static String getPublicKeyJson() {
|
||||||
if (rsaPublicJWK == null) {
|
if (rsaPublicJWK == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return rsaPublicJWK.toJSONString();
|
return rsaPublicJWK.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static java.security.interfaces.RSAPublicKey getPublicKeyJava() throws JOSEException {
|
public static java.security.interfaces.RSAPublicKey getPublicKeyJava() throws JOSEException {
|
||||||
if (rsaPublicJWK == null) {
|
if (rsaPublicJWK == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -164,7 +164,7 @@ public class JWTWrapper {
|
|||||||
// Convert back to std Java interface
|
// Convert back to std Java interface
|
||||||
return rsaPublicJWK.toRSAPublicKey();
|
return rsaPublicJWK.toRSAPublicKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a token with the provided elements
|
/** Create a token with the provided elements
|
||||||
* @param userID UniqueId of the USER (global unique ID)
|
* @param userID UniqueId of the USER (global unique ID)
|
||||||
* @param userLogin Login of the user (never change)
|
* @param userLogin Login of the user (never change)
|
||||||
@ -187,12 +187,12 @@ public class JWTWrapper {
|
|||||||
try {
|
try {
|
||||||
// Create RSA-signer with the private key
|
// Create RSA-signer with the private key
|
||||||
final JWSSigner signer = new RSASSASigner(rsaJWK);
|
final JWSSigner signer = new RSASSASigner(rsaJWK);
|
||||||
|
|
||||||
LOGGER.warn("timeOutInMunites= {}", timeOutInMunites);
|
LOGGER.warn("timeOutInMunites= {}", timeOutInMunites);
|
||||||
final Date now = new Date();
|
final Date now = new Date();
|
||||||
LOGGER.warn("now = {}", now);
|
LOGGER.warn("now = {}", now);
|
||||||
final Date expiration = new Date(new Date().getTime() - 60 * timeOutInMunites * 1000 /* millisecond */);
|
final Date expiration = new Date(new Date().getTime() - 60 * timeOutInMunites * 1000 /* millisecond */);
|
||||||
|
|
||||||
LOGGER.warn("expiration= {}", expiration);
|
LOGGER.warn("expiration= {}", expiration);
|
||||||
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID))
|
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID))
|
||||||
.claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
|
.claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
|
||||||
@ -205,7 +205,7 @@ public class JWTWrapper {
|
|||||||
final JWTClaimsSet claimsSet = builder.build();
|
final JWTClaimsSet claimsSet = builder.build();
|
||||||
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)
|
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)
|
||||||
/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
|
/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
|
||||||
|
|
||||||
// Compute the RSA signature
|
// Compute the RSA signature
|
||||||
signedJWT.sign(signer);
|
signedJWT.sign(signer);
|
||||||
// serialize the output...
|
// serialize the output...
|
||||||
@ -215,7 +215,7 @@ public class JWTWrapper {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JWTClaimsSet validateToken(final String signedToken, final String isuer, final String application) {
|
public static JWTClaimsSet validateToken(final String signedToken, final String isuer, final String application) {
|
||||||
try {
|
try {
|
||||||
// On the consumer side, parse the JWS and verify its RSA signature
|
// On the consumer side, parse the JWS and verify its RSA signature
|
||||||
@ -267,7 +267,7 @@ public class JWTWrapper {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createJwtTestToken(
|
public static String createJwtTestToken(
|
||||||
final long userID,
|
final long userID,
|
||||||
final String userLogin,
|
final String userLogin,
|
||||||
@ -280,10 +280,10 @@ public class JWTWrapper {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final int timeOutInMunites = 3600;
|
final int timeOutInMunites = 3600;
|
||||||
|
|
||||||
final Date now = new Date();
|
final Date now = new Date();
|
||||||
final Date expiration = new Date(new Date().getTime() + timeOutInMunites * 1000 /* ms */);
|
final Date expiration = new Date(new Date().getTime() + timeOutInMunites * 1000 /* ms */);
|
||||||
|
|
||||||
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID))
|
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID))
|
||||||
.claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
|
.claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
|
||||||
.expirationTime(expiration); // Do not ask why we need a "-" here ... this have no meaning
|
.expirationTime(expiration); // Do not ask why we need a "-" here ... this have no meaning
|
||||||
@ -295,10 +295,10 @@ public class JWTWrapper {
|
|||||||
final JWTClaimsSet claimsSet = builder.build();
|
final JWTClaimsSet claimsSet = builder.build();
|
||||||
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)
|
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)
|
||||||
/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
|
/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
|
||||||
|
|
||||||
// Compute the RSA signature
|
// Compute the RSA signature
|
||||||
signedJWT.sign(new TestSigner());
|
signedJWT.sign(new TestSigner());
|
||||||
|
|
||||||
// serialize the output...
|
// serialize the output...
|
||||||
return signedJWT.serialize();
|
return signedJWT.serialize();
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user