Source Code Cross Referenced for SecureRealm.java in  » Science » Cougaar12_4 » org » cougaar » lib » web » tomcat » 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 » Science » Cougaar12_4 » org.cougaar.lib.web.tomcat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 Networks Associates Technology, Inc
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         *
026:         * CHANGE RECORD
027:         * - 
028:         */
029:        package org.cougaar.lib.web.tomcat;
030:
031:        import java.beans.PropertyChangeListener;
032:        import java.security.Principal;
033:        import java.security.cert.X509Certificate;
034:
035:        import org.apache.catalina.Container;
036:        import org.apache.catalina.Realm;
037:
038:        /**
039:         * A Realm extension for Tomcat 4.0 that will use
040:         * org.cougaar.core.security.crypto.ldap.KeyRingJNDIRealm if it
041:         * exists and the System property
042:         * <code>org.cougaar.lib.web.tomcat.enableAuth</code> 
043:         * is "true".
044:         * <p>
045:         * The <code>server.xml</code> should have within the &lt;Engine&gt; section:
046:         * <pre>
047:         *   &lt;Realm className="org.cougaar.lib.web.tomcat.SecureRealm" /&gt;
048:         * </pre>
049:         *
050:         *
051:         * @property org.cougaar.lib.web.tomcat.realm.class
052:         *   classname for realm.
053:         * @property org.cougaar.lib.web.tomcat.enableAuth 
054:         *   enable default realm if classname property is
055:         *   not specified.
056:         */
057:        public class SecureRealm implements  Realm {
058:
059:            private static final String PROP_ENABLE = "org.cougaar.lib.web.tomcat.enableAuth";
060:            private static final String PROP_CLASS = "org.cougaar.lib.web.tomcat.realm.class";
061:            private static final String DEFAULT_SECURE = "org.cougaar.core.security.crypto.ldap.KeyRingJNDIRealm";
062:
063:            private Realm _secureRealm = null;
064:            private Container _container = null;
065:
066:            /** 
067:             * Default constructor.
068:             */
069:            public SecureRealm() {
070:                String realmClass = System.getProperty(PROP_CLASS);
071:
072:                if (realmClass == null && Boolean.getBoolean(PROP_ENABLE)) {
073:                    realmClass = DEFAULT_SECURE;
074:                }
075:
076:                if (realmClass != null) {
077:                    try {
078:                        Class c = Class.forName(realmClass);
079:                        _secureRealm = (Realm) c.newInstance();
080:                    } catch (ClassNotFoundException e) {
081:                        System.err.println("Error: could not find class "
082:                                + realmClass);
083:                    } catch (ClassCastException e) {
084:                        System.err.println("Error: the class " + realmClass
085:                                + " is not a Realm");
086:                    } catch (Exception e) {
087:                        System.err.println("Error: could not load the class "
088:                                + realmClass);
089:                    }
090:                }
091:            }
092:
093:            /**
094:             * returns the KeyRingJNDIRealm if it is available.
095:             */
096:            public Realm getRealm() {
097:                return _secureRealm;
098:            }
099:
100:            /** 
101:             * Uses the KeyRingJNDIRealm's addPropertyChangeListener if available.
102:             */
103:            public void addPropertyChangeListener(
104:                    PropertyChangeListener listener) {
105:                if (_secureRealm != null) {
106:                    _secureRealm.addPropertyChangeListener(listener);
107:                }
108:            }
109:
110:            /**
111:             * Authenticates using the KeyRingJNDIRealm if available.
112:             */
113:            public Principal authenticate(String username, String credentials) {
114:                if (_secureRealm != null) {
115:                    return _secureRealm.authenticate(username, credentials);
116:                }
117:                return null;
118:            }
119:
120:            /**
121:             * Authenticates using the KeyRingJNDIRealm if available.
122:             */
123:            public Principal authenticate(String username, byte[] credentials) {
124:                if (_secureRealm != null) {
125:                    return _secureRealm.authenticate(username, credentials);
126:                }
127:                return null;
128:            }
129:
130:            /**
131:             * Authenticates using the KeyRingJNDIRealm if available.
132:             */
133:            public Principal authenticate(X509Certificate certs[]) {
134:                if (_secureRealm != null) {
135:                    return _secureRealm.authenticate(certs);
136:                }
137:                return null;
138:            }
139:
140:            /**
141:             * Authenticates using the KeyRingJNDIRealm if available.
142:             */
143:            public Principal authenticate(String username, String clientDigest,
144:                    String nOnce, String nc, String cnonce, String qop,
145:                    String realm, String md5a2) {
146:                if (_secureRealm != null) {
147:                    return _secureRealm.authenticate(username, clientDigest,
148:                            nOnce, nc, cnonce, qop, realm, md5a2);
149:                }
150:                return null;
151:            }
152:
153:            /**
154:             * Uses the KeyRingJNDIRealm getContainer() if available
155:             */
156:            public Container getContainer() {
157:                if (_secureRealm != null) {
158:                    return _secureRealm.getContainer();
159:                }
160:                return _container;
161:            }
162:
163:            /**
164:             * Uses the KeyRingJNDIRealm getInfo() if available. Otherwise it returns
165:             * "SecureRealm";
166:             */
167:            public String getInfo() {
168:                if (_secureRealm != null) {
169:                    return _secureRealm.getInfo();
170:                }
171:                return "SecureRealm";
172:            }
173:
174:            /**
175:             * Uses the KeyRingJNDIRealm hasRole() if available. Otherwise it returns
176:             * false always
177:             */
178:            public boolean hasRole(Principal user, String role) {
179:                if (_secureRealm != null) {
180:                    return _secureRealm.hasRole(user, role);
181:                }
182:                return false;
183:            }
184:
185:            /**
186:             * Uses the KeyRingJNDIRealm removePropertyChangeListener() if available.
187:             */
188:            public void removePropertyChangeListener(
189:                    PropertyChangeListener listener) {
190:                if (_secureRealm != null) {
191:                    _secureRealm.removePropertyChangeListener(listener);
192:                }
193:            }
194:
195:            /**
196:             * Uses the KeyRingJNDIRealm setContainer() if available. Otherwise it
197:             * sets the value to be returned by getContainer()
198:             */
199:            public void setContainer(Container container) {
200:                if (_secureRealm != null) {
201:                    _secureRealm.setContainer(container);
202:                }
203:                _container = container;
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.