[java-identity-provider COMMIT] in /trunk/idp-authn-api/src: main/java/net/shibboleth/idp/authn/AuthenticationFlowDes...
noreply at shibboleth.net
noreply at shibboleth.net
Mon Jul 22 15:56:34 EDT 2013
Author: scantor
Date: Mon Jul 22 15:56:34 2013
New Revision: 4608
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4608&view=rev
Log:
Improve some APIs, add an isActive checker.
Modified:
trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthenticationFlowDescriptor.java
trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthenticationResult.java
trunk/idp-authn-api/src/test/java/net/shibboleth/idp/authn/AuthenticationFlowDescriptorTest.java
Modified: trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthenticationFlowDescriptor.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthenticationFlowDescriptor.java?rev=4608&r1=4607&r2=4608&view=diff
==============================================================================
--- trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthenticationFlowDescriptor.java (original)
+++ trunk/idp-authn-api/src/main/java/net/shibboleth/idp/authn/AuthenticationFlowDescriptor.java Mon Jul 22 15:56:34 2013
@@ -18,7 +18,7 @@
package net.shibboleth.idp.authn;
import java.security.Principal;
-import java.util.List;
+import java.util.Collection;
import java.util.Set;
import javax.annotation.Nonnull;
@@ -28,6 +28,8 @@
import org.opensaml.storage.StorageSerializer;
import com.google.common.base.Objects;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -159,12 +161,34 @@
* @param inactivityTimeout the flow timeout, must be 0 or greater
*/
public void setInactivityTimeout(long inactivityTimeout) {
- timeout =
- Constraint.isGreaterThanOrEqual(0, inactivityTimeout,
- "Inactivity timeout must be greater than, or equal to, 0");
- }
- /**
- * Get a set of supported non-user-specific principals that the flow may produce when it operates.
+ timeout = Constraint.isGreaterThanOrEqual(0, inactivityTimeout,
+ "Inactivity timeout must be greater than or equal to 0");
+ }
+
+ /**
+ * Check if a result generated by this flow is still active.
+ *
+ * @param result {@link AuthenticationResult} to check
+ *
+ * @return true iff the result remains valid
+ */
+ public boolean isResultActive(@Nonnull final AuthenticationResult result) {
+ Constraint.isNotNull(result, "AuthenticationResult cannot be null");
+ Constraint.isTrue(result.getAuthenticationFlowId().equals(getId()),
+ "AuthenticationResult was not produced by this flow");
+
+ long now = System.currentTimeMillis();
+ if (getLifetime() > 0 && result.getAuthenticationInstant() + getLifetime() <= now) {
+ return false;
+ } else if (getInactivityTimeout() > 0 && result.getLastActivityInstant() + getInactivityTimeout() <= now) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get an immutable set of supported non-user-specific principals that the flow may produce when it operates.
*
* @param <T> type of Principal to inquire on
* @param c type of Principal to inquire on
@@ -174,18 +198,31 @@
@Nonnull @NonnullElements @Unmodifiable public <T extends Principal> Set<T> getSupportedPrincipals(Class<T> c) {
return supportedPrincipals.getPrincipals(c);
}
+
+ /**
+ * Get a collection of supported non-user-specific principals that the flow may produce when it operates.
+ *
+ * <p>The {@link Collection#remove()} method is not supported.</p>
+ *
+ * @return a live collection of supported principals
+ */
+ @Nonnull @NonnullElements public Collection<Principal> getSupportedPrincipals() {
+ return Collections2.filter(supportedPrincipals.getPrincipals(), Predicates.notNull());
+ }
/**
* Set supported non-user-specific principals that the flow may produce when it operates.
*
* @param <T> a type of principal to add, if not generic
- * @param principals supported principals
- */
- public <T extends Principal> void setSupportedPrincipals(@Nonnull @NonnullElements final List<T> principals) {
+ * @param principals supported principals to add
+ */
+ public <T extends Principal> void setSupportedPrincipals(@Nonnull @NonnullElements final Collection<T> principals) {
+ Constraint.isNotNull(principals, "Principal list cannot be null.");
+
supportedPrincipals.getPrincipals().clear();
- supportedPrincipals.getPrincipals().addAll(principals);
- }
-
+ supportedPrincipals.getPrincipals().addAll(Collections2.filter(principals, Predicates.notNull()));
+ }
+
/**
* Get the custom serializer for events produced by this flow.
*
[... 77 lines stripped ...]
More information about the commits
mailing list