Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7537088DE for ; Tue, 13 Sep 2011 06:04:22 +0000 (UTC) Received: (qmail 668 invoked by uid 500); 13 Sep 2011 06:04:19 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 99684 invoked by uid 500); 13 Sep 2011 06:03:58 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 97446 invoked by uid 99); 13 Sep 2011 06:03:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2011 06:03:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2011 06:03:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BEB9223888FD; Tue, 13 Sep 2011 06:03:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1170055 - /geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/propertyeditor/MapEditor.java Date: Tue, 13 Sep 2011 06:03:33 -0000 To: scm@geronimo.apache.org From: genspring@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110913060333.BEB9223888FD@eris.apache.org> Author: genspring Date: Tue Sep 13 06:03:33 2011 New Revision: 1170055 URL: http://svn.apache.org/viewvc?rev=1170055&view=rev Log: GERONIMO-5705 Track: Encryption logic for connectionPassword attribute in ldap realm, patch from Yi Xiao. Modified: geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/propertyeditor/MapEditor.java Modified: geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/propertyeditor/MapEditor.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/propertyeditor/MapEditor.java?rev=1170055&r1=1170054&r2=1170055&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/propertyeditor/MapEditor.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-common/src/main/java/org/apache/geronimo/common/propertyeditor/MapEditor.java Tue Sep 13 06:03:33 2011 @@ -23,58 +23,77 @@ import java.util.Iterator; import java.util.Properties; import java.util.Map; +import org.apache.geronimo.crypto.EncryptionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A property editor for {@link java.util.Map}. - * + * * @version $Rev$ $Date$ */ -public class MapEditor - extends TextPropertyEditorSupport -{ +public class MapEditor extends TextPropertyEditorSupport { private static final Logger log = LoggerFactory.getLogger(MapEditor.class); - + /** - * - * @throws PropertyEditorException An IOException occured. + * + * @throws PropertyEditorException + * An IOException occured. */ + @SuppressWarnings("rawtypes") public void setAsText(String text) { try { - ByteArrayInputStream is = new ByteArrayInputStream(text == null? new byte[0]: text.getBytes()); + ByteArrayInputStream is = new ByteArrayInputStream(text == null ? new byte[0] : text.getBytes()); Properties p = new Properties(); p.load(is); - - setValue((Map)p); + Iterator it = p.keySet().iterator(); + while (it.hasNext()) { + String key = it.next().toString(); + if (key.toLowerCase().endsWith("password")) { + String encryptedValue = (String) p.get(key); + String decryptedValue = (String) EncryptionManager.decrypt(encryptedValue); + p.put(key, decryptedValue); + } + } + setValue((Map) p); } catch (IOException e) { throw new PropertyEditorException(e.getMessage(), e); } } + @SuppressWarnings({ "rawtypes", "unchecked" }) public String getAsText() { Map map = (Map) getValue(); if (!(map instanceof Properties)) { Properties p = new Properties(); - if(map != null) { - if(!map.containsKey(null) && !map.containsValue(null)) { + if (map != null) { + if (!map.containsKey(null) && !map.containsValue(null)) { p.putAll(map); } else { - // Map contains null keys or values. Replace null with empty string. + // Map contains null keys or values. Replace null with empty string. log.warn("Map contains null keys or values. Replacing null values with empty string."); - for(Iterator itr = map.entrySet().iterator(); itr.hasNext(); ) { + for (Iterator itr = map.entrySet().iterator(); itr.hasNext();) { Map.Entry entry = (Map.Entry) itr.next(); Object key = entry.getKey(); Object value = entry.getValue(); - if(key == null) { + if (key == null) { key = ""; } - if(value == null) { + if (value == null) { value = ""; } p.put(key, value); } } + Iterator it = p.keySet().iterator(); + while (it.hasNext()) { + String key = it.next().toString(); + if (key.toLowerCase().endsWith("password")) { + String value = (String) p.get(key); + String encryptedValue = EncryptionManager.encrypt(value); + p.put(key, encryptedValue); + } + } map = p; } }