Source Code Cross Referenced for CustomPermissionsURLClassLoader.java in  » Inversion-of-Control » PicoContainer » org » picocontainer » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Inversion of Control » PicoContainer » org.picocontainer.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*****************************************************************************
02:         * Copyright (C) PicoContainer Organization. All rights reserved.            *
03:         * ------------------------------------------------------------------------- *
04:         * The software in this package is published under the terms of the BSD      *
05:         * style license a copy of which has been included with this distribution in *
06:         * the LICENSE.txt file.                                                     *
07:         *                                                                           *
08:         *****************************************************************************/package org.picocontainer.security;
09:
10:        import java.net.URL;
11:        import java.net.URLClassLoader;
12:        import java.security.AccessController;
13:        import java.security.CodeSource;
14:        import java.security.PermissionCollection;
15:        import java.security.Permissions;
16:        import java.security.PrivilegedAction;
17:        import java.util.Map;
18:
19:        /**
20:         * CustomPermissionsURLClassLoader extends URLClassLoader, adding the abilty to programatically add permissions easily.
21:         * To be effective for permission management, it should be run in conjunction with a policy that restricts
22:         * some of the classloaders, but not all.
23:         * It's not ordinarily used by PicoContainer, but is here because PicoContainer is common
24:         * to most classloader trees.
25:         * 
26:         * @author Paul Hammant
27:         */
28:        public class CustomPermissionsURLClassLoader extends URLClassLoader {
29:            private final Map<URL, Permissions> permissionsMap;
30:
31:            public CustomPermissionsURLClassLoader(URL[] urls,
32:                    Map<URL, Permissions> permissionsMap, ClassLoader parent) {
33:                super (urls, parent);
34:                this .permissionsMap = permissionsMap;
35:            }
36:
37:            public Class<?> loadClass(String name)
38:                    throws ClassNotFoundException {
39:                try {
40:                    return super .loadClass(name);
41:                } catch (ClassNotFoundException e) {
42:                    throw decorateException(name, e);
43:                }
44:            }
45:
46:            protected Class<?> findClass(String name)
47:                    throws ClassNotFoundException {
48:                try {
49:                    return super .findClass(name);
50:                } catch (ClassNotFoundException e) {
51:                    throw decorateException(name, e);
52:                }
53:            }
54:
55:            private ClassNotFoundException decorateException(String name,
56:                    ClassNotFoundException e) {
57:                if (name.startsWith("class ")) {
58:                    return new ClassNotFoundException(
59:                            "Class '"
60:                                    + name
61:                                    + "' is not a classInstance.getName(). "
62:                                    + "It's a classInstance.toString(). The clue is that it starts with 'class ', no classname contains a space.");
63:                }
64:                ClassLoader classLoader = this ;
65:                StringBuffer sb = new StringBuffer("'").append(name).append(
66:                        "' classloader stack [");
67:                while (classLoader != null) {
68:                    sb.append(classLoader.toString()).append("\n");
69:                    final ClassLoader cl = classLoader;
70:                    classLoader = (ClassLoader) AccessController
71:                            .doPrivileged(new PrivilegedAction() {
72:                                public Object run() {
73:                                    return cl.getParent();
74:                                }
75:                            });
76:
77:                }
78:                return new ClassNotFoundException(sb.append("]").toString(), e);
79:            }
80:
81:            public String toString() {
82:                String result = CustomPermissionsURLClassLoader.class.getName()
83:                        + " " + System.identityHashCode(this ) + ":";
84:                URL[] urls = getURLs();
85:                for (URL url : urls) {
86:                    result += "\n\t" + url.toString();
87:                }
88:
89:                return result;
90:            }
91:
92:            public PermissionCollection getPermissions(CodeSource codeSource) {
93:                return (Permissions) permissionsMap.get(codeSource
94:                        .getLocation());
95:            }
96:
97:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.