[java-identity-provider COMMIT] in /trunk/idp-authn-api/src: main/java/net/shibboleth/idp/authn/BaseAuthenticationRes...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Sep 25 11:06:32 EDT 2013
Author: scantor
Date: Wed Sep 25 11:06:31 2013
New Revision: 4797
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4797&view=rev
Log:
Optimize out the last activity field from the serialization.
Modified:
trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/BaseAuthenticationResultSerializer.java
trunk/idp-authn-api/src/test/java/net/shibboleth/idp/authn/BaseAuthenticationResultSerializerTest.java
trunk/idp-authn-api/src/test/resources/data/net/shibboleth/idp/authn/complexAuthenticationResult.json
trunk/idp-authn-api/src/test/resources/data/net/shibboleth/idp/authn/noActivity.json
trunk/idp-authn-api/src/test/resources/data/net/shibboleth/idp/authn/noFlowId.json
trunk/idp-authn-api/src/test/resources/data/net/shibboleth/idp/authn/noInstant.json
trunk/idp-authn-api/src/test/resources/data/net/shibboleth/idp/authn/simpleAuthenticationResult.json
trunk/idp-authn-api/src/test/resources/data/net/shibboleth/idp/authn/symbolicAuthenticationResult.json
Modified: trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/BaseAuthenticationResultSerializer.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/BaseAuthenticationResultSerializer.java?rev=4797&r1=4796&r2=4797&view=diff
==============================================================================
--- trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/BaseAuthenticationResultSerializer.java (original)
+++ trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/BaseAuthenticationResultSerializer.java Wed Sep 25 11:06:31 2013
@@ -42,6 +42,8 @@
import javax.json.stream.JsonGenerator;
import javax.security.auth.Subject;
+import net.shibboleth.utilities.java.support.annotation.Duration;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonNegative;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -62,6 +64,9 @@
/**
* Handles serialization of results that carry only custom {@link Principal} objects of a simple
* nature that can be reconstructed via a String-argument constructor.
+ *
+ * <p>The expiration of the resulting record <strong>MUST</strong> be set to the last activity
+ * instant of the object plus an optional offset value supplied to the constructor.</p>
*/
public class BaseAuthenticationResultSerializer implements StorageSerializer<AuthenticationResult> {
@@ -71,9 +76,6 @@
/** Field name of authentication instant. */
private static final String AUTHN_INSTANT_FIELD = "ts";
- /** Field name of last activity time. */
- private static final String LAST_ACTIVITY_FIELD = "act";
-
/** Field name of principal array. */
private static final String PRINCIPAL_ARRAY_FIELD = "princ";
@@ -88,17 +90,25 @@
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(BaseAuthenticationResultSerializer.class);
-
+
+ /** Milliseconds to substract from record expiration to establish last activity value. */
+ @Duration @NonNegative private final long expirationOffset;
+
/** Shrinkage of long constants into symbolic numbers. */
@Nonnull private BiMap<String,Integer> symbolics;
/** A cache of Principal types that support string-based construction. */
@Nonnull private final Set<Class<? extends Principal>> compatiblePrincipalTypes;
- /** Constructor. */
- public BaseAuthenticationResultSerializer() {
+ /**
+ * Constructor.
+ *
+ * @param offset milliseconds to substract from record expiration to establish last activity value
+ */
+ public BaseAuthenticationResultSerializer(@Duration @NonNegative final long offset) {
symbolics = ImmutableBiMap.of();
compatiblePrincipalTypes = Collections.synchronizedSet(new HashSet<Class<? extends Principal>>());
+ expirationOffset = Constraint.isGreaterThanOrEqual(0, offset, "Offset must be greater than or equal to zero");
}
/**
@@ -119,7 +129,6 @@
gen.writeStartObject()
.write(FLOW_ID_FIELD, instance.getAuthenticationFlowId())
.write(AUTHN_INSTANT_FIELD, instance.getAuthenticationInstant())
- .write(LAST_ACTIVITY_FIELD, instance.getLastActivityInstant())
.writeStartArray(PRINCIPAL_ARRAY_FIELD);
for (Principal p : instance.getSubject().getPrincipals()) {
@@ -141,7 +150,7 @@
@Nonnull public AuthenticationResult deserialize(final int version, @Nonnull @NotEmpty final String context,
@Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable final Long expiration)
throws IOException {
-
+
try {
JsonReader reader = Json.createReader(new StringReader(value));
JsonStructure st = reader.read();
@@ -152,12 +161,11 @@
[... 129 lines stripped ...]
More information about the commits
mailing list