[java-identity-provider COMMIT] in /trunk: idp-profile-api/src/main/java/net/shibboleth/idp/profile/ProfileRequestCon...
noreply at shibboleth.net
noreply at shibboleth.net
Mon Jul 2 15:23:00 EDT 2012
Author: lajoie
Date: Mon Jul 2 15:23:00 2012
New Revision: 4197
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4197&view=rev
Log:
Track profile ID in request context
Add action to set profile ID
Added:
trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SetProfileId.java (with props)
trunk/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/SetProfileIdTest.java (with props)
Modified:
trunk/idp-profile-api/src/main/java/net/shibboleth/idp/profile/ProfileRequestContext.java
trunk/idp-profile-api/src/test/java/net/shibboleth/idp/profile/ProfileRequestContextTest.java
Modified: trunk/idp-profile-api/src/main/java/net/shibboleth/idp/profile/ProfileRequestContext.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-profile-api/src/main/java/net/shibboleth/idp/profile/ProfileRequestContext.java?rev=4197&r1=4196&r2=4197&view=diff
==============================================================================
--- trunk/idp-profile-api/src/main/java/net/shibboleth/idp/profile/ProfileRequestContext.java (original)
+++ trunk/idp-profile-api/src/main/java/net/shibboleth/idp/profile/ProfileRequestContext.java Mon Jul 2 15:23:00 2012
@@ -17,10 +17,14 @@
package net.shibboleth.idp.profile;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
import org.opensaml.messaging.context.InOutOperationContext;
@@ -37,6 +41,11 @@
/** ID under which this context is stored, for example, within maps or sessions. */
public static final String BINDING_KEY = ProfileRequestContext.class.getName();
+ public static final String ANONYMOUS_PROFILE_ID = "anonymous";
+
+ /** Unique identifier for the profile/operation/function of the current request. */
+ private String profileId;
+
/**
* Indicates whether the current profile request is passive. Passive requests are not capable of showing a UI to a
* user.
@@ -52,6 +61,30 @@
/** Constructor. */
public ProfileRequestContext() {
super();
+ profileId = ANONYMOUS_PROFILE_ID;
+ }
+
+ /**
+ * Gets the ID of the profile used by the current request.
+ *
+ * @return ID of the profile used by the current request
+ */
+ @Nonnull @NotEmpty public String getProfileId() {
+ return profileId;
+ }
+
+ /**
+ * Sets the ID of the profile used by the current request.
+ *
+ * @param id ID of the profile used by the current request
+ */
+ public void setProfileId(final String id) {
+ final String trimmedId = StringSupport.trimOrNull(id);
+ if (trimmedId == null) {
+ profileId = ANONYMOUS_PROFILE_ID;
+ } else {
+ profileId = id;
+ }
}
/**
Modified: trunk/idp-profile-api/src/test/java/net/shibboleth/idp/profile/ProfileRequestContextTest.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-profile-api/src/test/java/net/shibboleth/idp/profile/ProfileRequestContextTest.java?rev=4197&r1=4196&r2=4197&view=diff
==============================================================================
--- trunk/idp-profile-api/src/test/java/net/shibboleth/idp/profile/ProfileRequestContextTest.java (original)
+++ trunk/idp-profile-api/src/test/java/net/shibboleth/idp/profile/ProfileRequestContextTest.java Mon Jul 2 15:23:00 2012
@@ -25,8 +25,7 @@
/** Unit test for {@link ProfileRequestContext}. */
public class ProfileRequestContextTest {
- @Test
- public void testHttpRequest() {
+ @Test public void testHttpRequest() {
ProfileRequestContext context = new ProfileRequestContext();
Assert.assertNull(context.getHttpRequest());
@@ -35,8 +34,7 @@
Assert.assertSame(context.getHttpRequest(), request);
}
- @Test
- public void testHttpResponse() {
+ @Test public void testHttpResponse() {
ProfileRequestContext context = new ProfileRequestContext();
Assert.assertNull(context.getHttpResponse());
@@ -45,12 +43,25 @@
Assert.assertSame(context.getHttpResponse(), response);
}
- @Test
- public void testIsPassive() {
+ @Test public void testIsPassive() {
ProfileRequestContext context = new ProfileRequestContext();
Assert.assertFalse(context.isPassiveProfile());
context.setPassiveProfile(true);
Assert.assertTrue(context.isPassiveProfile());
}
+
+ @Test public void testProfileId() {
+ ProfileRequestContext context = new ProfileRequestContext();
+ Assert.assertEquals(context.getProfileId(), ProfileRequestContext.ANONYMOUS_PROFILE_ID);
+
+ context.setProfileId(null);
+ Assert.assertEquals(context.getProfileId(), ProfileRequestContext.ANONYMOUS_PROFILE_ID);
+
+ context.setProfileId("foo");
[... 7 lines stripped ...]
More information about the commits
mailing list