geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r798794 - in /geronimo/server/trunk/framework: configs/client-system/ configs/geronimo-boilerplate/src/main/assembly/ configs/j2ee-system/ configs/jsr88-deploymentfactory/ configs/online-deployer/ configs/shutdown/ modules/geronimo-kernel/ ...
Date Wed, 29 Jul 2009 06:54:51 GMT
Author: djencks
Date: Wed Jul 29 06:54:50 2009
New Revision: 798794

URL: http://svn.apache.org/viewvc?rev=798794&view=rev
Log:
GERONIMO-3003 Encrypt poassoreds and morked attributes in serialized gbeans and config.xml.
 Modified from patch by Jack Cai, many thanks.

Modified:
    geronimo/server/trunk/framework/configs/client-system/pom.xml
    geronimo/server/trunk/framework/configs/geronimo-boilerplate/src/main/assembly/boilerplate.xml
    geronimo/server/trunk/framework/configs/j2ee-system/pom.xml
    geronimo/server/trunk/framework/configs/jsr88-deploymentfactory/pom.xml
    geronimo/server/trunk/framework/configs/online-deployer/pom.xml
    geronimo/server/trunk/framework/configs/shutdown/pom.xml
    geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/DynamicGAttributeInfo.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GAttributeInfo.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/ParamAttribute.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/Persistent.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/xstream/GBeanDataConverter.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilderTest.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/MockGBean.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/ConfigurationUtilTest.java

Modified: geronimo/server/trunk/framework/configs/client-system/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/client-system/pom.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/client-system/pom.xml (original)
+++ geronimo/server/trunk/framework/configs/client-system/pom.xml Wed Jul 29 06:54:50 2009
@@ -138,6 +138,11 @@
                         </element>
                         <element>
                             <groupId>org.apache.geronimo.framework</groupId>
+                            <artifactId>geronimo-crypto</artifactId>
+                            <version>${version}</version>
+                        </element>
+                        <element>
+                            <groupId>org.apache.geronimo.framework</groupId>
                             <artifactId>geronimo-kernel</artifactId>
                             <version>${version}</version>
                         </element>

Modified: geronimo/server/trunk/framework/configs/geronimo-boilerplate/src/main/assembly/boilerplate.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/geronimo-boilerplate/src/main/assembly/boilerplate.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/geronimo-boilerplate/src/main/assembly/boilerplate.xml
(original)
+++ geronimo/server/trunk/framework/configs/geronimo-boilerplate/src/main/assembly/boilerplate.xml
Wed Jul 29 06:54:50 2009
@@ -65,6 +65,7 @@
                 <include>org.apache.xbean:xbean-reflect</include>
                 <include>com.thoughtworks.xstream:xstream</include>
                 <include>org.apache.geronimo.framework:geronimo-cli</include>
+                <include>org.apache.geronimo.framework:geronimo-crypto</include>
                 <include>org.apache.geronimo.framework:geronimo-kernel</include>
                 <include>org.apache.geronimo.framework:geronimo-system</include>
                 <include>org.apache.geronimo.framework:geronimo-deploy-jsr88-bootstrapper</include>

Modified: geronimo/server/trunk/framework/configs/j2ee-system/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/j2ee-system/pom.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/j2ee-system/pom.xml (original)
+++ geronimo/server/trunk/framework/configs/j2ee-system/pom.xml Wed Jul 29 06:54:50 2009
@@ -190,6 +190,11 @@
                         </element>
                         <element>
                             <groupId>org.apache.geronimo.framework</groupId>
+                            <artifactId>geronimo-crypto</artifactId>
+                            <version>${version}</version>
+                        </element>
+                        <element>
+                            <groupId>org.apache.geronimo.framework</groupId>
                             <artifactId>geronimo-kernel</artifactId>
                             <version>${version}</version>
                         </element>

Modified: geronimo/server/trunk/framework/configs/jsr88-deploymentfactory/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/jsr88-deploymentfactory/pom.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/jsr88-deploymentfactory/pom.xml (original)
+++ geronimo/server/trunk/framework/configs/jsr88-deploymentfactory/pom.xml Wed Jul 29 06:54:50
2009
@@ -126,6 +126,11 @@
                     <classpath>
                         <element>
                             <groupId>org.apache.geronimo.framework</groupId>
