[jboss-svn-commits] JBoss Common SVN: r2850 - common-core/trunk/src/main/java/org/jboss/util/collection.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 23 13:28:13 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-05-23 13:28:13 -0400 (Fri, 23 May 2008)
New Revision: 2850
Added:
common-core/trunk/src/main/java/org/jboss/util/collection/SecurityActions.java
Modified:
common-core/trunk/src/main/java/org/jboss/util/collection/WeakTypeCache.java
Log:
[JBCOMMON-54] Add privileged blocks
Added: common-core/trunk/src/main/java/org/jboss/util/collection/SecurityActions.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/SecurityActions.java (rev 0)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/SecurityActions.java 2008-05-23 17:28:13 UTC (rev 2850)
@@ -0,0 +1,70 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.util.collection;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+
+ interface GetClassLoaderAction
+ {
+ ClassLoader getClassLoader(Class<?> clazz);
+
+ GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+ public ClassLoader getClassLoader(Class<?> clazz)
+ {
+ return clazz.getClassLoader();
+ }};
+
+ GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+ public ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }});
+ }};
+ }
+
+ static ClassLoader getClassLoader(Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+ }
+ else
+ {
+ return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+ }
+ }
+}
Modified: common-core/trunk/src/main/java/org/jboss/util/collection/WeakTypeCache.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/collection/WeakTypeCache.java 2008-05-22 16:56:40 UTC (rev 2849)
+++ common-core/trunk/src/main/java/org/jboss/util/collection/WeakTypeCache.java 2008-05-23 17:28:13 UTC (rev 2850)
@@ -198,7 +198,8 @@
protected T peek(ParameterizedType type)
{
Class<?> rawType = (Class<?>) type.getRawType();
- Map<String, T> classLoaderCache = getClassLoaderCache(rawType.getClassLoader());
+ ClassLoader cl = SecurityActions.getClassLoader(rawType);
+ Map<String, T> classLoaderCache = getClassLoaderCache(cl);
synchronized (classLoaderCache)
{
@@ -215,7 +216,8 @@
protected void put(ParameterizedType type, T result)
{
Class<?> rawType = (Class<?>) type.getRawType();
- Map<String, T> classLoaderCache = getClassLoaderCache(rawType.getClassLoader());
+ ClassLoader cl = SecurityActions.getClassLoader(rawType);
+ Map<String, T> classLoaderCache = getClassLoaderCache(cl);
synchronized (classLoaderCache)
{
@@ -257,7 +259,8 @@
*/
protected T peek(Class<?> clazz)
{
- Map<String, T> classLoaderCache = getClassLoaderCache(clazz.getClassLoader());
+ ClassLoader cl = SecurityActions.getClassLoader(clazz);
+ Map<String, T> classLoaderCache = getClassLoaderCache(cl);
synchronized (classLoaderCache)
{
@@ -273,7 +276,8 @@
*/
protected void put(Class<?> clazz, T result)
{
- Map<String, T> classLoaderCache = getClassLoaderCache(clazz.getClassLoader());
+ ClassLoader cl = SecurityActions.getClassLoader(clazz);
+ Map<String, T> classLoaderCache = getClassLoaderCache(cl);
synchronized (classLoaderCache)
{
More information about the jboss-svn-commits
mailing list