aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/.svn/text-base/Linker.java.svn-base
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/.svn/text-base/Linker.java.svn-base')
-rw-r--r--id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/.svn/text-base/Linker.java.svn-base173
1 files changed, 173 insertions, 0 deletions
diff --git a/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/.svn/text-base/Linker.java.svn-base b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/.svn/text-base/Linker.java.svn-base
new file mode 100644
index 000000000..43d3adaa9
--- /dev/null
+++ b/id/server/stork2-commons/src/main/java/eu/stork/peps/auth/commons/.svn/text-base/Linker.java.svn-base
@@ -0,0 +1,173 @@
+package eu.stork.peps.auth.commons;
+
+import java.util.Iterator;
+
+/**
+ * This class is a bean used to store the information of Attribute Providers, the Attribute
+ * List to be requested, the Assertions returned by the Attribute Providers and the values
+ * that each Attribute has. This information along with the current status of the Linker (the
+ * attribute providers that were queried and the remaining providers) is used by the PEPS
+ * actions in order to complete the Attribute gathering.
+ *
+ * @author Stelios Lelis (stelios.lelis@aegean.gr), Elias Pastos (ilias@aegean.gr)
+ *
+ * @version $Revision: 1.20 $, $Date: 2013-10-28 $
+ */
+public final class Linker {
+ /**
+ * Attributes Providers map.
+ */
+ private IAttributeProvidersMap attributeProvidersMap;
+
+ /**
+ * The current index of local (domestic) Attribute Providers.
+ */
+ private int localIndex;
+
+ /**
+ * The current index of remote (foreign) Attribute Providers - countries.
+ */
+ private int remoteIndex;
+
+ /**
+ * Constructs an empty Linker object.
+ */
+ public Linker() {
+ localIndex = 0;
+ remoteIndex = 0;
+ }
+
+ /**
+ * Based on the internal state of the Linker it returns the next local Attribute Source
+ *
+ * @return The next Attribute Source or null if not found
+ *
+ * @see AttributeSource
+ */
+ public AttributeSource getNextLocalProvider() {
+ Iterator<AttributeSource> iterator;
+ AttributeSource source, found;
+ int curIndex = 0;
+
+ found = null;
+
+ if ( attributeProvidersMap!=null && !attributeProvidersMap.isEmpty() ) {
+ iterator = attributeProvidersMap.keyIterator();
+ while (iterator.hasNext()) {
+ source = iterator.next();
+
+ if ( source.getSourceType()==AttributeSource.SOURCE_LOCAL_APROVIDER ) {
+ if ( curIndex>=localIndex ) {
+ found = source;
+
+ break;
+ }
+
+ curIndex++;
+ }
+ }
+ }
+
+ return found;
+ }
+
+ /**
+ * Based on the internal state of the Linker it returns the next remote Attribute Source
+ *
+ * @return The next Attribute Source or null if not found
+ *
+ * @see AttributeSource
+ */
+ public AttributeSource getNextRemoteProvider() {
+ Iterator<AttributeSource> iterator;
+ AttributeSource source, found;
+ int curIndex = 0;
+
+ found = null;
+
+ if ( attributeProvidersMap !=null && !attributeProvidersMap.isEmpty() ) {
+ iterator = attributeProvidersMap.keyIterator();
+ while (iterator.hasNext()) {
+ source = iterator.next();
+
+ if ( source.getSourceType()==AttributeSource.SOURCE_REMOTE_COUNTRY ) {
+ if ( curIndex>=remoteIndex ) {
+ found = source;
+
+ break;
+ }
+
+ curIndex++;
+ }
+ }
+ }
+
+ return found;
+ }
+
+ /**
+ * It updates the Linker with the values returned by the Attribute Source. It also advances
+ * to the next index in order to mark this attribute source as completed.
+ *
+ * @param source The Attribute Source that was queried for attribute values.
+ * @param attrResponse The attrResponse returned by the Attribute Source that contains the attribute values.
+ *
+ * @see AttributeSource, STORKAttrQueryResponse
+ */
+ public void setProviderReponse(AttributeSource source, STORKAttrQueryResponse attrResponse) {
+ if ( source.getSourceType()==AttributeSource.SOURCE_REMOTE_COUNTRY )
+ remoteIndex++;
+ else
+ localIndex++;
+
+ //TODO How to store Assertions (format: byte, base64 string, entire object?)
+
+ this.attributeProvidersMap.put(source, attrResponse.getPersonalAttributeList());
+ }
+
+ /**
+ * Reset the internal state of the local Attribute Source in order to start over.
+ */
+ public void resetLocalIndex() {
+ localIndex = 0;
+ }
+
+ /**
+ * Reset the internal state of the remote Attribute Source in order to start over.
+ */
+ public void resetRemoteIndex() {
+ remoteIndex = 0;
+ }
+
+ /**
+ * Setter for attributeProvidersMap.
+ *
+ * @param attributeProvidersMap The attributeProvidersMap to set.
+ */
+ public void setAttributeProvidersMap(IAttributeProvidersMap attributeProvidersMap) {
+ this.attributeProvidersMap = attributeProvidersMap;
+ }
+
+ /**
+ * Getter for attributeProvidersMap.
+ *
+ * @return attributeProvidersMap
+ */
+ public IAttributeProvidersMap getAttributeProvidersMap() {
+ return attributeProvidersMap;
+ }
+
+ /**
+ * Returns the Personal Attribute list of the provided Attribute Source.
+ *
+ * @return The IPersonalAttributeList assosiated with this source or null if empty
+ *
+ * @see IPersonalAttributeList
+ */
+ public IPersonalAttributeList getProviderAttributes(AttributeSource source) {
+ if ( attributeProvidersMap.containsKey(source) )
+ return attributeProvidersMap.get(source);
+ else
+ return null;
+ }
+}