+                            <artifactId>geronimo-crypto</artifactId>
+                            <version>${version}</version>
+                        </element>
+                        <element>
+                            <groupId>org.apache.geronimo.framework</groupId>
                             <artifactId>geronimo-kernel</artifactId>
                             <version>${version}</version>
                         </element>

Modified: geronimo/server/trunk/framework/configs/online-deployer/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/online-deployer/pom.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/online-deployer/pom.xml (original)
+++ geronimo/server/trunk/framework/configs/online-deployer/pom.xml Wed Jul 29 06:54:50 2009
@@ -146,6 +146,11 @@
                         </element>
                         <element>
                             <groupId>org.apache.geronimo.framework</groupId>
+                            <artifactId>geronimo-crypto</artifactId>
+                            <version>${version}</version>
+                        </element>
+                        <element>
+                            <groupId>org.apache.geronimo.framework</groupId>
                             <artifactId>geronimo-kernel</artifactId>
                             <version>${version}</version>
                         </element>

Modified: geronimo/server/trunk/framework/configs/shutdown/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/shutdown/pom.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/shutdown/pom.xml (original)
+++ geronimo/server/trunk/framework/configs/shutdown/pom.xml Wed Jul 29 06:54:50 2009
@@ -98,6 +98,11 @@
                     <classpath>
                         <element>
                             <groupId>org.apache.geronimo.framework</groupId>
