From 9cb68043945f53246928443cea723b58ee2b1c24 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Tue, 21 Jan 2014 14:38:35 +0100 Subject: updated samlengine --- .../peps/auth/commons/PersonalAttributeList.java | 143 +++++++++++++++++---- 1 file changed, 117 insertions(+), 26 deletions(-) (limited to 'id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/PersonalAttributeList.java') diff --git a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/PersonalAttributeList.java b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/PersonalAttributeList.java index d33ccfe18..642b249d4 100644 --- a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/PersonalAttributeList.java +++ b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/PersonalAttributeList.java @@ -18,7 +18,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import java.util.StringTokenizer; import org.apache.commons.lang.StringUtils; @@ -37,7 +37,7 @@ import org.apache.log4j.Logger; */ @SuppressWarnings("PMD") public final class PersonalAttributeList extends - HashMap implements IPersonalAttributeList{ + ConcurrentHashMap implements IPersonalAttributeList{ /** * Logger object. @@ -118,8 +118,9 @@ public final class PersonalAttributeList extends if (StringUtils.isNotEmpty(key) && val != null) { // Validate if attribute name already exists! String attrAlias = key; - if (this.containsKey(key)) { - if (!val.isEmptyValue() && StringUtils.isNumeric(val.getValue().get(0))) { + if (this.containsKey(attrAlias)) { + //TODO isAgeOver should not be hardcoded, a better way of handling multipe isAgeOver requests should be implemented. + if (!val.isEmptyValue() && StringUtils.isNumeric(val.getValue().get(0)) && "isAgeOver".equals( val.getName() ) ) { final String attrValue = val.getValue().get(0); attrAlias = key + attrValue; this.attrAliasNumber.put(key, Integer.valueOf(attrValue)); @@ -169,27 +170,9 @@ public final class PersonalAttributeList extends .valueOf(tuples[AttributeConstants.ATTR_TYPE_INDEX.intValue()])); // check if it is a complex value - if (tuples[AttributeConstants.ATTR_NAME_INDEX.intValue()] - .equals(PEPSParameters.COMPLEX_ADDRESS_VALUE.toString())) - { + if (isComplexValue(vals)) { persAttr.setComplexValue(createComplexValue(vals)); } - else if (tuples[AttributeConstants.ATTR_NAME_INDEX.intValue()] - .equals(PEPSParameters.COMPLEX_NEWATTRIBUTE_VALUE.toString())) - { - persAttr.setComplexValue(createComplexValue(vals)); - } - - else if (tuples[AttributeConstants.ATTR_NAME_INDEX.intValue()] - .equals(PEPSParameters.COMPLEX_HASDEGREE_VALUE.toString())) - { - persAttr.setComplexValue(createComplexValue(vals)); - } - else if (tuples[AttributeConstants.ATTR_NAME_INDEX.intValue()] - .equals(PEPSParameters.COMPLEX_MANDATECONTENT_VALUE.toString())) - { - persAttr.setComplexValue(createComplexValue(vals)); - } else { persAttr.setValue(createValues(vals)); @@ -215,7 +198,11 @@ public final class PersonalAttributeList extends * @return The copy of this IPersonalAttributeList. */ public Object clone() { - return (PersonalAttributeList) super.clone(); + try { + return (PersonalAttributeList) super.clone(); + } catch (CloneNotSupportedException e) { + return null; + } } /** @@ -234,7 +221,8 @@ public final class PersonalAttributeList extends while (itAttrs.hasNext()) { final Entry attrEntry = itAttrs.next(); final PersonalAttribute attr = attrEntry.getValue(); - strBuilder.append(attr.toString()); + //strBuilder.append(attr.toString()); + strBuilder.insert(0, attr.toString()); } return strBuilder.toString(); @@ -260,6 +248,22 @@ public final class PersonalAttributeList extends return complexValue; } + /** + * Checks if value is complex or not + * @param values The values to check + * @return True if succesful + */ + private boolean isComplexValue(final String[] values) { + boolean isComplex = false; + if (values.length > 0) { + final String[] tVal = values[0].split("="); + if (StringUtils.isNotEmpty(values[0]) && tVal.length == 2) { + isComplex = true; + } + } + return isComplex; + } + /** * Validates and creates the attribute values. * @@ -302,4 +306,91 @@ public final class PersonalAttributeList extends } return newFormatTuples; } -} + + /** + * Returns a IPersonalAttributeList of the complex attributes in this map. + * + * @return an IPersonalAttributeList of the complex attributes contained in this map. + */ + public IPersonalAttributeList getComplexAttributes() { + LOG.info("get complex attributes"); + IPersonalAttributeList attrList = new PersonalAttributeList(); + for(PersonalAttribute attr: this) { + if(!attr.getComplexValue().isEmpty()) { + attrList.put(attr.getName(), attr); + LOG.info("adding complex attribute:"+attr.getName()); + } + } + return attrList; + } + + /** + * Returns a IPersonalAttributeList of the mandatory attributes in this map. + * + * @return an IPersonalAttributeList of the mandatory attributes contained in this map. + */ + public IPersonalAttributeList getSimpleValueAttributes() { + LOG.info("get simple attributes"); + IPersonalAttributeList attrList = new PersonalAttributeList(); + for(PersonalAttribute attr: this) { + if(attr.getComplexValue().isEmpty()) { + attrList.put(attr.getName(), attr); + LOG.info("adding simple attribute:"+attr.getName()); + } + } + return attrList; + } + + + + /** + * Returns a IPersonalAttributeList of the mandatory attributes in this map. + * + * @return an IPersonalAttributeList of the mandatory attributes contained in this map. + */ + public IPersonalAttributeList getMandatoryAttributes() { + return getAttributesByParam(true); + } + + + /** + * Returns a IPersonalAttributeList of the attributes in this map by parameter value. + * + * @param compareValue The boolean to get mandatory (true) or optional (false) attributes. + * + * @return an IPersonalAttributeList of the mandatory attributes contained in this map if compareValue is true or optional otherwise. + */ + private IPersonalAttributeList getAttributesByParam(final boolean compareValue) { + LOG.info("get attributes by param :"+compareValue); + IPersonalAttributeList attrList = new PersonalAttributeList(); + for(PersonalAttribute attr: this) { + if(attr.isRequired() == compareValue) { + attrList.put(attr.getName(), attr); + LOG.info("adding attribute:"+attr.getName()); + } + } + return attrList; + } + + + /** + * Returns a IPersonalAttributeList of the optional attributes in this map. + * + * @return an IPersonalAttributeList of the optional attributes contained in this map. + */ + public IPersonalAttributeList getOptionalAttributes() { + return getAttributesByParam(false); + } + + /** + * {@inheritDoc} + */ + public boolean hasMissingValues() { + for(PersonalAttribute attr: this) { + if(attr.isEmptyValue() && attr.isEmptyComplexValue()) { + return true; + } + } + return false; + } +} \ No newline at end of file -- cgit v1.2.3