[java-identity-provider COMMIT] in /trunk: idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSessio...

noreply at shibboleth.net noreply at shibboleth.net
Thu Sep 26 22:51:00 EDT 2013


Author: scantor
Date: Thu Sep 26 22:51:00 2013
New Revision: 4804

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4804&view=rev
Log:
Implement address binding, begin work on write-back / update

Modified:
    trunk/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java
    trunk/idp-session-impl/pom.xml
    trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
    trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedSessionManager.java
    trunk/idp-session-impl/src/test/java/net/shibboleth/idp/session/impl/StorageBackedIdPSessionSerializerTest.java

Modified: trunk/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java?rev=4804&r1=4803&r2=4804&view=diff
==============================================================================
--- trunk/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java (original)
+++ trunk/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java Thu Sep 26 22:51:00 2013
@@ -328,6 +328,10 @@
     /** {@inheritDoc} */
     public boolean checkAddress(@Nonnull @NotEmpty final String address) throws SessionException {
         AddressFamily family = getAddressFamily(address);
+        if (family == AddressFamily.UNKNOWN) {
+            log.warn("Address {} is of unknown type", address);
+            return false;
+        }
         String bound = getAddress(family);
         if (bound != null) {
             if (!bound.equals(address)) {
@@ -404,7 +408,7 @@
      * @param address   the string to check
      * @return the address family
      */
-    @Nonnull private static AddressFamily getAddressFamily(@Nonnull @NotEmpty final String address) {
+    @Nonnull protected static AddressFamily getAddressFamily(@Nonnull @NotEmpty final String address) {
         if (address.contains(":")) {
             return AddressFamily.IPV6;
         } else if (address.contains(".")) {

Modified: trunk/idp-session-impl/pom.xml
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-session-impl/pom.xml?rev=4804&r1=4803&r2=4804&view=diff
==============================================================================
Binary files - no diff available.

Modified: trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java?rev=4804&r1=4803&r2=4804&view=diff
==============================================================================
--- trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java (original)
+++ trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java Thu Sep 26 22:51:00 2013
@@ -18,6 +18,7 @@
 package net.shibboleth.idp.session.impl;
 
 import java.io.IOException;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -28,6 +29,7 @@
 import org.joda.time.DateTime;
 import org.opensaml.storage.StorageRecord;
 import org.opensaml.storage.StorageSerializer;
+import org.opensaml.storage.VersionMismatchException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -100,19 +102,65 @@
 
     /** {@inheritDoc} */
     public void bindToAddress(@Nonnull @NotEmpty final String address) throws SessionException {
-        // TODO Auto-generated method stub
+        // Update ourselves and then attempt to write back.
         super.bindToAddress(address);
+        try {
+            int attempts = 10;
+            boolean success = writeToStorage();
+            while (!success && attempts-- > 0) {
+                // The record may have changed underneath, so we need to re-check the address.
+                String nowBound = getAddress(getAddressFamily(address));
+                if (nowBound != null) {
+                    // The same address type is now set, so recheck. No need to update storage regardless.
+                    if (nowBound.equals(address)) {
+                        return;
+                    } else {
+                        log.warn("Client address is {} but session {} already bound to {}", address, getId(), nowBound);
+                        throw new SessionException("A different address of the same type was bound to the session");
+                    }
+                } else {
+                    // We're still clear, so update ourselves again and try to write back.
+                    super.bindToAddress(address);
+                    success = writeToStorage();
+                }
+            }
+            log.error("Exhausted retry attempts updating record for session {}", getId());
+        } catch (IOException e) {
+            log.error("Exception updating address binding of master record for session " + getId(), e);

[... 297 lines stripped ...]


More information about the commits mailing list