[java-opensaml COMMIT] /trunk/opensaml-temp/src/main/java/org/opensaml/ws/security/provider/HTTPRule.java

noreply at shibboleth.net noreply at shibboleth.net
Fri May 31 16:48:23 EDT 2013


Author: putmanb
Date: Fri May 31 16:48:23 2013
New Revision: 3353

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3353&view=rev
Log:
Port HTTPRule to MessageHandler API.

Modified:
    trunk/opensaml-temp/src/main/java/org/opensaml/ws/security/provider/HTTPRule.java

Modified: trunk/opensaml-temp/src/main/java/org/opensaml/ws/security/provider/HTTPRule.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-temp/src/main/java/org/opensaml/ws/security/provider/HTTPRule.java?rev=3353&r1=3352&r2=3353&view=diff
==============================================================================
--- trunk/opensaml-temp/src/main/java/org/opensaml/ws/security/provider/HTTPRule.java (original)
+++ trunk/opensaml-temp/src/main/java/org/opensaml/ws/security/provider/HTTPRule.java Fri May 31 16:48:23 2013
@@ -17,19 +17,23 @@
 
 package org.opensaml.ws.security.provider;
 
+import javax.servlet.http.HttpServletRequest;
+
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.component.ComponentSupport;
+import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
-import org.opensaml.ws.message.MessageContext;
-import org.opensaml.ws.security.SecurityPolicyException;
-import org.opensaml.ws.security.SecurityPolicyRule;
-import org.opensaml.ws.transport.http.HTTPTransport;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.handler.AbstractMessageHandler;
+import org.opensaml.messaging.handler.MessageHandlerException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A security rule that checks basic HTTP connection properties.
+ * A security message handler that checks basic HTTP request properties.
  */
-public class HTTPRule implements SecurityPolicyRule {
+public class HTTPRule extends AbstractMessageHandler {
 
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(HTTPRule.class);
@@ -42,89 +46,152 @@
 
     /** Whether the request must be secure. */
     private boolean requireSecured;
+    
+    /** The HTTP servlet request being evaluated. */
+    private HttpServletRequest httpServletRequest;
 
     /**
-     * Constructor.
+     * Get the required content type.
      * 
-     * @param type expected content type
-     * @param method expected request method
-     * @param secured whether the request must be secured
+     * @return the required content type
      */
-    public HTTPRule(String type, String method, boolean secured) {
-        requiredContentType = StringSupport.trimOrNull(type);
-        requiredRequestMethod = StringSupport.trimOrNull(method);
+    public String getRequiredContentType() {
+        return requiredContentType;
+    }
+
+    /**
+     * Set the required content type.
+     * 
+     * @param contentType the content type
+     */
+    public void setRequiredContentType(String contentType) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        requiredContentType = contentType;
+        requiredRequestMethod = StringSupport.trimOrNull(contentType);
+    }
+
+    /**
+     * Get the required request method.
+     * 
+     * @return the required request method
+     */
+    public String getRequiredRequestMethod() {
+        return requiredRequestMethod;
+    }
+
+    /**
+     * Set the required request method.
+     * 
+     * @param requestMethod the required request method
+     */
+    public void setRequiredRequestMethod(String requestMethod) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        requiredRequestMethod = StringSupport.trimOrNull(requestMethod);
+    }
+
+    /**
+     * Get whether request is required to be secure.
+     * 
+     * @return true if required to be secure, false otherwise
+     */
+    public boolean isRequireSecured() {
+        return requireSecured;
+    }
+
+    /**
+     * Set whether request is required to be secure. 
+     * 
+     * @param secured true if required to be secure, false otherwise
+     */
+    public void setRequireSecured(boolean secured) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
         requireSecured = secured;
     }
 
-    /** {@inheritDoc} */
-    public void evaluate(MessageContext messageContext) throws SecurityPolicyException {
-
-        if (!(messageContext.getInboundMessageTransport() instanceof HTTPTransport)) {
-            log.debug("Message context was did not contain an HTTP transport, unable to evaluate security rule");
-            return;
-        }
-
-        doEvaluate(messageContext);
+    /**
+     * Get the HTTP servlet request instance being evaluated.
+     * 
+     * @return returns the request instance
+     */
+    public HttpServletRequest getHttpServletRequest() {
+        return httpServletRequest;
     }
 
     /**
-     * Evaluates if the message context transport, guaranteed to be of type {@link HTTPTransport}, meets all
-     * requirements.

[... 108 lines stripped ...]


More information about the commits mailing list