Source Code Cross Referenced for JAASPnutsImpl.java in  » Scripting » Pnuts » pnuts » 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 » Scripting » Pnuts » pnuts.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)JAASPnutsImpl.java 1.2 04/12/06
003:         *
004:         * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
005:         *
006:         * See the file "LICENSE.txt" for information on usage and redistribution
007:         * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
008:         */
009:        package pnuts.security;
010:
011:        import java.security.AccessController;
012:        import java.security.CodeSource;
013:        import java.security.PermissionCollection;
014:        import java.security.Permissions;
015:        import java.security.Policy;
016:        import java.security.Principal;
017:        import java.security.PrivilegedAction;
018:        import java.security.ProtectionDomain;
019:        import java.util.Set;
020:
021:        import javax.security.auth.Subject;
022:
023:        import pnuts.lang.Implementation;
024:        import pnuts.lang.PnutsImpl;
025:
026:        /**
027:         * A SecurePnutsImpl subclass that executes scripts with permissions constructed from
028:         * codesource-based policy and subject-based policy.
029:         *
030:         * <pre>e.g.
031:         *  context.setImplementation(new JAASPnutsImpl(context.Implementation(), codesource, subject))
032:         * </pre>
033:         */
034:        public class JAASPnutsImpl extends SecurePnutsImpl {
035:
036:            private Subject subject;
037:
038:            /**
039:             * A Constructor
040:             *
041:             * @param impl a PnutsImpl object
042:             *
043:             * @deprecated replaced by JAASPnutsImpl(Implementation)
044:             */
045:            public JAASPnutsImpl(PnutsImpl impl) {
046:                this (impl, null);
047:            }
048:
049:            /**
050:             * A Constructor
051:             *
052:             * @param impl a Implementation object
053:             */
054:            public JAASPnutsImpl(Implementation impl) {
055:                this (impl, null);
056:            }
057:
058:            /**
059:             * A Constructor
060:             *
061:             * @param impl the base implementation
062:             * @param codeSource a CodeSource object which indicates the source of the expression
063:             *		execute by eval(String, Context).
064:             *
065:             * @deprecated replaced byte JAASPnutsImpl(Implementation, CodeSource)
066:             */
067:            public JAASPnutsImpl(PnutsImpl impl, CodeSource codeSource) {
068:                this (impl, codeSource, null);
069:            }
070:
071:            /**
072:             * A Constructor
073:             *
074:             * @param impl the base implementation
075:             * @param codeSource a CodeSource object which indicates the source of the expression
076:             *		execute by eval(String, Context).
077:             */
078:            public JAASPnutsImpl(Implementation impl, CodeSource codeSource) {
079:                this (impl, codeSource, null);
080:            }
081:
082:            /**
083:             * A Constructor
084:             *
085:             * @param impl the base implementation
086:             * @param codeSource a CodeSource object which indicates the source of the expression
087:             *		execute by eval(String, Context).
088:             * @param subject a Subject
089:             *
090:             * @deprecated replaced by JAASPnutsImpl(Implementation, CodeSource, Subject)
091:             */
092:            public JAASPnutsImpl(PnutsImpl impl, CodeSource codeSource,
093:                    Subject subject) {
094:                super (impl, codeSource);
095:                this .subject = subject;
096:            }
097:
098:            /**
099:             * A Constructor
100:             *
101:             * @param impl the base implementation
102:             * @param codeSource a CodeSource object which indicates the source of the expression
103:             *		execute by eval(String, Context).
104:             * @param subject a Subject
105:             */
106:            public JAASPnutsImpl(Implementation impl, CodeSource codeSource,
107:                    Subject subject) {
108:                super (impl, codeSource);
109:                this .subject = subject;
110:            }
111:
112:            protected PermissionCollection getPermissions(
113:                    final CodeSource codesource) {
114:                if (subject != null) {
115:                    PermissionCollection perms = (PermissionCollection) AccessController
116:                            .doPrivileged(new PrivilegedAction() {
117:                                public Object run() {
118:                                    Policy policy = Policy.getPolicy();
119:                                    if (policy != null) {
120:                                        Set s = subject.getPrincipals();
121:                                        Principal[] principals = new Principal[s
122:                                                .size()];
123:                                        s.toArray(principals);
124:                                        return policy
125:                                                .getPermissions(new ProtectionDomain(
126:                                                        codesource, null, null,
127:                                                        principals));
128:                                    } else {
129:                                        return null;
130:                                    }
131:                                }
132:                            });
133:                    if (perms == null) {
134:                        perms = new Permissions();
135:                    }
136:                    return perms;
137:                } else {
138:                    return super .getPermissions(codesource);
139:                }
140:            }
141:
142:            public String toString() {
143:                return getClass().getName() + "[" + getBaseImpl() + ", "
144:                        + getCodeSource() + "]";
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.