You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/07/29 21:13:02 UTC
svn commit: r799023 - in /geronimo/server/trunk/framework/modules:
geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/
geronimo-system/src/main/java/org/apache/geronimo/system/configuration/
geronimo-system/src/test/java/org/apache/gero...
Author: djencks
Date: Wed Jul 29 19:13:02 2009
New Revision: 799023
URL: http://svn.apache.org/viewvc?rev=799023&view=rev
Log:
GERONIMO-3003 Encrypt poassoreds and morked attributes in serialized gbeans and config.xml. Modified from patch by Jack Cai, many thanks. 2nd half of patch.... missed adding one file and several geronimo-system changes earlier
Added:
geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java (with props)
Modified:
geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java
geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java
geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java?rev=799023&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java Wed Jul 29 19:13:02 2009
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gbean.annotation;
+
+import org.apache.geronimo.crypto.EncryptionManager;
+
+public enum EncryptionSetting {
+ ENCRYPTED {
+ public Object encrypt(Object plaintext) {
+ if (plaintext == null) return null;
+ return EncryptionManager.encrypt((String)plaintext);
+ }
+ public Object decrypt(Object encrypted) {
+ if (encrypted == null) return null;
+ return EncryptionManager.decrypt((String)encrypted);
+ }},
+ PLAINTEXT {
+
+ public Object encrypt(Object plaintext) {
+ return plaintext;
+ }
+ public Object decrypt(Object encrypted) {
+ return encrypted;
+ }},
+ // Default is to encrypt attributes whose name contains "password"
+ DEFAULT {
+
+ public Object encrypt(Object plaintext) {
+ throw new RuntimeException("dont call this");
+ }
+ public Object decrypt(Object encrypted) {
+ throw new RuntimeException("dont call this");
+ }};
+
+ public abstract Object encrypt(Object plaintext);
+
+ public abstract Object decrypt(Object encrypted);
+
+ public static EncryptionSetting defaultEncryption(String name, String type) {
+ if (name == null) throw new NullPointerException("Name missing");
+ if (type == null) throw new NullPointerException("type missing");
+ if (!String.class.getName().equals(type)) return PLAINTEXT;
+ return (name.toLowerCase().indexOf("password") > -1)? ENCRYPTED: PLAINTEXT;
+ }
+
+}
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/EncryptionSetting.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java?rev=799023&r1=799022&r2=799023&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/GBeanOverride.java Wed Jul 29 19:13:02 2009
@@ -32,9 +32,6 @@
import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLStreamException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.geronimo.common.propertyeditor.PropertyEditors;
import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.gbean.AbstractNameQuery;
@@ -51,7 +48,8 @@
import org.apache.geronimo.system.plugin.model.AttributeType;
import org.apache.geronimo.system.plugin.model.GbeanType;
import org.apache.geronimo.system.plugin.model.ReferenceType;
-import org.apache.geronimo.crypto.EncryptionManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version $Rev$ $Date$
@@ -64,6 +62,7 @@
private final Object name;
private String comment;
private boolean load;
+ //Note that encrypted attributes are stored encrypted in this map.
private final Map<String, String> attributes = new LinkedHashMap<String, String>();
private final Map<String, String> propertyEditors = new HashMap<String, String>();
private final Map<String, ReferencePatterns> references = new LinkedHashMap<String, ReferencePatterns>();
@@ -136,15 +135,15 @@
load = true;
// set attributes
- for (Object o : gbeanData.getAttributes().entrySet()) {
- Map.Entry entry = (Map.Entry) o;
- String attributeName = (String) entry.getKey();
+ for (Map.Entry<String, Object> entry : gbeanData.getAttributes().entrySet()) {
+ String attributeName = entry.getKey();
GAttributeInfo attributeInfo = gbeanInfo.getAttribute(attributeName);
if (attributeInfo == null) {
throw new InvalidAttributeException("No attribute: " + attributeName + " for gbean: " + gbeanData.getAbstractName());
}
+ // TODO: shouldn't we only save manageable attributes here?
Object attributeValue = entry.getValue();
- setAttribute(attributeName, attributeValue, attributeInfo.getType(), classLoader);
+ setAttribute(attributeInfo, attributeValue, classLoader);
}
// references can be coppied in blind
@@ -197,8 +196,7 @@
if (value == null || value.length() == 0) {
setClearAttribute(attr.getName());
} else {
- String truevalue = (String) EncryptionManager.decrypt(value);
- setAttribute(attr.getName(), truevalue);
+ setAttribute(attr.getName(), value);
}
}
} else if (o instanceof ReferenceType) {
@@ -312,12 +310,22 @@
references.remove(referenceName);
}
- public void setAttribute(String attributeName, Object attributeValue, String attributeType, ClassLoader classLoader) throws InvalidAttributeException {
- String stringValue = getAsText(attributeName, attributeValue, attributeType, classLoader);
- setAttribute(attributeName, stringValue);
+ public void setAttribute(GAttributeInfo attrInfo, Object attributeValue,
+ ClassLoader classLoader) throws InvalidAttributeException {
+ String stringValue = getAsText(attrInfo.getName(), attributeValue, attrInfo.getType(), classLoader);
+ stringValue = (String) attrInfo.getEncryptedSetting().encrypt(stringValue);
+ setAttribute(attrInfo.getName(), stringValue);
}
- public void setAttribute(String attributeName, String attributeValue) {
+ /**
+ * This method should be discouraged for usage outside in future, as it does
+ * not pass in encryption meta-information about the attribute being set.
+ *
+ * Use setAttribute(GAttributeInfo attrInfo, Object attributeValue,
+ * ClassLoader classLoader) instead.
+ *
+ */
+ private void setAttribute(String attributeName, String attributeValue) {
if (attributeValue == null || attributeValue.length() == 0) {
setClearAttribute(attributeName);
} else {
@@ -395,6 +403,7 @@
if (value == null) {
return null;
}
+ value = (String) attribute.getEncryptedSetting().decrypt(value);
value = substituteVariables(attribute.getName(), value);
PropertyEditor editor = loadPropertyEditor(attribute, classLoader);
editor.setAsText(value);
@@ -468,10 +477,6 @@
} else {
nullAttributes.remove(name);
clearAttributes.remove(name);
-
- if (name.toLowerCase().indexOf("password") > -1) {
- value = EncryptionManager.encrypt(value);
- }
/**
* if there was a value such as jdbc url with & then when that value was oulled
* from the config.xml the & would have been replaced/converted to '&', we need to check
Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=799023&r1=799022&r2=799023&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java Wed Jul 29 19:13:02 2009
@@ -277,7 +277,7 @@
}
try {
- gbean.setAttribute(attribute.getName(), value, attribute.getType(), classLoader);
+ gbean.setAttribute(attribute, value, classLoader);
attributeChanged();
} catch (InvalidAttributeException e) {
// attribute can not be represented as a string
@@ -410,6 +410,13 @@
}
}
+ void write(Writer writer) throws XMLStreamException, JAXBException,
+ IOException {
+ AttributesType attributes = serverOverride.writeXml();
+ AttributesXmlUtil.writeAttributes(attributes, writer);
+ writer.flush();
+ }
+
private static void saveXmlToFile(File file, ServerOverride serverOverride) {
try {
Writer fileOut = new FileWriter(file);
Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java?rev=799023&r1=799022&r2=799023&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/GBeanOverrideTest.java Wed Jul 29 19:13:02 2009
@@ -19,19 +19,22 @@
package org.apache.geronimo.system.configuration;
-import java.beans.PropertyEditorSupport;
-import java.net.URI;
-import java.util.Collection;
-import java.util.Collections;
-
import junit.framework.TestCase;
-
import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.annotation.AnnotationGBeanInfoFactory;
+import org.apache.geronimo.gbean.annotation.GBean;
import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
import org.apache.geronimo.system.plugin.model.AttributeType;
import org.apache.geronimo.system.plugin.model.GbeanType;
+import java.beans.PropertyEditorSupport;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
+
/**
*
* @version $Rev:$ $Date:$
@@ -40,13 +43,26 @@
private GbeanType gbeanType;
private String attributeName;
+ private GBeanInfo gbeanInfo;
+ private GAttributeInfo beanInfo;
+ private GAttributeInfo serviceInfo;
+ private GAttributeInfo intInfo;
+ private GAttributeInfo collectionInfo;
+ private GAttributeInfo fooInfo;
+ private ClassLoader classLoader = getClass().getClassLoader();
@Override
protected void setUp() throws Exception {
gbeanType = new GbeanType();
gbeanType.setName("name");
- attributeName = "attName";
+ attributeName = "bean";
+ gbeanInfo = new AnnotationGBeanInfoFactory().getGBeanInfo(TestGBean.class);
+ beanInfo = gbeanInfo.getAttribute(attributeName);
+ serviceInfo = gbeanInfo.getAttribute("service");
+ intInfo = gbeanInfo.getAttribute("intValue");
+ collectionInfo = gbeanInfo.getAttribute("collection");
+ fooInfo = gbeanInfo.getAttribute("foo");
}
public void testPropertyEditorIsCarriedByWriteXml() throws Exception {
@@ -65,7 +81,7 @@
public void testPropertyEditorIsUsedToGetTextValue() throws Exception {
GBeanOverride override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute(attributeName, new Bean(), Bean.class.getName(), getClass().getClassLoader());
+ override.setAttribute(beanInfo, new Bean(), classLoader);
assertEquals("bean", override.getAttribute(attributeName));
@@ -77,7 +93,7 @@
public void testPropertyEditorIsDefinedWhenAttributeIsNotAPrimitiveAndItsTypeDoesNotEqualValueType() throws Exception {
GBeanOverride override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute(attributeName, new Bean(), Service.class.getName(), getClass().getClassLoader());
+ override.setAttribute(serviceInfo, new Bean(), classLoader);
GbeanType copiedGBeanType = override.writeXml();
assertEquals(1, copiedGBeanType.getAttributeOrReference().size());
@@ -87,7 +103,7 @@
public void testPropertyEditorIsNotDefinedWhenAttributeTypeEqualsValueType() throws Exception {
GBeanOverride override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute(attributeName, new Bean(), Bean.class.getName(), getClass().getClassLoader());
+ override.setAttribute(beanInfo, new Bean(), classLoader);
GbeanType copiedGBeanType = override.writeXml();
assertEquals(1, copiedGBeanType.getAttributeOrReference().size());
@@ -97,7 +113,7 @@
public void testPropertyEditorIsNotDefinedForPrimitives() throws Exception {
GBeanOverride override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute(attributeName, new Integer(1), int.class.getName(), getClass().getClassLoader());
+ override.setAttribute(intInfo, 1, classLoader);
GbeanType copiedGBeanType = override.writeXml();
assertEquals(1, copiedGBeanType.getAttributeOrReference().size());
@@ -107,7 +123,7 @@
public void testPropertyEditorIsNotDefinedForCollectionSubClasses() throws Exception {
GBeanOverride override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute(attributeName, Collections.singleton("test"), Collection.class.getName(), getClass().getClassLoader());
+ override.setAttribute(collectionInfo, Collections.singleton("test"), classLoader);
GbeanType copiedGBeanType = override.writeXml();
assertEquals(1, copiedGBeanType.getAttributeOrReference().size());
@@ -145,7 +161,7 @@
override = new GBeanOverride(gbeanType, new JexlExpressionParser());
override.setNullAttribute("foo");
override.setClearAttribute("foo");
- override.setAttribute("foo", "bar");
+ override.setAttribute(fooInfo, "bar", classLoader);
override.writeXml();
assertFalse(override.isNullAttribute("foo"));
@@ -156,7 +172,7 @@
assertTrue(override.getAttributes().containsKey("foo"));
override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute("foo", "bar");
+ override.setAttribute(fooInfo, "bar", classLoader);
override.setNullAttribute("foo");
override.setClearAttribute("foo");
override.writeXml();
@@ -170,7 +186,7 @@
override = new GBeanOverride(gbeanType, new JexlExpressionParser());
override.setClearAttribute("foo");
- override.setAttribute("foo", "bar");
+ override.setAttribute(fooInfo, "bar", classLoader);
override.setNullAttribute("foo");
override.writeXml();
@@ -182,8 +198,8 @@
assertTrue(override.getNullAttributes().contains("foo"));
override = new GBeanOverride(gbeanType, new JexlExpressionParser());
- override.setAttribute("bar1", "foo");
- override.setAttribute("bar2", "foo");
+ override.setAttribute(gbeanInfo.getAttribute("bar1"), "foo", classLoader);
+ override.setAttribute(gbeanInfo.getAttribute("bar2"), "foo", classLoader);
override.getAttributes().put("foo", null);
GbeanType gbean = override.writeXml();
assertEquals(3, gbean.getAttributeOrReference().size());
@@ -192,13 +208,80 @@
assertTrue(attribute.isNull());
}
- public interface Service {
+ @GBean
+ public static class TestGBean {
+ private Bean bean;
+ private Service service;
+ private int intvalue;
+ private Collection collection;
+ private String foo;
+ private String bar1;
+ private String bar2;
+
+ public String getFoo() {
+ return foo;
+ }
+
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getBar1() {
+ return bar1;
+ }
+
+ public void setBar1(String bar1) {
+ this.bar1 = bar1;
+ }
+
+ public String getBar2() {
+ return bar2;
+ }
+
+ public void setBar2(String bar2) {
+ this.bar2 = bar2;
+ }
+
+ public Collection getCollection() {
+ return collection;
+ }
+
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
+
+ public int getIntValue() {
+ return intvalue;
+ }
+
+ public void setIntValue(int intvalue) {
+ this.intvalue = intvalue;
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ public void setService(Service service) {
+ this.service = service;
+ }
+
+
+ public Bean getBean() {
+ return bean;
+ }
+
+ public void setBean(Bean bean) {
+ this.bean = bean;
+ }
}
- public static class Bean implements Service {
+ public interface Service {
+ }
+ public static class Bean implements Service {
}
-
+
public static class BeanEditor extends PropertyEditorSupport {
@Override
@@ -212,5 +295,18 @@
}
}
-
+ public static class ServiceEditor extends PropertyEditorSupport {
+
+ @Override
+ public String getAsText() {
+ return "bean";
+ }
+
+ @Override
+ public void setAsText(String text) throws IllegalArgumentException {
+ assertEquals("bean", text);
+ }
+
+ }
+
}
Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java?rev=799023&r1=799022&r2=799023&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java Wed Jul 29 19:13:02 2009
@@ -16,30 +16,35 @@
*/
package org.apache.geronimo.system.configuration;
+import java.io.ByteArrayOutputStream;
+import java.io.FileReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
import junit.framework.TestCase;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GReferenceInfo;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.gbean.ReferencePatterns;
-import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.Naming;
import org.apache.geronimo.kernel.Jsr77Naming;
+import org.apache.geronimo.kernel.Naming;
import org.apache.geronimo.kernel.config.InvalidConfigException;
+import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.system.serverinfo.BasicServerInfo;
-
-import javax.management.ObjectName;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
/**
* @version $Rev$ $Date$
@@ -51,6 +56,7 @@
private Artifact configurationName;
private AbstractName gbeanName;
private GAttributeInfo attributeInfo;
+ private GAttributeInfo encryptedAttributeInfo;
private GReferenceInfo referenceInfo;
public void testConfigurationShouldLoad() throws Exception {
@@ -128,6 +134,22 @@
gbeanDatas.add(gbeanData);
gbeanDatas = localAttributeManager.applyOverrides(configurationName, gbeanDatas, getClass().getClassLoader());
assertEquals(attributeValue, gbeanData.getAttribute(attributeInfo.getName()));
+ StringWriter w = new StringWriter();
+ localAttributeManager.write(w);
+ assertTrue(w.toString().contains(attributeValue));
+ }
+
+ public void testEncryptedAttribute() throws Exception {
+ String attributeValue = "attribute value";
+ localAttributeManager.setValue(configurationName, gbeanName, encryptedAttributeInfo, attributeValue, getClass().getClassLoader());
+ Collection gbeanDatas = new ArrayList();
+ GBeanData gbeanData = new GBeanData(gbeanName, GBEAN_INFO);
+ gbeanDatas.add(gbeanData);
+ gbeanDatas = localAttributeManager.applyOverrides(configurationName, gbeanDatas, getClass().getClassLoader());
+ assertEquals(attributeValue, gbeanData.getAttribute(encryptedAttributeInfo.getName()));
+ StringWriter w = new StringWriter();
+ localAttributeManager.write(w);
+ assertFalse(w.toString().contains(attributeValue));
}
public void testSetReference() throws Exception {
@@ -227,6 +249,7 @@
ObjectName objectName = ObjectName.getInstance(":name=gbean,parent="+configurationName+",foo=bar");
gbeanName = new AbstractName(configurationName, objectName.getKeyPropertyList(), objectName);
attributeInfo = GBEAN_INFO.getAttribute("attribute");
+ encryptedAttributeInfo = GBEAN_INFO.getAttribute("secret");
referenceInfo = GBEAN_INFO.getReference("reference");
}
@@ -241,6 +264,7 @@
GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(LocalAttributeManagerTest.class);
infoFactory.addReference("reference", String.class);
infoFactory.addAttribute("attribute", String.class, true);
+ infoFactory.addAttribute("secret", String.class, true, true, true);
GBEAN_INFO = infoFactory.getBeanInfo();
}
Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java?rev=799023&r1=799022&r2=799023&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java Wed Jul 29 19:13:02 2009
@@ -32,6 +32,7 @@
import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.ReferencePatterns;
+import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.system.configuration.condition.JexlExpressionParser;
import org.apache.geronimo.system.configuration.condition.ParserUtils;
@@ -44,6 +45,13 @@
public class ServerOverrideTest extends TestCase {
private JexlExpressionParser expressionParser;
+ private GAttributeInfo cheeseInfo = new GAttributeInfo("cheese", String.class.getName(), true, true, "getCheese", "setCheese");
+ private GAttributeInfo sizeInfo = new GAttributeInfo("size", String.class.getName(), true, true, "getSize", "setSize");
+ private GAttributeInfo emptyStringInfo = new GAttributeInfo("emptyString", String.class.getName(), true, true, "getEmptyString", "setEmptyString");
+ private GAttributeInfo portInfo = new GAttributeInfo("port", int.class.getName(), true, true, "getPort", "setPort");
+ private GAttributeInfo expressionInfo = new GAttributeInfo("expression", boolean.class.getName(), true, true, "getExpression", "setExpression");
+ private ClassLoader classLoader = getClass().getClassLoader();
+
protected void setUp() throws java.lang.Exception {
HashMap<String, String> subs = new HashMap<String, String>();
subs.put("host", "localhost");
@@ -60,7 +68,7 @@
pizza.setLoad(false);
assertFalse(pizza.isLoad());
- pizza.setAttribute("cheese", "mozzarella");
+ pizza.setAttribute(cheeseInfo, "mozzarella", classLoader);
assertEquals("mozzarella", pizza.getAttribute("cheese"));
AbstractNameQuery pizzaOvenQuery = getAbstractNameQuery(":name=PizzaOven");
@@ -105,10 +113,10 @@
pizza.setLoad(false);
assertCopyIdentical(pizza);
- pizza.setAttribute("cheese", "mozzarella");
+ pizza.setAttribute(cheeseInfo, "mozzarella", classLoader);
assertCopyIdentical(pizza);
- pizza.setAttribute("size", "x-large");
+ pizza.setAttribute(sizeInfo, "x-large", classLoader);
assertCopyIdentical(pizza);
AbstractNameQuery pizzaOvenQuery = getAbstractNameQuery(":name=PizzaOven");
@@ -131,9 +139,9 @@
assertCopyIdentical(dinnerMenu);
GBeanOverride pizza = new GBeanOverride("Pizza", false, expressionParser);
- pizza.setAttribute("cheese", "mozzarella");
- pizza.setAttribute("size", "x-large");
- pizza.setAttribute("emptyString", "");
+ pizza.setAttribute(cheeseInfo, "mozzarella", classLoader);
+ pizza.setAttribute(sizeInfo, "x-large", classLoader);
+ pizza.setAttribute(emptyStringInfo, "", classLoader);
pizza.setClearAttribute("greenPeppers");
pizza.setNullAttribute("pineapple");
@@ -163,9 +171,9 @@
ConfigurationOverride dinnerMenu = new ConfigurationOverride(new Artifact("test","Dinner Menu","1.0","car"), false);
restaurant.addConfiguration(dinnerMenu);
GBeanOverride pizza = new GBeanOverride("Pizza", false, expressionParser);
- pizza.setAttribute("cheese", "mozzarella");
- pizza.setAttribute("size", "x-large");
- pizza.setAttribute("emptyString", "");
+ pizza.setAttribute(cheeseInfo, "mozzarella", classLoader);
+ pizza.setAttribute(sizeInfo, "x-large", classLoader);
+ pizza.setAttribute(emptyStringInfo, "", classLoader);
pizza.setClearAttribute("greenPeppers");
pizza.setNullAttribute("pineapple");
AbstractNameQuery pizzaOvenQuery = getAbstractNameQuery(":name=PizzaOven");
@@ -258,21 +266,21 @@
GBeanOverride gbean = new GBeanOverride(gbeanElement, expressionParser);
assertCopyIdentical(gbean);
GBeanData data = new GBeanData(MockGBean.GBEAN_INFO);
- gbean.setAttribute("port", "${port}");
+ gbean.setAttribute(portInfo, "${port}", classLoader);
gbean.applyOverrides(data, null, null, getClass().getClassLoader());
assertEquals(8080, data.getAttribute("port"));
- gbean.setAttribute("port", "${port + 1}");
+ gbean.setAttribute(portInfo, "${port + 1}", classLoader);
gbean.applyOverrides(data, null, null, getClass().getClassLoader());
assertEquals(8081, data.getAttribute("port"));
- gbean.setAttribute("port", "${port + portOffset}");
+ gbean.setAttribute(portInfo, "${port + portOffset}", classLoader);
gbean.applyOverrides(data, null, null, getClass().getClassLoader());
assertEquals(8081, data.getAttribute("port"));
- gbean.setAttribute("expression", "${if (java == null) 'null'; else 'non-null';}");
+ gbean.setAttribute(expressionInfo, "${if (java == null) 'null'; else 'non-null';}", classLoader);
gbean.applyOverrides(data, null, null, getClass().getClassLoader());
assertEquals("non-null", data.getAttribute("expression"));
- gbean.setAttribute("expression", "${if (java == null) { 'null'; } else { if (os == null) { 'java,null'; } else { 'java,non-null'; } } }");
+ gbean.setAttribute(expressionInfo, "${if (java == null) { 'null'; } else { if (os == null) { 'java,null'; } else { 'java,non-null'; } } }", classLoader);
gbean.applyOverrides(data, null, null, getClass().getClassLoader());
assertEquals("java,non-null", data.getAttribute("expression"));
}