+                            <artifactId>geronimo-crypto</artifactId>
+                            <version>${version}</version>
+                        </element>
+                        <element>
+                            <groupId>org.apache.geronimo.framework</groupId>
                             <artifactId>geronimo-kernel</artifactId>
                             <version>${version}</version>
                         </element>

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/pom.xml Wed Jul 29 06:54:50 2009
@@ -67,6 +67,12 @@
             <version>${version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.framework</groupId>
+            <artifactId>geronimo-crypto</artifactId>
+            <version>${version}</version>
+        </dependency>
     </dependencies>
 
     <build>

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/DynamicGAttributeInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/DynamicGAttributeInfo.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/DynamicGAttributeInfo.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/DynamicGAttributeInfo.java
Wed Jul 29 06:54:50 2009
@@ -17,12 +17,18 @@
 
 package org.apache.geronimo.gbean;
 
+import org.apache.geronimo.gbean.annotation.EncryptionSetting;
+
 /**
  * Describes an attibute of a GBean.
  * 
  * @version $Rev$ $Date$
  */
 public class DynamicGAttributeInfo extends GAttributeInfo {
+    public DynamicGAttributeInfo(String name, String type, boolean persistent, boolean manageable,
EncryptionSetting encrypted, boolean readable, boolean writable) {
+        super(name, type, persistent, manageable, encrypted, readable, writable, null, null);
+    }
+    
     public DynamicGAttributeInfo(String name, String type, boolean persistent, boolean manageable,
boolean readable, boolean writable) {
         super(name, type, persistent, manageable, readable, writable, null, null);
     }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GAttributeInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GAttributeInfo.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GAttributeInfo.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GAttributeInfo.java
Wed Jul 29 06:54:50 2009
@@ -17,11 +17,11 @@
 
 package org.apache.geronimo.gbean;
 
-import java.io.Serializable;
-import java.util.Arrays;
-
+import org.apache.geronimo.gbean.annotation.EncryptionSetting;
 import org.apache.geronimo.kernel.KernelRegistry;
 
+import java.io.Serializable;
+
 /**
  * Describes an attibute of a GBean.
  *
@@ -51,6 +51,11 @@
     private final boolean manageable;
 
     /**
+     * Does this attribute need to be encrypted when persisted?
+     */
+    private final EncryptionSetting encrypted;
+
+    /**
      * Is this attribute readable?
      */
     private final boolean readable;
@@ -77,11 +82,34 @@
     }
 
     public GAttributeInfo(String name, String type, boolean persistent, boolean manageable,
boolean readable, boolean writable, String getterName, String setterName) {
+        this(name, type, persistent, manageable, EncryptionSetting.defaultEncryption(name,
type), readable, writable, getterName,
+                setterName);
+    }
+
+    public GAttributeInfo(String name, String type, boolean persistent, boolean manageable,
boolean encrypted, String getterName, String setterName) {
+        this(name, type, persistent, manageable, encrypted ? EncryptionSetting.ENCRYPTED
: EncryptionSetting.PLAINTEXT, getterName != null, setterName != null, getterName,
+                setterName);
+    }
+
+    public GAttributeInfo(String name, String type, boolean persistent, boolean manageable,
EncryptionSetting encrypted, String getterName, String setterName) {
+        this(name, type, persistent, manageable, encrypted, getterName != null, setterName
!= null, getterName,
+                setterName);
+    }
+
+    public GAttributeInfo(String name, String type, boolean persistent, boolean manageable,
EncryptionSetting encrypted, boolean readable, boolean writable, String getterName, String
setterName) {
+        if (encrypted == null) throw new NullPointerException("enctryption must be specified");
+        if (encrypted == EncryptionSetting.ENCRYPTED && !"java.lang.String".equals(type))
{
+            throw new IllegalArgumentException("Only attributes of String type can be encrypted.");
+        }
+        if (encrypted == EncryptionSetting.DEFAULT) {
+            encrypted = EncryptionSetting.defaultEncryption(name, type);
+        }
         this.name = name;
         this.type = type;
         this.persistent = persistent;
         //non persistent attributes cannot be manageable
         this.manageable = manageable & persistent;
+        this.encrypted = encrypted;
         this.readable = readable;
         this.writable = writable;
         this.getterName = getterName;
@@ -104,6 +132,14 @@
         return manageable;
     }
 
+    public boolean isEncrypted() {
+        return encrypted == EncryptionSetting.ENCRYPTED;
+    }
+
+    public EncryptionSetting getEncryptedSetting() {
+        return encrypted;
+    }
+
     public boolean isReadable() {
         return readable;
     }
@@ -122,44 +158,48 @@
 
     public String toString() {
         return "[GAttributeInfo: name=" + name +
-                 " type=" + type +
-                 " persistent=" + persistent +
-                 " manageable=" + manageable +
-                 " readable=" + readable +
-                 " writable=" + writable +
-                 " getterName=" + getterName +
-                 " setterName=" + setterName +
-                 "]";
+                " type=" + type +
+                " persistent=" + persistent +
+                " manageable=" + manageable +
+                " encrypted=" + encrypted +
+                " readable=" + readable +
+                " writable=" + writable +
+                " getterName=" + getterName +
+                " setterName=" + setterName +
+                "]";
     }
 
     public String toXML(AbstractName abstractName) {
         StringBuilder xml = new StringBuilder();
 
         xml.append("<gAttributeInfo ");
-        xml.append("name='" + name + "' ");
-        xml.append("type='" + type + "' ");
-        xml.append("persistent='" + persistent + "' ");
-        xml.append("manageable='" + manageable + "' ");
-        xml.append("readable='" + readable + "' ");
-        xml.append("writable='" + writable + "' ");
+        xml.append("name='").append(name).append("' ");
+        xml.append("type='").append(type).append("' ");
+        xml.append("persistent='").append(persistent).append("' ");
+        xml.append("manageable='").append(manageable).append("' ");
+        xml.append("encrypted='").append(encrypted).append("' ");
+        xml.append("readable='").append(readable).append("' ");
+        xml.append("writable='").append(writable).append("' ");
         xml.append(">");
 
-        xml.append("<getterName>" + getterName + "</getterName>");
-        xml.append("<setterName>" + setterName + "</setterName>");
+        xml.append("<getterName>").append(getterName).append("</getterName>");
+        xml.append("<setterName>").append(setterName).append("</setterName>");
 
         if (readable) {
             try {
                 Object value = KernelRegistry.getSingleKernel().getAttribute(abstractName,
name);
                 if (value != null) {
                     if (value instanceof String[]) {
-                        for (String valueString : Arrays.asList((String[]) value))
-                            xml.append("<value>" + valueString + "</value>");
+                        for (String valueString : (String[])value) {
+                            xml.append("<value>").append(valueString).append("</value>");
+                        }
                     } else {
-                        xml.append("<value>" + value + "</value>");
+                        value = encrypted.encrypt((String) value);
+                        xml.append("<value>").append(value).append("</value>");
                     }
                 }
             } catch (Exception e) {
-
+                xml.append("<value>[could not be determined:").append(e.getMessage()).append("]</value>");
             }
         }
 

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
Wed Jul 29 06:54:50 2009
@@ -27,6 +27,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.geronimo.gbean.annotation.EncryptionSetting;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -131,8 +133,19 @@
     public Object getAttribute(String name) {
         return attributes.get(name);
     }
+    
+    private EncryptionSetting isEncrypted(String attrName) {
+        if (gbeanInfo != null) {
+            GAttributeInfo attr = gbeanInfo.getAttribute(attrName);
+            if (attr != null) {
+                return attr.getEncryptedSetting();
+            }
+        }
+        return EncryptionSetting.PLAINTEXT;
+    }
 
     public void setAttribute(String name, Object value) {
+        value = isEncrypted(name). decrypt(value);
         attributes.put(name, value);
     }
 
@@ -228,6 +241,7 @@
         for (Map.Entry<String, Object> entry : attributes.entrySet()) {
             String name = entry.getKey();
             Object value = entry.getValue();
+            value = isEncrypted(name).encrypt(value);
             try {
                 out.writeObject(name);
                 out.writeObject(value);
@@ -377,3 +391,4 @@
 
 }
 
+

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
Wed Jul 29 06:54:50 2009
@@ -120,11 +120,11 @@
 
     private final Class gbeanType;
 
-    private final Map attributes = new HashMap();
+    private final Map<String, GAttributeInfo> attributes = new HashMap<String, GAttributeInfo>();
 
     private GConstructorInfo constructor = new GConstructorInfo();
 
-    private final Map operations = new HashMap();
+    private final Map<GOperationSignature, GOperationInfo> operations = new HashMap<GOperationSignature,
GOperationInfo>();
 
     private final Map references = new HashMap();
 
@@ -233,11 +233,12 @@
                     // magic attributes can't be persistent
                     continue;
                 }
-                attributes.put(attributeName,
+                attributes.put(attributeName,   
                         new GAttributeInfo(attributeName,
-                                attribute.getType(),
+                                attribute.getType(), 
                                 true,
                                 attribute.isManageable(),
+                                attribute.getEncryptedSetting(),
                                 attribute.getGetterName(),
                                 attribute.getSetterName()));
             } else {
@@ -264,6 +265,7 @@
                                 attribute.getType(),
                                 attribute.isPersistent(),
                                 true,
+                                attribute.getEncryptedSetting(),
                                 attribute.getGetterName(),
                                 attribute.getSetterName()));
             }
