[jboss-cvs] JBossAS SVN: r111490 - in branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config: attribute and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 31 14:20:09 EDT 2011


Author: thauser at redhat.com
Date: 2011-05-31 14:20:07 -0400 (Tue, 31 May 2011)
New Revision: 111490

Added:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/AuthenticationProtocol.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/PrivacyProtocol.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/User.java
Modified:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java
Log:
finally fix this user issue


Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java	2011-05-31 17:38:58 UTC (rev 111489)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java	2011-05-31 18:20:07 UTC (rev 111490)
@@ -46,6 +46,7 @@
 	private AttributeMappings attrInfo;
 	private ArrayList<MappedAttribute> maList; // a list of all mapped attributes algamated from all attributes.xml
 	private ArrayList<MIBObject> miboList; //internal list of MIBObjects
+	private MBeanServer server; // reference to the MBeanServer, which we will use to query attribute types and other such things
 	
 	public MIBGenerator(){
 		mibResName = null;
@@ -54,7 +55,7 @@
 		this.miboList = null;
 	}
 	
-	public MIBGenerator(String mibResName, AttributesMapping attrInfo, ArrayList<MappedAttribute> maList){
+	public MIBGenerator(String mibResName, AttributesMapping attrInfo, ArrayList<MappedAttribute> maList, MBeanServer server){
 		this.mibResName = mibResName;
 		this.maList = maList;
 		this.attrInfo = attrInfo;
@@ -86,12 +87,21 @@
 		this.attrInfo = attrInfo;
 	}
 	
+	public MBeanServer getMBeanServer(){
+		return this.server;
+	}
+	
+	public void setMBeanServer(MBeanServer server){
+		this.server = server;
+	}
 	//we're done gathering attributes. write the MIB.
 	public void writeMib() throws Exception{
 		try{
 		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(mibResName)));
 		writeHeader(out);
-		writeDefinitions(miboList,out);
+		//writeDefinitions(out);
+		writeObjects(miboList, out);
+		out.println();
 		out.println("END");
 		out.close();
 		}
@@ -134,13 +144,21 @@
 	}
 	
 	/** This method is used to write the definitions of our SYNTAX inside the JBoss MIB
-	 * 
+	 *  For use when we figure out what OIDs we want our metrics to be. 
 	 * @param attrList list of MBeans that we're interested in
 	 * @param out The PrintWriter that writes to the file we need it to
 	 * @author Tom Hauser
 	 */	
