[java-identity-provider COMMIT] in /trunk/idp-authn-impl/src: main/java/net/shibboleth/idp/authn/impl/ExtractUserAgen...
noreply at shibboleth.net
noreply at shibboleth.net
Fri Jul 26 01:17:25 EDT 2013
Author: scantor
Date: Fri Jul 26 01:17:24 2013
New Revision: 4623
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4623&view=rev
Log:
IDP-158 - user agent address extract action / unit test
Added:
trunk/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/ExtractUserAgentAddressTest.java (with props)
Modified:
trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExtractUserAgentAddress.java
Modified: trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExtractUserAgentAddress.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExtractUserAgentAddress.java?rev=4623&r1=4622&r2=4623&view=diff
==============================================================================
--- trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExtractUserAgentAddress.java (original)
+++ trunk/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/ExtractUserAgentAddress.java Fri Jul 26 01:17:24 2013
@@ -18,51 +18,55 @@
package net.shibboleth.idp.authn.impl;
import javax.annotation.Nonnull;
+import javax.servlet.http.HttpServletRequest;
-import net.shibboleth.ext.spring.webflow.Event;
-import net.shibboleth.ext.spring.webflow.Events;
import net.shibboleth.idp.authn.AbstractAuthenticationAction;
import net.shibboleth.idp.authn.AuthenticationException;
import net.shibboleth.idp.authn.AuthnEventIds;
import net.shibboleth.idp.authn.context.AuthenticationContext;
import net.shibboleth.idp.authn.context.UserAgentContext;
-import net.shibboleth.idp.profile.ActionSupport;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.webflow.execution.RequestContext;
import com.google.common.net.InetAddresses;
/**
- * A stage that extracts the user-agent's IP address from the incoming requests, creates an
- * {@link UserAgentAddressContext}, and attaches it to the {@link AuthenticationContext}.
+ * An action that extracts the user-agent's IP address from the incoming request, creates a
+ * {@link UserAgentContext}, and attaches it to the {@link AuthenticationContext}.
+ *
+ * @event {@link org.opensaml.profile.action.EventIds#PROCEED_EVENT_ID}
+ * @event {@link AuthnEventIds#NO_CREDENTIALS}
+ * @pre <pre>ProfileRequestContext.getSubcontext(AuthenticationContext.class, false) != null</pre>
+ * @post If ProfileRequestContext.getHttpRequest() != null, the content of getRemoteAddr() will be
+ * attached via a {@link UserAgentContext}, provided it is a valid IP address.
*/
- at Events({@Event(id = EventIds.PROCEED_EVENT_ID),
- @Event(id = AuthnEventIds.NO_CREDENTIALS, description = "request does not contain user agent's IP address")})
public class ExtractUserAgentAddress extends AbstractAuthenticationAction {
/** Class logger. */
private final Logger log = LoggerFactory.getLogger(ExtractUserAgentAddress.class);
-
+
/** {@inheritDoc} */
- protected org.springframework.webflow.execution.Event doExecute(@Nonnull final RequestContext springRequestContext,
- @Nonnull final ProfileRequestContext profileRequestContext,
+ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext,
@Nonnull final AuthenticationContext authenticationContext) throws AuthenticationException {
- final String addressString = Constraint.isNotNull(profileRequestContext.getHttpRequest(),
- "HttpServletRequest cannot be null").getRemoteAddr();
- if (!InetAddresses.isInetAddress(addressString)) {
- log.debug("Action {}: User agent's IP address, {}, is not a valid IP address", getId(), addressString);
- return ActionSupport.buildEvent(this, AuthnEventIds.NO_CREDENTIALS);
+ final HttpServletRequest request = profileRequestContext.getHttpRequest();
+ if (request == null) {
+ log.debug("{} profile request context does not contain an HttpServletRequest", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.NO_CREDENTIALS);
+ return;
+ }
+
+ final String addressString = request.getRemoteAddr();
+ if (addressString == null || !InetAddresses.isInetAddress(addressString)) {
+ log.debug("{} User agent's address, {}, is not a valid IP address", getLogPrefix(), addressString);
+ ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.NO_CREDENTIALS);
+ return;
}
authenticationContext.getSubcontext(UserAgentContext.class, true).setAddress(
InetAddresses.forString(addressString));
-
- return ActionSupport.buildProceedEvent(this);
}
}
More information about the commits
mailing list