summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java43
1 files changed, 16 insertions, 27 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java
index ebfe7500..83ea7da0 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/AuthenticatedEncryptionPendingRequestIdGenerationStrategy.java
@@ -1,6 +1,6 @@
package at.gv.egiz.eaaf.core.impl.utils;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.security.Provider;
import java.util.Base64;
@@ -98,10 +98,10 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
}
return Base64.getUrlEncoder()
- .encodeToString(encToken.getCompactSerialization().getBytes("UTF-8"));
+ .encodeToString(encToken.getCompactSerialization().getBytes(StandardCharsets.UTF_8));
- } catch (final JoseException | UnsupportedEncodingException e) {
- throw new EaafException("internal.99", new Object[] { e.getMessage() }, e);
+ } catch (final JoseException e) {
+ throw new EaafException("internal.pendingreqid.02", new Object[] { e.getMessage() }, e);
}
@@ -117,7 +117,7 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
if (!(StringUtils.countMatches(stringToken, TOKEN_SEPARATOR) == ENCODED_TOKEN_PARTS - 1)) {
log.warn("PendingRequestId has an unvalid format");
log.debug("PendingRequestId: {}", stringToken);
- throw new PendingReqIdValidationException(null, "PendingReqId has an unvalid format");
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.01");
}
@@ -125,13 +125,10 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
StringUtils.split(stringToken, TOKEN_SEPARATOR, ENCODED_TOKEN_PARTS);
return tokenElements[1];
- } catch (final UnsupportedEncodingException e) {
- throw new RuntimeException(e);
-
} catch (JoseException e) {
log.warn("Token is NOT a valid String. Msg: {}", e.getMessage());
log.debug("TokenValue: {}", externalPendingReqId);
- throw new PendingReqIdValidationException(null, "PendingReqId is NOT a valid String", e);
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.05", e);
}
}
@@ -144,9 +141,8 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
log.debug("Token decryption successful");
if (!(StringUtils.countMatches(stringToken, TOKEN_SEPARATOR) == ENCODED_TOKEN_PARTS - 1)) {
- log.warn("PendingRequestId has an unvalid format");
- log.debug("PendingRequestId: {}", stringToken);
- throw new PendingReqIdValidationException(null, "PendingReqId has an unvalid format");
+ log.info("PendingRequestId: {}", stringToken);
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.01");
}
@@ -155,16 +151,13 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
final String internalPendingReqId = tokenElements[1];
final DateTime timeStamp = TOKEN_TEXTUAL_DATE_FORMAT.parseDateTime(tokenElements[0]);
-
-
log.trace("Checking valid period ... ");
final DateTime now = DateTime.now();
if (timeStamp.withFieldAdded(DurationFieldType.seconds(), maxPendingRequestIdLifeTime)
.isBefore(now)) {
- log.warn("Token exceeds the valid period");
- log.debug("Token: {} | Now: {}", timeStamp, now);
+ log.info("Token exceeds the valid period. Token: {} | Now: {}", timeStamp, now);
throw new PendingReqIdValidationException(internalPendingReqId,
- "PendingRequestId exceeds the valid period");
+ "internal.pendingreqid.06");
}
log.debug("Token valid-period check successful");
@@ -174,25 +167,22 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
} catch (JoseException e) {
log.warn("Token is NOT a valid encrypt. Msg: {}", e.getMessage());
log.debug("TokenValue: {}", externalPendingReqId);
- throw new PendingReqIdValidationException(null, "PendingReqId is NOT a valid encrypted", e);
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.04", e);
} catch (final IllegalArgumentException e) {
log.warn("Token is NOT a valid String. Msg: {}", e.getMessage());
log.debug("TokenValue: {}", externalPendingReqId);
- throw new PendingReqIdValidationException(null, "PendingReqId is NOT a valid String", e);
-
- } catch (final UnsupportedEncodingException e) {
- throw new RuntimeException(e);
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.05", e);
}
}
@Nonnull
private String getDecryptedExternalPendingRequestId(String externalPendingReqId)
- throws JoseException, PendingReqIdValidationException, UnsupportedEncodingException {
+ throws JoseException, PendingReqIdValidationException {
if (StringUtils.isEmpty(externalPendingReqId)) {
log.info("PendingReqId is 'null' or empty");
- throw new PendingReqIdValidationException(null, "PendingReqId is 'null' or empty");
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.00");
}
@@ -201,8 +191,7 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
if (externalPendingReqIdBytes.length > maxPendingReqIdSize) {
log.warn("pendingReqId size exceeds {}", maxPendingReqIdSize);
- throw new PendingReqIdValidationException(null,
- "pendingReqId exceeds max.size: " + maxPendingReqIdSize);
+ throw new PendingReqIdValidationException(null, "internal.pendingreqid.03");
}
@@ -225,7 +214,7 @@ public class AuthenticatedEncryptionPendingRequestIdGenerationStrategy
}
- encToken.setCompactSerialization(new String(externalPendingReqIdBytes, "UTF-8"));
+ encToken.setCompactSerialization(new String(externalPendingReqIdBytes, StandardCharsets.UTF_8));
return encToken.getPayload();
}