@@ -317,6 +319,7 @@
                                     attributeType,
                                     attribute.isPersistent() || persistentNames.contains(attributeName),
                                     attribute.isManageable() || manageableNames.contains(attributeName),
+                                    attribute.getEncryptedSetting(),
                                     method.getName(),
                                     attribute.getSetterName()));
                 }
@@ -341,6 +344,7 @@
                                     attributeType,
                                     attribute.isPersistent() || persistentNames.contains(attributeName),
                                     attribute.isManageable() || manageableNames.contains(attributeName),
+                                    attribute.getEncryptedSetting(),
                                     attribute.getGetterName(),
                                     method.getName()));
                 }
@@ -362,7 +366,6 @@
             addInterface(set, cls[i]);
         }
     }
-
     public void addAttribute(String name, Class type, boolean persistent) {
         addAttribute(name, type.getName(), persistent, true);
     }
@@ -381,6 +384,16 @@
         addAttribute(new GAttributeInfo(name, type, persistent, manageable, getter, setter));
     }
 
+    public void addAttribute(String name, Class type, boolean persistent, boolean manageable,
boolean encrypted) {
+        addAttribute(name, type.getName(), persistent, manageable, encrypted);
+    }
+
+    public void addAttribute(String name, String type, boolean persistent, boolean manageable,
boolean encrypted) {
+        String getter = searchForGetter(name, type, gbeanType);
+        String setter = searchForSetter(name, type, gbeanType);
+        addAttribute(new GAttributeInfo(name, type, persistent, manageable, encrypted, getter,
setter));
+    }
+
     public void addAttribute(GAttributeInfo info) {
         attributes.put(info.getName(), info);
     }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilder.java
