[wsas-java-dev] svn commit r9738 - in branches/wsas/java/2.1/commons/throttle: . modules/core modules/core/src/main/java/org/wso2/throttle modules/core/src/main/java/org/wso2/throttle/impl/domainbase modules/mar modules/mar/src/main/java/org/wso2/throttle/module/handler

svn at wso2.org svn at wso2.org
Tue Nov 13 10:26:44 PST 2007


Author: indika
Date: Tue Nov 13 10:26:29 2007
New Revision: 9738

Modified:
   branches/wsas/java/2.1/commons/throttle/modules/core/pom.xml
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java
   branches/wsas/java/2.1/commons/throttle/modules/mar/pom.xml
   branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
   branches/wsas/java/2.1/commons/throttle/pom.xml
Log:
fixes for domain based accesscontrol


Modified: branches/wsas/java/2.1/commons/throttle/modules/core/pom.xml
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/pom.xml	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/pom.xml	Tue Nov 13 10:26:29 2007
@@ -4,8 +4,8 @@
 
 
     <parent>
-        <groupId>org.wso2.wso2throttle</groupId>
-        <artifactId>wso2throttle</artifactId>
+        <groupId>org.wso2.throttle</groupId>
+        <artifactId>wso2-throttle</artifactId>
         <version>2.1-SNAPSHOT</version>
     </parent>
 

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java	Tue Nov 13 10:26:29 2007
@@ -76,17 +76,17 @@
         }
         if (remoteIP == null) {
             if (debugOn) {
-                log.debug("Caller " + type + " not found!");
+                log.debug("Caller host or ip  couldn't find !! - Access will be denied ");
             }
             return false;
         }
         CallerConfiguration configuration =
