KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > profileservice > support > SecurityActions


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.profileservice.support;
23
24 import java.net.URL JavaDoc;
25 import java.net.URLClassLoader JavaDoc;
26 import java.security.PrivilegedAction JavaDoc;
27 import java.security.AccessController JavaDoc;
28
29 /**
30  * Package priviledged actions
31  *
32  * @author Scott.Stark@jboss.org
33  * @version $Revision$
34  */

35 class SecurityActions
36 {
37    interface ClassLoaderActions
38    {
39       ClassLoaderActions PRIVILEGED = new ClassLoaderActions()
40       {
41          public URLClassLoader JavaDoc newClassLoader(final URL JavaDoc[] urls)
42          {
43             PrivilegedAction JavaDoc action = new PrivilegedAction JavaDoc()
44             {
45                public Object JavaDoc run()
46                {
47                   return new URLClassLoader JavaDoc(urls);
48                }
49             };
50             return (URLClassLoader JavaDoc) AccessController.doPrivileged(action);
51          }
52       };
53
54       ClassLoaderActions NON_PRIVILEGED = new ClassLoaderActions()
55       {
56          public URLClassLoader JavaDoc newClassLoader(URL JavaDoc[] urls)
57          {
58             return new URLClassLoader JavaDoc(urls);
59          }
60       };
61
62       URLClassLoader JavaDoc newClassLoader(URL JavaDoc[] urls);
63    }
64
65    static URLClassLoader JavaDoc newClassLoader(URL JavaDoc[] urls)
66    {
67       if(System.getSecurityManager() == null)
68       {
69          return ClassLoaderActions.NON_PRIVILEGED.newClassLoader(urls);
70       }
71       else
72       {
73          return ClassLoaderActions.PRIVILEGED.newClassLoader(urls);
74       }
75    }
76
77    static String JavaDoc getSystemProperty(final String JavaDoc name)
78    {
79       PrivilegedAction JavaDoc action = new PrivilegedAction JavaDoc()
80       {
81          public Object JavaDoc run()
82          {
83             return System.getProperty(name);
84          }
85       };
86       return (String JavaDoc) AccessController.doPrivileged(action);
87    }
88 }
89
Popular Tags