Wed Jul 29 06:54:50 2009
@@ -114,7 +114,16 @@
                     String name = attribute.name();
                     boolean persistent = attribute.persistent();
                     boolean manageable = attribute.manageable();
-                    infoBuilder.addAttribute(name, parameterType, persistent, manageable);
+                    if (attribute.encrypted() == EncryptionSetting.ENCRYPTED) {
+                        infoBuilder.addAttribute(name, parameterType,
+                                persistent, manageable, true);
+                    } else if (attribute.encrypted() == EncryptionSetting.PLAINTEXT) {
+                        infoBuilder.addAttribute(name, parameterType,
+                                persistent, manageable, false);
+                    } else {
+                        infoBuilder.addAttribute(name, parameterType,
+                                persistent, manageable);
+                    }
                     cstrNames[index] = name;
                     annotationFound = true;
                     break;
@@ -168,7 +177,13 @@
             Class type = method.getParameterTypes()[0];
             String name = getName(method);
             name = Introspector.decapitalize(name);
-            infoBuilder.addAttribute(name, type, true, persistent.manageable());
+            if (persistent.encrypted() == EncryptionSetting.ENCRYPTED) {
+                infoBuilder.addAttribute(name, type, true, persistent.manageable(), true);
+            } else if (persistent.encrypted() == EncryptionSetting.PLAINTEXT) {
+                infoBuilder.addAttribute(name, type, true, persistent.manageable(), false);
+            } else {
+                infoBuilder.addAttribute(name, type, true, persistent.manageable());
+            }
         }
     }
     

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/ParamAttribute.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/ParamAttribute.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/ParamAttribute.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/ParamAttribute.java
Wed Jul 29 06:54:50 2009
@@ -39,4 +39,7 @@
     boolean persistent() default true;
     
     boolean manageable() default true;