-            throttleContext.getThrottleConfiguration().getCallerConfiguration(remoteIP);
+            throttleConfigurationBean.getCallerConfiguration(remoteIP);
         if (configuration == null) {
             if (debugOn) {
-                log.debug("Caller configuration couldn't find for " + type + " " + remoteIP);
+                log.debug("Caller configuration couldn't find for " + type + " and for caller " + remoteIP);
             }
-            return false;
+            return true;
         }
         if (configuration.getAccessState() == ThrottleConstants.ACCESS_DENIED) {
             log.info(ACCESS_DENIED);
@@ -108,7 +108,7 @@
                 if (caller != null) {
                     long currentTime = System.currentTimeMillis();
 
-                    if (!caller.canAccess(throttleContext, currentTime)) {
+                    if (!caller.canAccess(throttleContext,configuration, currentTime)) {
                         //if current caller cannot access , then perform cleaning
                         log.info(ACCESS_DENIED);
                         throttleContext.processCleanList(currentTime);
@@ -123,7 +123,7 @@
                     if (debugOn) {
                         log.debug("Caller " + type + " not found! " + remoteIP);
                     }
-                    return false;
+                    return true;
                 }
             }
         }

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java	Tue Nov 13 10:26:29 2007
@@ -200,27 +200,27 @@
      * @return boolean          -The boolean value which say access will allolw or not
      * @throws ThrottleException
      */
-    public boolean canAccess(ThrottleContext throttleContext, long currentTime) throws ThrottleException {
+    public boolean canAccess(ThrottleContext throttleContext, CallerConfiguration callerConfiguration,long currentTime) throws ThrottleException {
         boolean canAcess = false;
         ThrottleConfiguration throttleConfiguration = throttleContext.getThrottleConfiguration();
-        CallerConfiguration ipBasedconfiguration = throttleConfiguration.getCallerConfiguration(getID());
-        if (ipBasedconfiguration == null) {
+//        CallerConfiguration callerConfiguration = throttleConfiguration.getCallerConfiguration(getID());
+        if (callerConfiguration == null) {
             return false;
         }
-        if (ipBasedconfiguration.getMaximumRequestPerUnitTime() < 0 || ipBasedconfiguration.getUnitTimeInMiliSecond() <= 0 || ipBasedconfiguration.getProhibitTimePeriod() < 0) {
+        if (callerConfiguration.getMaximumRequestPerUnitTime() < 0 || callerConfiguration.getUnitTimeInMiliSecond() <= 0 || callerConfiguration.getProhibitTimePeriod() < 0) {
             throw new ThrottleException("Invalid Throttle Configuration");
         }
 
-        if (!(ipBasedconfiguration.getMaximumRequestPerUnitTime() == 0)) {
+        if (!(callerConfiguration.getMaximumRequestPerUnitTime() == 0)) {
             // if caller access first time in his new session
             if (this.firstAccessTime == 0) {
-                initAccess(ipBasedconfiguration, throttleContext, currentTime);
+                initAccess(callerConfiguration, throttleContext, currentTime);
             }
             // if unit time period (session time) is not over
             if (nextTimeWindow > currentTime) {
-                canAcess = canAccessIfUnitTimeNotOver(ipBasedconfiguration, throttleContext, currentTime);
+                canAcess = canAccessIfUnitTimeNotOver(callerConfiguration, throttleContext, currentTime);
             } else {
-                canAcess = canAccessIfUnitTimeOver(ipBasedconfiguration, throttleContext, currentTime);
+                canAcess = canAccessIfUnitTimeOver(callerConfiguration, throttleContext, currentTime);
             }
 
         }

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java	Tue Nov 13 10:26:29 2007
@@ -121,10 +121,19 @@
         * @return Object-String representation of  corrected epr-key for get configuration
         */
        public Object getConfigurationKeyOfCaller(Object callerID) {
-           String domain = (String) callerID;
-           //if there is a unique Domain
-           if (configurationsMap.containsKey(domain)) {
-               return domain;
+
+           if (callerID != null) {
+               String domain = (String) callerID;
+               //if there is a unique Domain
+               if (configurationsMap.containsKey(domain)) {
+                   return domain;
+               } else {
+                   int index = domain.indexOf(".");
+                   if (index > 0) {
+                       String rootDomain = domain.substring(index + 1, domain.length());
+                       return getConfigurationKeyOfCaller(rootDomain);
+                   }
+               }
            }
            return keyOfOther;
        }

Modified: branches/wsas/java/2.1/commons/throttle/modules/mar/pom.xml
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/mar/pom.xml	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/mar/pom.xml	Tue Nov 13 10:26:29 2007
@@ -4,13 +4,13 @@
 
 
     <parent>
-        <groupId>org.wso2.wso2throttle</groupId>
-        <artifactId>wso2throttle</artifactId>
+        <groupId>org.wso2.throttle</groupId>
+        <artifactId>wso2-throttle</artifactId>
         <version>2.1-SNAPSHOT</version>
     </parent>
 
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>wso2throttle-mar</artifactId>
+    <artifactId>wso2throttle</artifactId>
     <packaging>jar</packaging>
     <version>2.1-SNAPSHOT</version>
     <name>WSO2 Throttling module - Mar</name>
@@ -68,7 +68,7 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.wso2.wso2throttle</groupId>
+            <groupId>org.wso2.throttle</groupId>
             <artifactId>wso2throttle-core</artifactId>
             <version>2.1-SNAPSHOT</version>
         </dependency>

Modified: branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java	Tue Nov 13 10:26:29 2007
@@ -20,6 +20,7 @@
 
 
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisOperation;
@@ -29,6 +30,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.wso2.throttle.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 
@@ -135,40 +137,62 @@
 
             if (messageContext.getFLOW() == MessageContext.IN_FLOW) {
                 // do the normal throttling
-                String domainName = "domain_name";   //TODO
+                String domainName = null;
+
+                HttpServletRequest request =
+                    (HttpServletRequest) messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
+                if (request != null) {
+                    domainName = request.getRemoteHost();
+                }
+                ThrottleContext throttleContext = null;
                 if (domainName != null) {
-                    ThrottleContext throttleContext =
+                    throttleContext =
                         throttle.getThrottleContext(ThrottleConstants.DOMAIN_BASED_THROTTLE_KEY);
-                    if (throttleContext == null) {
-                        throw new AxisFault("Could not find the Throttle Context for DomainBased Thottling");
-                    }
-                    if (!accessController.canAccess(throttleContext, domainName, ThrottleConstants.DOMAIN_BASE)) {
-                        throw new AxisFault("You cannot access this service since you have" +
-                            " exceeded the allocated quota.");
+                    if (throttleContext != null) {
+                        if (!accessController.canAccess(throttleContext, domainName, ThrottleConstants.DOMAIN_BASE)) {
+                            throw new AxisFault("A caller with domain " + domainName + " cannot access this service since " +
+                                "the allocated quota  have been exceeded.");
+                        }
+                    } else {
+                        if (log.isDebugEnabled()) {
+                            log.debug("Could not find the Throttle Context for Domain-Based Thottling");
+                        }
                     }
                 } else {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Could not find the Domain of the caller - IP-based throttling may occur");
+                    }
+                }
+                if (throttleContext == null) {
                     String remoteIP = (String) messageContext.getProperty(MessageContext.REMOTE_ADDR);
                     if (remoteIP != null) {
-                        ThrottleContext throttleContext =
+                        throttleContext =
                             throttle.getThrottleContext(ThrottleConstants.IP_BASED_THROTTLE_KEY);
-                        if (throttleContext == null) {
-                            throw new AxisFault("Could not find the Throttle Context for IPBased Thottling");
-                        }
-                        if (!accessController.canAccess(throttleContext, remoteIP, ThrottleConstants.IP_BASE)) {
-                            throw new AxisFault("You cannot access this service since you have" +
-                                " exceeded the allocated quota.");
+                        if (throttleContext != null) {
+                            ConcurrentAccessController concurrentAccessController = throttle.getConcurrentAccessController();
+                            if (concurrentAccessController != null) {
+                                concurrentAccessController.incrementAndGet();
+                            }
+                            if (!accessController.canAccess(throttleContext, remoteIP, ThrottleConstants.IP_BASE)) {
+                                throw new AxisFault("A caller with IP " + remoteIP + " cannot access this service since" +
+                                    " the allocated quota  have been exceeded.");
+                            }
+                        } else {
+                            if (log.isDebugEnabled()) {
+                                log.debug("Could not find the Throttle Context for IP-Based Thottling");
+                            }
                         }
                     } else {
-                        throw new AxisFault("Could not find the IP address or Domain of the caller - Currently only support caller-IP(or Domain) base access control");
+                        if (log.isDebugEnabled()) {
+                            log.debug("Could not find the IP address of the caller - throttling will not occur");
+                        }
 
                     }
                 }
             }
 
         } else {
-            if (log.isDebugEnabled()) {
-                log.debug("Access deny from concurrent throttlling");
-            }
+            throw new AxisFault("Access deny from concurrent throttlling");
         }
     }
 
@@ -198,7 +222,9 @@
         return canAccess;
     }
 
-    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+    public InvocationResponse invoke
+        (MessageContext
+            msgContext) throws AxisFault {
         //Load throttle
         try {
             Throttle throttle = loadThrottle(msgContext, getThrottleType());

Modified: branches/wsas/java/2.1/commons/throttle/pom.xml
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/pom.xml	(original)
+++ branches/wsas/java/2.1/commons/throttle/pom.xml	Tue Nov 13 10:26:29 2007
@@ -3,8 +3,8 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
     <modelVersion>4.0.0</modelVersion>
-    <groupId>org.wso2.wso2throttle</groupId>
-    <artifactId>wso2throttle</artifactId>
+    <groupId>org.wso2.throttle</groupId>
+    <artifactId>wso2-throttle</artifactId>
     <packaging>pom</packaging>
     <version>2.1-SNAPSHOT</version>
     <name>WSO2 throttle module</name>
@@ -84,6 +84,13 @@
             <artifactId>ant-nodeps</artifactId>
             <version>${ant.version}</version>
         </dependency>
+
+       <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>${servlet-api.version}</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
     <build>
@@ -175,7 +182,7 @@
     </modules>
 
     <properties>
-         <axis2.version>1.3</axis2.version>
+        <axis2.version>1.3</axis2.version>
         <wso2throttle.version>${pom.version}</wso2throttle.version>
         <axiom.version>1.2.5</axiom.version>
         <neethi.version>2.0.2</neethi.version>
@@ -183,5 +190,6 @@
         <junit.version>3.8.2</junit.version>
         <log4j.version>1.2.13</log4j.version>
         <ant.version>1.6.5</ant.version>
+        <servlet-api.version>2.3</servlet-api.version>
     </properties>
 </project>




More information about the Wsas-java-dev mailing list