diff options
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java')
-rw-r--r-- | eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java index eb32d03f..a4f60ddc 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java @@ -23,7 +23,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Date; +import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -49,12 +49,17 @@ import at.gv.egiz.eaaf.core.api.idp.IConfigurationWithSP; import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration; import at.gv.egiz.eaaf.core.exceptions.EaafAuthenticationException; import at.gv.egiz.eaaf.core.exceptions.EaafException; +import at.gv.egiz.eaaf.core.exceptions.EaafJsonMapperException; import at.gv.egiz.eaaf.core.exceptions.EaafStorageException; import at.gv.egiz.eaaf.core.impl.http.HttpUtils; import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper; import at.gv.egiz.eaaf.core.impl.json.EscapedJsonDeserializer; import at.gv.egiz.eaaf.core.impl.json.EscapedJsonSerializer; +import at.gv.egiz.eaaf.core.impl.utils.DefaultJsonMapper; import at.gv.egiz.eaaf.core.impl.utils.TransactionIdUtils; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -172,9 +177,9 @@ public abstract class RequestImpl implements IRequest, Serializable { uniquePiiTransactionIdentifier = UUID.randomUUID().toString(); } - // initialize session object - genericDataStorage.put(EaafConstants.AUTH_DATA_CREATED, new Date()); + genericDataStorage.put(EaafConstants.AUTH_DATA_CREATED, + AuthProcessDataWrapper.buildDateTimeUtcString(Instant.now())); // genericDataStorage.put(EAAFConstants.VALUE_SESSIONID, // Random.nextLongRandom()); @@ -500,7 +505,7 @@ public abstract class RequestImpl implements IRequest, Serializable { @Override public final Object getRawData(final String key) { if (StringUtils.isNotEmpty(key)) { - return genericDataStorage.get(key); + return objectSaveJsonDeserialization(genericDataStorage.get(key)); } @@ -515,19 +520,18 @@ public abstract class RequestImpl implements IRequest, Serializable { if (data == null) { return null; + } try { - @SuppressWarnings("unchecked") - final T test = (T) data; - return test; + Object deserializedObject = objectSaveJsonDeserialization(data); + return deserializedObject != null ? (T) deserializedObject : null; } catch (final Exception e) { log.warn("Generic request-data object can not be casted to requested type", e); return null; } - } log.info("Can not load generic request-data with key='null'"); @@ -544,7 +548,6 @@ public abstract class RequestImpl implements IRequest, Serializable { null); } - if (object != null && !Serializable.class.isInstance(object)) { log.warn( "Generic request-data can only store objects which implements the 'Seralizable' interface"); @@ -559,7 +562,7 @@ public abstract class RequestImpl implements IRequest, Serializable { log.trace("Add generic request-data with key:" + key + " to session."); } - genericDataStorage.put(key, object); + genericDataStorage.put(key, objectSaveJsonSerialization(object)); } @@ -580,4 +583,50 @@ public abstract class RequestImpl implements IRequest, Serializable { } + private String objectSaveJsonSerialization(Object object) throws EaafStorageException { + try { + return DefaultJsonMapper.serialize(RawDataHolder.builder() + .object(DefaultJsonMapper.serialize(object)) + .clazzzType(object.getClass().getName()) + .build()); + + } catch (EaafJsonMapperException e) { + throw new EaafStorageException("Can no serialize object to JSON", e); + + } + } + + private Object objectSaveJsonDeserialization(Object data) { + try { + if (data instanceof String) { + RawDataHolder holder = (RawDataHolder) DefaultJsonMapper.deserialize( + (String) data, RawDataHolder.class); + Class<?> clz = Class.forName(holder.getClazzzType()); + return DefaultJsonMapper.deserialize(holder.getObject(), clz); + + } else { + log.error("Can not deserialize: {} because it's not of type String", data.getClass().getName()); + + } + } catch (final Exception e) { + log.warn("Generic request-data object can not be casted to requested type", e); + + } + return null; + + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + private static class RawDataHolder implements Serializable { + private static final long serialVersionUID = -8127401393932687928L; + + private String object; + + private String clazzzType; + + } + } |