+    
+    EncryptionSetting encrypted() default EncryptionSetting.DEFAULT;
+
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/Persistent.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/Persistent.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/Persistent.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/Persistent.java
Wed Jul 29 06:54:50 2009
@@ -35,4 +35,5 @@
 @Target(value = {METHOD})
 public @interface Persistent {
     boolean manageable() default true;
+    EncryptionSetting encrypted() default EncryptionSetting.DEFAULT;
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanAttribute.java
Wed Jul 29 06:54:50 2009
@@ -17,14 +17,15 @@
 
 package org.apache.geronimo.gbean.runtime;
 
-import java.lang.reflect.Method;
-
 import org.apache.geronimo.gbean.DynamicGAttributeInfo;
 import org.apache.geronimo.gbean.DynamicGBean;
 import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.gbean.annotation.EncryptionSetting;
 import org.apache.geronimo.kernel.ClassLoading;
 
+import java.lang.reflect.Method;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -47,6 +48,8 @@
 
     private final boolean manageable;
 
+    private final EncryptionSetting encrypted;
+
     private Object persistentValue;
     /**
      * Is this a special attribute like objectName, classLoader or gbeanContext?
@@ -113,6 +116,9 @@
         // not manageable
         this.manageable = false;
 
+        // special attributes are not encrypted
+        this.encrypted = EncryptionSetting.PLAINTEXT;
+
         // create an attribute info for this gbean
         if (attribute != null) {
             GAttributeInfo attributeInfo = attribute.getAttributeInfo();
@@ -120,6 +126,7 @@
                     this.type.getName(),
                     this.persistent,
                     this.manageable,
+                    this.encrypted,
                     this.readable,
                     this.writable,
                     attributeInfo.getGetterName(),
@@ -129,6 +136,7 @@
                     this.type.getName(),
                     this.persistent,
                     this.manageable,
+                    this.encrypted,
                     this.readable,
                     this.writable,
                     null,
@@ -148,7 +156,6 @@
         this.special = false;
         this.framework = true;
         this.dynamic = false;
-        this.persistentValue = persistentValue;
 
         if (gbeanInstance == null || name == null || type == null) {
             throw new IllegalArgumentException("null param(s) supplied");
@@ -181,6 +188,9 @@
                 this.writable,
                 null,
                 null);
+
+        this.encrypted = attributeInfo.getEncryptedSetting();
+        this.persistentValue = encrypted.decrypt(persistentValue);
     }
 
     public GBeanAttribute(GBeanInstance gbeanInstance, GAttributeInfo attributeInfo) throws
InvalidConfigurationException {
@@ -200,6 +210,7 @@
         }
         this.persistent = attributeInfo.isPersistent();
         this.manageable = attributeInfo.isManageable();
+        this.encrypted = attributeInfo.getEncryptedSetting();
 
         readable = attributeInfo.isReadable();
         writable = attributeInfo.isWritable();
@@ -299,6 +310,14 @@
         return manageable;
     }
 
+    public boolean isEncrypted() {
+        return encrypted == EncryptionSetting.ENCRYPTED;
+    }
+
+    public EncryptionSetting getEncryptionSetting() {
+        return encrypted;
+    }
+
     public boolean isSpecial() {
         return special;
     }
@@ -320,7 +339,7 @@
         }
 
         // @todo actually check type
-        this.persistentValue = persistentValue;
+        this.persistentValue = encrypted.decrypt(persistentValue);
     }
 
     public Object getValue(Object target) throws Exception {
@@ -368,6 +387,7 @@
         }
 
         // call the setter
+        value = encrypted.decrypt(value);
         setInvoker.invoke(target, new Object[]{value});
     }
 
@@ -399,11 +419,11 @@
             return null;
         }
     }
-    
+
     public void inject(Object target) throws Exception {
         if ((persistent || special) && writable && null != persistentValue)
{
             setValue(target, persistentValue);
         }
     }
-    
+
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/xstream/GBeanDataConverter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/xstream/GBeanDataConverter.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/xstream/GBeanDataConverter.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/xstream/GBeanDataConverter.java
Wed Jul 29 06:54:50 2009
@@ -16,17 +16,16 @@
  */
 package org.apache.geronimo.kernel.config.xstream;
 
-import java.util.Iterator;
+import java.net.URI;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.LinkedHashSet;
-import java.util.LinkedHashMap;
-import java.net.URI;
 
+import com.thoughtworks.xstream.converters.ConversionException;
 import com.thoughtworks.xstream.converters.Converter;
 import com.thoughtworks.xstream.converters.MarshallingContext;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
-import com.thoughtworks.xstream.converters.ConversionException;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 import com.thoughtworks.xstream.mapper.Mapper;
@@ -36,6 +35,7 @@
 import org.apache.geronimo.gbean.GBeanInfoFactory;
 import org.apache.geronimo.gbean.MultiGBeanInfoFactory;
 import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.gbean.annotation.EncryptionSetting;
 
 /**
  * @version $Rev$ $Date$
@@ -79,20 +79,19 @@
         }
 
         // dependencies Set<ReferencePatterns>
-        Set dependencies = gbeanData.getDependencies();
-        for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) {
-            ReferencePatterns referencePatterns = (ReferencePatterns) iterator.next();
+        Set<ReferencePatterns> dependencies = gbeanData.getDependencies();
+        for (ReferencePatterns referencePatterns : dependencies) {
             writer.startNode("dependency");
             marshallingContext.convertAnother(referencePatterns);
             writer.endNode();
         }
 
         // attributes Map<String, Object>
-        Map attributes = gbeanData.getAttributes();
-        for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            String attributeName = (String) entry.getKey();
-            Object attributeValue = entry.getValue();
+        Map<String, Object> attributes = gbeanData.getAttributes();
+        for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+            String attributeName = entry.getKey();
+            EncryptionSetting encryptionSetting = gbeanInfo.getAttribute(attributeName).getEncryptedSetting();
+            Object attributeValue = encryptionSetting.encrypt(entry.getValue());
             if (attributeValue != null) {
                 writer.startNode("attribute");
                 writer.addAttribute("name", attributeName);
@@ -105,11 +104,10 @@
             }
         }
         // references Map<String, ReferencePatterns>
-        Map references = gbeanData.getReferences();
-        for (Iterator iterator = references.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            String referenceName = (String) entry.getKey();
-            ReferencePatterns referencePatterns = (ReferencePatterns) entry.getValue();
+        Map<String, ReferencePatterns> references = gbeanData.getReferences();
+        for (Map.Entry<String, ReferencePatterns> entry : references.entrySet()) {
+            String referenceName = entry.getKey();
+            ReferencePatterns referencePatterns = entry.getValue();
             writer.startNode("reference");
             writer.addAttribute("name", referenceName);
             marshallingContext.convertAnother(referencePatterns);
@@ -137,9 +135,9 @@
             gbeanInfo = infoFactory.getGBeanInfo(sourceClass, classLoader);
         }
 
-        Set dependencies = new LinkedHashSet();
-        Map attributes = new LinkedHashMap();
-        Map references = new LinkedHashMap();
+        Set<ReferencePatterns> dependencies = new LinkedHashSet<ReferencePatterns>();
+        Map<String, Object> attributes = new LinkedHashMap<String, Object>();
+        Map<String, ReferencePatterns> references = new LinkedHashMap<String, ReferencePatterns>();
         while (reader.hasMoreChildren()) {
             reader.moveDown();
 
@@ -184,16 +182,14 @@
 
         GBeanData gbeanData = new GBeanData(abstractName, gbeanInfo);
         gbeanData.setDependencies(dependencies);
-        for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            String attributeName = (String) entry.getKey();
+        for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+            String attributeName = entry.getKey();
             Object attributeValue = entry.getValue();
             gbeanData.setAttribute(attributeName, attributeValue);
         }
-        for (Iterator iterator = references.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            String referenceName = (String) entry.getKey();
-            ReferencePatterns referencePatterns = (ReferencePatterns) entry.getValue();
+        for (Map.Entry <String, ReferencePatterns> entry : references.entrySet()) {
+            String referenceName = entry.getKey();
+            ReferencePatterns referencePatterns = entry.getValue();
             gbeanData.setReferencePatterns(referenceName, referencePatterns);
         }
 

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilderTest.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilderTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoBuilderTest.java
Wed Jul 29 06:54:50 2009
@@ -50,11 +50,14 @@
 
         GConstructorInfo constructor = beanInfo.getConstructor();
         List<String> cstrNames = constructor.getAttributeNames();
-        assertEquals(4, cstrNames.size());
+        assertEquals(5, cstrNames.size());
         assertEquals("classLoader", cstrNames.get(0));
         assertEquals("name", cstrNames.get(1));
         assertEquals("Name", cstrNames.get(2));
         assertEquals("Collection", cstrNames.get(3));
+        assertEquals("attr1", cstrNames.get(4));
+        assertTrue(beanInfo.getAttribute("attr1").isEncrypted());
+        
         
         GAttributeInfo nameAttribute = beanInfo.getAttribute("name");
         assertNotNull(nameAttribute);
@@ -74,12 +77,21 @@
         assertEquals(String.class.getName(), setterAttribute.getType());
         assertEquals(true, setterAttribute.isPersistent());
         assertEquals(true, setterAttribute.isManageable());
+        assertEquals(EncryptionSetting.ENCRYPTED, setterAttribute.getEncryptedSetting());
+        
+        GAttributeInfo password = beanInfo.getAttribute("password");
+        assertNotNull(password);
+        assertEquals(String.class.getName(), password.getType());
+        assertEquals(true, password.isPersistent());
+        assertEquals(true, password.isManageable());
+        assertEquals(EncryptionSetting.ENCRYPTED, password.getEncryptedSetting());
 
         GAttributeInfo setterNotManageableAttribute = beanInfo.getAttribute("setterNotManageableAttribute");
         assertNotNull(setterNotManageableAttribute);
         assertEquals(String.class.getName(), setterNotManageableAttribute.getType());
         assertEquals(true, setterNotManageableAttribute.isPersistent());
         assertEquals(false, setterNotManageableAttribute.isManageable());
+        assertEquals(EncryptionSetting.PLAINTEXT, setterNotManageableAttribute.getEncryptedSetting());
         
         GReferenceInfo setterReference = beanInfo.getReference("SetterReference");
         assertNotNull(setterReference);
@@ -165,10 +177,11 @@
         public SmokeGBean(@ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader
classLoader,
             @ParamAttribute(name = "name") String name,
             @ParamReference(name = "Name") Runnable runnable,
-            @ParamReference(name = "Collection") Collection<Runnable> runnables) {
+            @ParamReference(name = "Collection") Collection<Runnable> runnables,
+            @ParamAttribute(name = "attr1", encrypted = EncryptionSetting.ENCRYPTED) String
confidential) {
         }
         
-        @Persistent
+        @Persistent(encrypted=EncryptionSetting.ENCRYPTED)
         public void setSetterAttribute(String value) {
         }
         
@@ -176,6 +189,10 @@
         public void setSetterNotManageableAttribute(String value) {
         }
         
+        @Persistent
+        public void setPassword(String value) {
+        }
+                
         @Reference
         public void setSetterReference(Runnable value) {
         }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
Wed Jul 29 06:54:50 2009
@@ -20,6 +20,7 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.KernelFactory;
@@ -48,6 +49,15 @@
     private GAttributeInfo attributeInfo = null;
     private Kernel kernel;
 
+    public final void testGBeanAttributeEncryption() {
+        GBeanInfo ginfo = gbeanInstance.getGBeanInfo();
+        assertTrue(ginfo.getAttribute("value").isEncrypted());
+        assertTrue(ginfo.getAttribute("yourPassword").isEncrypted());
+        assertFalse(ginfo.getAttribute("myPassword").isEncrypted());
+        assertFalse(ginfo.getAttribute("nonStringPassword").isEncrypted());
+        assertFalse(ginfo.getAttribute("finalInt").isEncrypted());
+    }
+    
     public final void testGBeanAttributStringClassMethodInvokerMethodInvoker() {
         try {
             GBeanAttribute.createFrameworkAttribute(null, null, null, null);
@@ -62,18 +72,21 @@
         assertTrue(attribute.isReadable());
         assertFalse(attribute.isWritable());
         assertFalse(attribute.isPersistent());
+        assertFalse(attribute.isEncrypted());
         attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName,
String.class, null, setInvoker, false, null, false);
         assertEquals(String.class, attribute.getType());
         assertEquals(attributeName, attribute.getName());
         assertFalse(attribute.isReadable());
         assertTrue(attribute.isWritable());
         assertFalse(attribute.isPersistent());
+        assertFalse(attribute.isEncrypted());
         attribute = GBeanAttribute.createFrameworkAttribute(gbeanInstance, attributeName,
String.class, getInvoker, setInvoker, false, null, false);
         assertEquals(String.class, attribute.getType());
         assertEquals(attributeName, attribute.getName());
         assertTrue(attribute.isReadable());
         assertTrue(attribute.isWritable());
         assertFalse(attribute.isPersistent());
+        assertFalse(attribute.isEncrypted());
     }
 
     public final void testGBeanAttributeInfoClass() {

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/MockGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/MockGBean.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/MockGBean.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/MockGBean.java
Wed Jul 29 06:54:50 2009
@@ -67,7 +67,10 @@
         infoFactory.addAttribute("classLoader", ClassLoader.class, false);
         infoFactory.addAttribute("actualKernel", Kernel.class, false);
         infoFactory.addAttribute("kernel", Kernel.class, false);
-        infoFactory.addAttribute("value", String.class, true);
+        infoFactory.addAttribute("value", String.class, true, true, true);
+        infoFactory.addAttribute("myPassword", String.class, true, true, false);
+        infoFactory.addAttribute("yourPassword", String.class, true);
+        infoFactory.addAttribute("nonStringPassword", Object.class, true);
         infoFactory.addAttribute("finalInt", Integer.TYPE, true);
         infoFactory.addAttribute("mutableInt", Integer.TYPE, false);
         infoFactory.addAttribute("exceptionMutableInt", Integer.TYPE, true);

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/ConfigurationUtilTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/ConfigurationUtilTest.java?rev=798794&r1=798793&r2=798794&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/ConfigurationUtilTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/kernel/config/ConfigurationUtilTest.java
Wed Jul 29 06:54:50 2009
@@ -52,6 +52,12 @@
         configurationData = createConfigurationData(xstreamConfigurationMarshaler);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         xstreamConfigurationMarshaler.writeConfigurationData(configurationData, out);
+        // Test whether the attribute "value" is encrypted
+        assertFalse(out.toString().contains("1234"));
+        assertFalse(out.toString().contains("5678"));
+        // Test whether other attributes are not encrypted
+        assertTrue(out.toString().contains("Parent"));
+        assertTrue(out.toString().contains("child"));
         data = copy(configurationData, xstreamConfigurationMarshaler, xstreamConfigurationMarshaler);
         assertEquals(data, configurationData);
 



Mime
View raw message