TOMEE-1790, allow primitive arrays
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/72927b15 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/72927b15 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/72927b15 Branch: refs/heads/tomee-1.7.x Commit: 72927b15624c152b6c51675b396cbf57718a2f31 Parents: a1d3760 Author: Jonathan Gallimore <[email protected]> Authored: Fri May 13 16:03:44 2016 +0100 Committer: Jonathan Gallimore <[email protected]> Committed: Fri May 13 16:03:44 2016 +0100 ---------------------------------------------------------------------- .../openejb/client/EjbObjectInputStream.java | 8 ++++ .../client/BlacklistClassResolverTest.java | 39 ++++++++++++++++++++ 2 files changed, 47 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/72927b15/server/openejb-client/src/main/java/org/apache/openejb/client/EjbObjectInputStream.java ---------------------------------------------------------------------- diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/EjbObjectInputStream.java b/server/openejb-client/src/main/java/org/apache/openejb/client/EjbObjectInputStream.java index f20e375..dab036f 100644 --- a/server/openejb-client/src/main/java/org/apache/openejb/client/EjbObjectInputStream.java +++ b/server/openejb-client/src/main/java/org/apache/openejb/client/EjbObjectInputStream.java @@ -22,6 +22,7 @@ import java.io.ObjectInputStream; import java.io.ObjectStreamClass; import java.lang.reflect.Proxy; import java.util.concurrent.atomic.AtomicReference; +import java.util.regex.Pattern; /** * @version $Rev$ $Date$ @@ -98,6 +99,8 @@ public class EjbObjectInputStream extends ObjectInputStream { private final String[] blacklist; private final String[] whitelist; + public static final Pattern PRIMITIVE_ARRAY = Pattern.compile("^\\[+[BCDFIJSVZ]$"); + protected BlacklistClassResolver() { this(toArray(System.getProperty( "tomee.serialization.class.blacklist", @@ -111,6 +114,11 @@ public class EjbObjectInputStream extends ObjectInputStream { } protected boolean isBlacklisted(final String name) { + // allow primitive arrays + if (PRIMITIVE_ARRAY.matcher(name).matches()) { + return false; + } + if (name != null && name.startsWith("[L") && name.endsWith(";")) { return isBlacklisted(name.substring(2, name.length() - 1)); } http://git-wip-us.apache.org/repos/asf/tomee/blob/72927b15/server/openejb-client/src/test/java/org/apache/openejb/client/BlacklistClassResolverTest.java ---------------------------------------------------------------------- diff --git a/server/openejb-client/src/test/java/org/apache/openejb/client/BlacklistClassResolverTest.java b/server/openejb-client/src/test/java/org/apache/openejb/client/BlacklistClassResolverTest.java new file mode 100644 index 0000000..c56fc2f --- /dev/null +++ b/server/openejb-client/src/test/java/org/apache/openejb/client/BlacklistClassResolverTest.java @@ -0,0 +1,39 @@ +/** + * 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.openejb.client; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; +public class BlacklistClassResolverTest { + @Test + public void isBlacklisted() throws Exception { + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[B")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[C")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[D")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[F")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[I")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[J")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[S")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[V")); + Assert.assertFalse(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[[Z")); + Assert.assertTrue(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("[Ljava.lang.Process;")); + Assert.assertTrue(new EjbObjectInputStream.BlacklistClassResolver().isBlacklisted("java.lang.Process;")); + } + +}