-	private void writeDefinitions(AttributeMappings attrList, PrintWriter out){
-		
+	private void writeDefinitions(PrintWriter out){
+		out.println("-- Tree Roots");
+		out.println("org\tOBJECT IDENTIFIER ::= { iso 3 }");
+		out.println("dod\tOBJECT IDENTIFIER ::= { org 6 }");
+		out.println("internet\tOBJECT IDENTIFIER ::= { dod 1 }");
+		out.println("private\tOBJECT IDENTIFIER ::= { internet 4 }");
+		out.println("enterprise\tOBJECT IDENTIFIER ::= { private 1 }");
+		out.println("redhat\tOBJECT IDENTIFIER ::= { enterprise 2312 }");
+		out.println("jboss\tOBJECT IDENTIFIER ::= { redhat 100 }");
+		out.println();
 	}
 	
 	private void writeObjects(ArrayList<MIBObject>miboList, PrintWriter out){
@@ -171,14 +189,20 @@
 		private String status;
 		private String description;
 		private String objectId; 
+		private String oidPrefix; 
 				
 		//need to modify the information saved in mapped attribute maybe.
 		//or just make a new class to hold this info in, instead of an internal one.
 		//we need to get the information out of the MappedAttribute and format it 
 		//correctly for use in an MIB.
+		MIBObject(MappedAttribute ma, String oidPrefix){
+			MIBObject(ma);
+			this.oidPrefix = oidPrefix;
+		}
+		
 		MIBObject(MappedAttribute ma){
 			this.name = ma.getName();
-			this.syntax = "STRING"; // definitely need a better way to find this out.
+			this.syntax = "OCTET STRING (SIZE (0..255))"; // definitely need a better way to find this out.
 			// maybe need to parse notifications.xml to find out trap objects
 		
 			if (ma.isReadWrite()) // since we only have "rw" and "ro", this needs expansion.
@@ -186,10 +210,10 @@
 			else
 				maxAccess = "read-only";
 			
-			this.status = "mandatory"; // again, need expansions to attributes.xml to account for this
-			this.description = ma.getDesc(); // see above.
+			this.status = "mandatory"; // need expansions to attributes.xml to account for this
+			this.description = ""; // see above.
 			this.objectId = ma.getOid(); // this will contain the full numerical OID.
-			
+			this.oidPrefix = "";
 		}
 	
 		public String toString(){
@@ -203,10 +227,10 @@
 			buf.append("\n");
 			buf.append("\tDESCRIPTION ");
 			buf.append("\n\t\t");
-			buf.append("\"DESCRIPTION\"");
+			buf.append(\"this.description\");
 			buf.append("\n");
 			buf.append("::= {").append(" ");
-			buf.append(objectId + " }");
+			buf.append(oidPrefix + objectId + " }");
 			return buf.toString();
 		}
 	

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/AuthenticationProtocol.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/AuthenticationProtocol.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/AuthenticationProtocol.java	2011-05-31 18:20:07 UTC (rev 111490)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jmx.adaptor.snmp.config.user;
+
+/**
+ * @author jean.deruelle at gmail.com
+ *
+ */
+public enum AuthenticationProtocol {
+	MD5, SHA;
+}

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/PrivacyProtocol.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/PrivacyProtocol.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/PrivacyProtocol.java	2011-05-31 18:20:07 UTC (rev 111490)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jmx.adaptor.snmp.config.user;
+
+/**
+ * @author jean.deruelle at gmail.com
+ *
+ */
+public enum PrivacyProtocol {
+	DES, TRIPLE_DES, AES128, AES192, AES256;	
+}

Added: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/User.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/User.java	                        (rev 0)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/user/User.java	2011-05-31 18:20:07 UTC (rev 111490)
@@ -0,0 +1,198 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jmx.adaptor.snmp.config.user;
+
+import org.snmp4j.security.AuthMD5;
+import org.snmp4j.security.AuthSHA;
+import org.snmp4j.security.Priv3DES;
+import org.snmp4j.security.PrivAES128;
+import org.snmp4j.security.PrivAES192;
+import org.snmp4j.security.PrivAES256;
+import org.snmp4j.security.PrivDES;
+import org.snmp4j.security.SecurityLevel;
+import org.snmp4j.smi.OID;
+
+/**
+ * Simple POJO class to model XML data
+ * 
+ * @author  <a href="mailto:jean.deruelle at gmail.com">Jean Deruelle</a>
+ * 
+ */
+public class User
+{
+   // Private Data --------------------------------------------------
+   
+   private String  securityName;
+   private String  authenticationProtocol;
+   private String  authenticationPassphrase;
+   private String  privacyProtocol;
+   private String  privacyPassphrase;
+   private int securityLevel;
+   
+   // Constructors -------------------------------------------------
+    
+   /**
+    * Default CTOR
+    */
+   public User()
+   {
+      // empty
+   }
+   
+   // Accessors/Modifiers -------------------------------------------
+   /**
+    * @param securityName the securityName to set
+    */
+   public void setSecurityName(String securityName) {
+   	this.securityName = securityName;
+   }
+
+   /**
+    * @return the securityName
+    */
+   public String getSecurityName() {
+   	return securityName;
+   }
+
+   /**
+    * @param authenticationProtocol the authenticationProtocol to set
+    */
+   public void setAuthenticationProtocol(String authenticationProtocol) {
+   	this.authenticationProtocol = authenticationProtocol;
+   }
+
+   /**
+    * @return the authenticationProtocol
+    */
+   public String getAuthenticationProtocol() {
+   	return authenticationProtocol;
+   }
+   
+   /**
+    * @return the authenticationProtocol
+    */
+   public OID getAuthenticationProtocolID() {
+		AuthenticationProtocol authenticationProtocolID = AuthenticationProtocol.valueOf(authenticationProtocol.trim()); 
+		switch (authenticationProtocolID) {
+			case MD5:
+				return AuthMD5.ID;
+			case SHA:
+				return AuthSHA.ID;
+			default:
+				return null;
+		}
+   }
+
+   /**
+    * @param authenticationPassphrase the authenticationPassphrase to set
+    */
+   public void setAuthenticationPassphrase(String authenticationPassphrase) {
+   	this.authenticationPassphrase = authenticationPassphrase;
+   }
+
+   /**
+    * @return the authenticationPassphrase
+    */
+   public String getAuthenticationPassphrase() {
+   	return authenticationPassphrase;
+   }
+
+   /**
+    * @param privacyProtocol the privacyProtocol to set
+    */
+   public void setPrivacyProtocol(String privacyProtocol) {
+   	this.privacyProtocol = privacyProtocol;
+   }
+
+   /**
+    * @return the privacyProtocol
+    */
+   public String getPrivacyProtocol() {
+   	return privacyProtocol;
+   }
+   
+   /**
+    * @return the authenticationProtocol
+    */
+   public OID getPrivacyProtocolID() {
+	   PrivacyProtocol privacyProtocolID = PrivacyProtocol.valueOf(privacyProtocol.trim()); 
+		switch (privacyProtocolID) {
+			case DES:
+				return PrivDES.ID;
+			case TRIPLE_DES:
+				return Priv3DES.ID;
+			case AES128:
+				return PrivAES128.ID;
+			case AES192:
+				return PrivAES192.ID;
+			case AES256:
+				return PrivAES256.ID;
+			default:
+				return null;
+		}
+   }
+
+   /**
+    * @param privacyPassphrase the privacyPassphrase to set
+    */
+   public void setPrivacyPassphrase(String privacyPassphrase) {
+   	this.privacyPassphrase = privacyPassphrase;
+   }
+
+   /**
+    * @return the privacyPassphrase
+    */
+   public String getPrivacyPassphrase() {
+   	return privacyPassphrase;
+   }
+   /**
+    * Returns the given security level depending on te authentication protocol and privacy protocol chosen
+    * @return
+    */
+   public int getSecurityLevel() {
+	   if(authenticationProtocol == null) {
+		   return SecurityLevel.NOAUTH_NOPRIV;
+	   } else if(privacyProtocol == null) {
+		   return SecurityLevel.AUTH_NOPRIV;
+	   } else {
+		   return SecurityLevel.AUTH_PRIV;
+	   }
+	   
+   }
+   
+   // Object overrides ----------------------------------------------
+   
+   public String toString()
+   {
+      StringBuffer sbuf = new StringBuffer(256);
+      
+      sbuf.append('[')
+      .append("securityName=").append(securityName)
+      .append(", authenticationProtocol=").append(authenticationProtocol)
+      .append(", authenticationPassphrase=").append(authenticationPassphrase)
+      .append(", privacyProtocol=").append(privacyProtocol)
+      .append(", privacyPassphrase=").append(privacyPassphrase)
+      .append(']');
+      
+      return sbuf.toString();      
+   }
+}



More information about the jboss-cvs-commits mailing list