aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java')
-rw-r--r--id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java151
1 files changed, 147 insertions, 4 deletions
diff --git a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java
index 43d3adaa9..6e7c891da 100644
--- a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java
+++ b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/Linker.java
@@ -1,6 +1,12 @@
package eu.stork.peps.auth.commons;
+import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import org.apache.log4j.Logger;
/**
* This class is a bean used to store the information of Attribute Providers, the Attribute
@@ -11,15 +17,30 @@ import java.util.Iterator;
*
* @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos (ilias@aegean.gr)
*
- * @version $Revision: 1.20 $, $Date: 2013-10-28 $
+ * @version $Revision: 1.50 $, $Date: 2013-11-28 $
*/
-public final class Linker {
+public final class Linker implements Serializable {
+ /**
+ * Unique identifier.
+ */
+ private static final long serialVersionUID = -3268006381745987237L;
+
+ /**
+ * Logger object.
+ */
+ private static final Logger LOG = Logger.getLogger(Linker.class.getName());
+
/**
* Attributes Providers map.
*/
private IAttributeProvidersMap attributeProvidersMap;
/**
+ * Assertion map.
+ */
+ private LinkedHashMap<AttributeSource, STORKAttrQueryResponse> assertions;
+
+ /**
* The current index of local (domestic) Attribute Providers.
*/
private int localIndex;
@@ -35,6 +56,8 @@ public final class Linker {
public Linker() {
localIndex = 0;
remoteIndex = 0;
+
+ assertions = new LinkedHashMap<AttributeSource, STORKAttrQueryResponse>();
}
/**
@@ -120,9 +143,11 @@ public final class Linker {
else
localIndex++;
- //TODO How to store Assertions (format: byte, base64 string, entire object?)
+ //Assertion storage
+ this.assertions.put(source, attrResponse);
this.attributeProvidersMap.put(source, attrResponse.getPersonalAttributeList());
+ //this.attributeProvidersMap.put(source, attrResponse.getTotalPersonalAttributeList());
}
/**
@@ -160,6 +185,8 @@ public final class Linker {
/**
* Returns the Personal Attribute list of the provided Attribute Source.
*
+ * @param source The attributeSource in reference
+ *
* @return The IPersonalAttributeList assosiated with this source or null if empty
*
* @see IPersonalAttributeList
@@ -170,4 +197,120 @@ public final class Linker {
else
return null;
}
-}
+
+ /**
+ * Returns the merged Personal Attribute list from all the Attribute Sources.
+ *
+ * @return The IPersonalAttributeList merged Personal Attribute list or null if empty
+ *
+ * @see IPersonalAttributeList
+ */
+ public IPersonalAttributeList getAllAttributes() {
+ Iterator<AttributeSource> iterator;
+ AttributeSource source;
+ IPersonalAttributeList list, merged;
+
+ merged = null;
+
+ if ( attributeProvidersMap !=null && !attributeProvidersMap.isEmpty() ) {
+ iterator = attributeProvidersMap.keyIterator();
+
+ merged = new PersonalAttributeList();
+ while (iterator.hasNext()) {
+ source = iterator.next();
+ list = this.getProviderAttributes(source);
+
+ for (final PersonalAttribute pa : list) {
+ merged.add(pa);
+ }
+ }
+ }
+
+ return merged;
+ }
+
+ /**
+ * Returns a List with all the assertions gathered by the AAS-PEPS module
+ * returned both by local APs or remote A-PEPS.
+ *
+ * @return The assertions returned from the APs and A-PEPS
+ */
+ public List<STORKAttrQueryResponse> getAttrQueryResponseList() {
+ List<STORKAttrQueryResponse> originalAssertions;
+
+ originalAssertions = new ArrayList<STORKAttrQueryResponse>();
+
+ //Gather all assertions
+ for (STORKAttrQueryResponse element : this.assertions.values()) {
+ originalAssertions.add(element);
+ }
+
+ return originalAssertions;
+ }
+
+ /**
+ * Checks the internal state of the Linker and if all Attribute Sources where visited
+ * returns true, otherwise it returns false. So if you go directly from AtPLinkerAction
+ * to MoreAttributesAction the call will have, since the method setProviderReponse
+ * was not executed from every Attribute Source.
+ *
+ * @return true if everything is OK, false otherwise
+ */
+ public boolean isComplete() {
+ boolean outcome = false;
+
+ LOG.debug("Check if linkder is complete: R[" + remoteIndex + "], L[" + localIndex + "], S[" + attributeProvidersMap.size() + "]");
+ if ( attributeProvidersMap !=null && !attributeProvidersMap.isEmpty() ) {
+ if ( (remoteIndex + localIndex)==attributeProvidersMap.size() )
+ outcome = true;
+ }
+ else {
+ outcome = true;
+ }
+
+ return outcome;
+ }
+
+ /**
+ * Merge the two Linker objects.
+ *
+ * @param previous The other Linker object to merge with this one.
+ */
+ public void mergeWith(Linker previous) {
+ //BEFORE
+ if ( LOG.isDebugEnabled() ) {
+ LOG.debug("The attributeProvidersMap from the current object.");
+ ((AttributeProvidersMap)this.attributeProvidersMap).trace();
+ LOG.debug("The attributeProvidersMap from the provided object.");
+ ((AttributeProvidersMap)previous.getAttributeProvidersMap()).trace();
+ }
+
+ IAttributeProvidersMap map = previous.getAttributeProvidersMap();
+ Iterator<AttributeSource> items = map.keyIterator();
+ while( items.hasNext() ) {
+ AttributeSource item = items.next();
+ IPersonalAttributeList pal = map.get(item);
+
+ if ( this.attributeProvidersMap.containsKey(item) ) {
+ IPersonalAttributeList new_pal = this.attributeProvidersMap.get(item);
+
+ for(PersonalAttribute pa : pal)
+ new_pal.add(pa);
+ }
+ else {
+ if ( item.getSourceType()==AttributeSource.SOURCE_REMOTE_COUNTRY )
+ remoteIndex++;
+ else
+ localIndex++;
+
+ this.attributeProvidersMap.put(item, pal);
+ }
+ }
+
+ //AFTER
+ if ( LOG.isDebugEnabled() ) {
+ LOG.debug("The attributeProvidersMap after the merge.");
+ ((AttributeProvidersMap)this.attributeProvidersMap).trace();
+ }
+ }
+} \ No newline at end of file