From 0d1e067665e556b1f2b13a0d9febdafc6b50feaa Mon Sep 17 00:00:00 2001
From: fguigues <fguigues@localhost>
Date: Wed, 04 Jun 2008 16:26:47 +0000
Subject: [PATCH] 

---
 opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java |   38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java b/opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java
index 44dd066..71c6127 100644
--- a/opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java
+++ b/opends/src/snmp/src/org/opends/server/snmp/SNMPUserAcl.java
@@ -55,7 +55,6 @@
      * Admin User for cloning mechanism.
      */
     private static final String ADMIN_USER = "snmpAdmin";
-
     /**
      * Current Security Configuration for the SNMP Connection Handler.
      */
@@ -75,7 +74,7 @@
     /**
      * Configured Security level.
      */
-    private SecurityLevel securityLevel;
+    private int securityLevel;
 
     /**
      * {@inheritDoc}
@@ -91,7 +90,10 @@
         // Get the traps destinations
         this.trapDestinations = this.currentConfig.getTrapsDestination();
         // Get the min security level to accept
-        this.securityLevel = this.currentConfig.getSecurityLevel();
+        SecurityLevel level = this.currentConfig.getSecurityLevel();
+        this.securityLevel =
+                SNMPConnectionHandlerDefinitions.SECURITY_LEVELS.get(
+                level.toString());
     }
 
     /**
@@ -126,21 +128,23 @@
 
     /**
      * {@inheritDoc}
+     * @param user
+     * @param contextName
+     * @param securityLevel
      */
     public boolean checkReadPermission(String user, String contextName,
             int securityLevel) {
 
         // Special check for the defaultUser
-        if ((user.equals(ADMIN_USER))
-            && (contextName.equals("null"))
-            && ((this.securityLevel.ordinal() + 1) >= securityLevel)) {
+        if ((user.equals(ADMIN_USER)) && (contextName.equals("null"))
+                && ((checkSecurityLevel(securityLevel)))) {
             return true;
         }
 
         // Else
-        if ((checkReadPermission(user))  &&
+        if ((checkReadPermission(user)) &&
                 ((checkContextName(contextName))) &&
-                ((this.securityLevel.ordinal() + 1) >= securityLevel)) {
+                (checkSecurityLevel(securityLevel))) {
             return true;
         }
         return false;
@@ -148,6 +152,7 @@
 
     /**
      * {@inheritDoc}
+     * @return true if the context is correct, false otherwise.
      */
     public boolean checkContextName(String contextName) {
         return this.contextName.equals(contextName);
@@ -155,6 +160,8 @@
 
     /**
      * {@inheritDoc}
+     * @param user to check the write permission.
+     * @return true if the user has the write permission, false otherwise.
      */
     public boolean checkWritePermission(String user) {
         if (user.equals(ADMIN_USER)) {
@@ -170,7 +177,20 @@
             int securityLevel) {
         if ((checkWritePermission(user)) &&
                 (contextName.equals("null")) &&
-                ((this.securityLevel.ordinal() + 1) >= securityLevel)) {
+                (checkSecurityLevel(securityLevel))) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Check the incoming security level of the request.
+     * @param securityLevel
+     * @return true if the securityLevel is appropriated, else return false
+     */
+    private boolean checkSecurityLevel(int securityLevel) {
+
+        if (securityLevel >= this.securityLevel) {
             return true;
         }
         return false;

--
Gitblit v1.10.0