From b76b6e6212784d622ca79bd258fa3e529b353346 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 28 Sep 2018 14:19:50 +0200 Subject: add first code for eID4U --- .../AbstractStringAttributeMarshaller.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 id/server/modules/eID4UExtensions/src/main/java/at/gv/egiz/eid4u/impl/attributes/AbstractStringAttributeMarshaller.java (limited to 'id/server/modules/eID4UExtensions/src/main/java/at/gv/egiz/eid4u/impl/attributes/AbstractStringAttributeMarshaller.java') diff --git a/id/server/modules/eID4UExtensions/src/main/java/at/gv/egiz/eid4u/impl/attributes/AbstractStringAttributeMarshaller.java b/id/server/modules/eID4UExtensions/src/main/java/at/gv/egiz/eid4u/impl/attributes/AbstractStringAttributeMarshaller.java new file mode 100644 index 000000000..c5a019aa2 --- /dev/null +++ b/id/server/modules/eID4UExtensions/src/main/java/at/gv/egiz/eid4u/impl/attributes/AbstractStringAttributeMarshaller.java @@ -0,0 +1,49 @@ +package at.gv.egiz.eid4u.impl.attributes; + +import eu.eidas.auth.commons.attribute.AttributeValue; +import eu.eidas.auth.commons.attribute.AttributeValueMarshaller; +import eu.eidas.auth.commons.attribute.AttributeValueMarshallingException; +import eu.eidas.auth.commons.attribute.impl.StringAttributeValue; + +public abstract class AbstractStringAttributeMarshaller implements AttributeValueMarshaller { + + @Override + public String marshal(AttributeValue value) throws AttributeValueMarshallingException { + String result = value.getValue(); + + //to validation + if (!hasValidForm(result)) + throw new AttributeValueMarshallingException( + "Illegal " + getName() + " value \"" + result + "\""); + + return result; + } + + @Override + public AttributeValue unmarshal(String value, boolean isNonLatinScriptAlternateVersion) + throws AttributeValueMarshallingException { + + //to validation + if (!hasValidForm(value)) + throw new AttributeValueMarshallingException( + "Illegal " + getName() + " value \"" + value + "\""); + + return new StringAttributeValue(value); + } + + /** + * Validate a String attribute if required + * + * @param value String based attribute value + * @return true if valid, otherwise false + */ + abstract protected boolean hasValidForm(String value); + + /** + * Get the name of the attribute mashaller + * + * @return + */ + abstract protected String getName(); + +} -- cgit v1.2.3