Source Code Cross Referenced for JResources.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: JResources.java 4840 2004-05-28 14:02:57Z sauthieg $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.security;
025:
026:        import java.util.Enumeration;
027:        import java.util.Hashtable;
028:
029:        import org.objectweb.jonas.security.realm.factory.JResource;
030:        import org.objectweb.jonas.security.realm.factory.JResourceDS;
031:        import org.objectweb.jonas.security.realm.factory.JResourceLDAP;
032:        import org.objectweb.jonas.security.realm.factory.JResourceMemory;
033:
034:        /**
035:         *
036:         *
037:         * @author Guillaume Sauthier
038:         */
039:        public class JResources {
040:
041:            /**
042:             * List of Resource
043:             */
044:            private Hashtable jResources = null;
045:
046:            /**
047:             * SecurityService
048:             */
049:            private SecurityService service = null;
050:
051:            /**
052:             * Xml Header
053:             */
054:            public static final String HEADER_XML = "<?xml version='1.0' encoding='utf-8'?>\n"
055:                    + "<!DOCTYPE jonas-realm PUBLIC\n"
056:                    + "          \"-//ObjectWeb//DTD JOnAS realm 1.0//EN\"\n"
057:                    + "          \"http://www.objectweb.org/jonas/dtds/jonas-realm_1_0.dtd\">\n";
058:
059:            /**
060:             * Create a JResoures list attached to a given SecurityService.
061:             * @param s the parent SecurityService
062:             */
063:            public JResources(SecurityService s) {
064:                jResources = new Hashtable();
065:                service = s;
066:            }
067:
068:            /**
069:             * Add the Resource (memory, ldap, datasource,...)
070:             * @param jResource  an instance of JResource or subclasses (JResourceMemory, JResourceDS,...)
071:             * @throws Exception if the resource name already exists
072:             */
073:            public void addJResource(JResource jResource) throws Exception {
074:                if (jResources.get(jResource.getName()) != null) {
075:                    throw new Exception("The resource name "
076:                            + jResource.getName() + " already exists !");
077:                }
078:
079:                jResources.put(jResource.getName(), jResource);
080:
081:                service.bindResource(jResource.getName(), jResource);
082:            }
083:
084:            /**
085:             * Removes the named JResource from the JResource list.
086:             * @param resourceName JResource name to be removed
087:             * @return the removed JResource
088:             * @throws Exception when JResource is not found with given name.
089:             */
090:            public JResource remove(String resourceName) throws Exception {
091:                JResource jResource = (JResource) jResources.get(resourceName);
092:                if (jResource == null) {
093:                    throw new Exception("The resource name " + resourceName
094:                            + " doesn't exist !");
095:                }
096:                jResources.remove(resourceName);
097:                return jResource;
098:            }
099:
100:            /**
101:             * @param name the name of the JResource to get.
102:             * @return Returns the named JResource
103:             */
104:            public JResource getJResource(String name) {
105:                return (JResource) jResources.get(name);
106:            }
107:
108:            /**
109:             * @return Returns the JResources Enumeration
110:             */
111:            public Enumeration getResources() {
112:                return jResources.elements();
113:            }
114:
115:            /**
116:             * String representation of the JOnAS realm
117:             * @return the xml representation of the JOnAS realm
118:             */
119:            public String toXML() {
120:
121:                // Required values
122:
123:                StringBuffer xml = new StringBuffer(HEADER_XML);
124:                xml.append("<!--\n");
125:                xml
126:                        .append(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
127:                xml
128:                        .append(" - Define a jonas-realm.xml file for JOnAS realms\n");
129:                xml
130:                        .append(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
131:                xml.append(" -->\n");
132:
133:                xml.append("<jonas-realm>\n");
134:
135:                // Memory realms
136:                xml.append("  <!--\n");
137:                xml.append("       -=  MEMORY REALM =-\n");
138:                xml.append("       Define the users, groups and roles\n");
139:                xml.append("  -->\n");
140:                xml.append("  <jonas-memoryrealm>\n");
141:                for (Enumeration e = jResources.elements(); e.hasMoreElements();) {
142:                    Object o = e.nextElement();
143:                    if (o instanceof  JResourceMemory) {
144:                        xml.append(o.toString());
145:                        xml.append("\n");
146:                    }
147:                }
148:                xml.append("  </jonas-memoryrealm>\n");
149:
150:                // Datasource realms
151:                xml.append("  <!--\n");
152:                xml.append("       -=  DATASOURCE REALM =-\n");
153:                xml
154:                        .append("       Define the configuration to use datas from a datasource\n");
155:                xml.append("  -->\n");
156:                xml.append("  <jonas-dsrealm>\n");
157:                for (Enumeration e = jResources.elements(); e.hasMoreElements();) {
158:                    Object o = e.nextElement();
159:                    if (o instanceof  JResourceDS) {
160:                        xml.append(o.toString());
161:                        xml.append("\n");
162:                    }
163:                }
164:                xml.append("  </jonas-dsrealm>\n");
165:
166:                // Ldap realms
167:                xml.append("  <!--\n");
168:                xml.append("       -=  LDAP REALM =-\n");
169:                xml
170:                        .append("       Define the configuration to use datas from an ldap server\n");
171:                xml.append("  -->\n");
172:                xml.append("  <jonas-ldaprealm>\n");
173:                for (Enumeration e = jResources.elements(); e.hasMoreElements();) {
174:                    Object o = e.nextElement();
175:                    if (o instanceof  JResourceLDAP) {
176:                        xml.append(o.toString());
177:                        xml.append("\n");
178:                    }
179:                }
180:                xml.append("  </jonas-ldaprealm>\n");
181:
182:                xml.append("</jonas-realm>\n");
183:
184:                return xml.toString();
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.