Source Code Cross Referenced for SecurityMetadata.java in  » EJB-Server-JBoss-4.2.1 » messaging » org » jboss » mq » 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 » EJB Server JBoss 4.2.1 » messaging » org.jboss.mq.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.mq.security;
023:
024:        import java.util.Set;
025:        import java.util.HashSet;
026:        import java.util.HashMap;
027:        import java.io.StringReader;
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:        import javax.xml.parsers.DocumentBuilder;
030:
031:        import org.w3c.dom.Document;
032:        import org.w3c.dom.Element;
033:        import org.w3c.dom.Attr;
034:        import org.w3c.dom.NodeList;
035:
036:        import org.xml.sax.InputSource;
037:        import org.xml.sax.SAXException;
038:
039:        import org.jboss.security.SimplePrincipal;
040:        import org.jboss.logging.Logger;
041:
042:        /**
043:         * SecurityMetadata.java
044:         *
045:         *
046:         * Created: Tue Feb 26 15:02:29 2002
047:         *
048:         * @author Peter
049:         * @version
050:         */
051:
052:        public class SecurityMetadata {
053:            static Role DEFAULT_ROLE = new Role("guest", true, true, true);
054:
055:            static class Role {
056:                String name;
057:                boolean read = false;
058:                boolean write = false;
059:                boolean create = false;
060:
061:                public Role(String name, boolean read, boolean write,
062:                        boolean create) {
063:                    this .name = name;
064:                    this .read = read;
065:                    this .write = write;
066:                    this .create = create;
067:                }
068:
069:                public String toString() {
070:                    return "Role {name=" + name + ";read=" + read + ";write="
071:                            + write + ";create=" + create + "}";
072:                }
073:
074:            }
075:
076:            HashMap roles = new HashMap();
077:            HashSet read = new HashSet();
078:            HashSet write = new HashSet();
079:            HashSet create = new HashSet();
080:            static Logger log = Logger.getLogger(SecurityMetadata.class);
081:
082:            public SecurityMetadata() {
083:                addRole(DEFAULT_ROLE);
084:            }
085:
086:            /**
087:             * Create with given xml @see configure.
088:             *
089:             * If the configure script is null, a default role named guest will be
090:             * created with read and write access, but no create access.
091:             */
092:            public SecurityMetadata(String conf) throws Exception {
093:                configure(conf);
094:            }
095:
096:            public SecurityMetadata(Element conf) throws Exception {
097:                configure(conf);
098:            }
099:
100:            /**
101:             * Configure with an xml string.
102:             *
103:             * The format of the string is:
104:             * <security>
105:             *  <role name="nameOfRole" read="true" write="true" create="false"/>
106:             * </security>
107:             *
108:             * There may be one or more role elements.
109:             */
110:            public void configure(String conf) throws Exception {
111:                Element sec = null;
112:                if (conf != null) {
113:                    DocumentBuilderFactory factory = DocumentBuilderFactory
114:                            .newInstance();
115:                    DocumentBuilder parser = factory.newDocumentBuilder();
116:                    Document doc = parser.parse(new InputSource(
117:                            new StringReader(conf)));
118:                    sec = doc.getDocumentElement();
119:
120:                }
121:                configure(sec);
122:            }
123:
124:            public void configure(Element sec) throws Exception {
125:
126:                if (sec == null) {
127:                    addRole(DEFAULT_ROLE);
128:                } else {
129:
130:                    if (!sec.getTagName().equals("security"))
131:                        throw new SAXException(
132:                                "Configuration document not valid: root element must be security, not "
133:                                        + sec.getTagName());
134:
135:                    // Parse 
136:                    NodeList list = sec.getElementsByTagName("role");
137:                    int l = list.getLength();
138:                    for (int i = 0; i < l; i++) {
139:                        Element role = (Element) list.item(i);
140:                        Attr na = role.getAttributeNode("name");
141:                        if (na == null)
142:                            throw new SAXException(
143:                                    "There must exist a name attribute of role");
144:                        String n = na.getValue();
145:                        boolean r = role.getAttributeNode("read") != null ? Boolean
146:                                .valueOf(
147:                                        role.getAttributeNode("read")
148:                                                .getValue()).booleanValue()
149:                                : false;
150:                        boolean w = role.getAttributeNode("write") != null ? Boolean
151:                                .valueOf(
152:                                        role.getAttributeNode("write")
153:                                                .getValue()).booleanValue()
154:                                : false;
155:                        boolean c = role.getAttributeNode("create") != null ? Boolean
156:                                .valueOf(
157:                                        role.getAttributeNode("create")
158:                                                .getValue()).booleanValue()
159:                                : false;
160:                        addRole(n, r, w, c);
161:
162:                    }
163:                }
164:            }
165:
166:            public void addRole(String name, boolean read, boolean write,
167:                    boolean create) {
168:                Role r = new Role(name, read, write, create);
169:                addRole(r);
170:            }
171:
172:            public void addRole(Role r) {
173:                if (log.isTraceEnabled())
174:                    log.trace("Adding role: " + r.toString());
175:
176:                roles.put(r.name, r);
177:                SimplePrincipal p = new SimplePrincipal(r.name);
178:                if (r.read == true)
179:                    read.add(p);
180:                if (r.write == true)
181:                    write.add(p);
182:                if (r.create == true)
183:                    create.add(p);
184:            }
185:
186:            public Set getReadPrincipals() {
187:                return read;
188:            }
189:
190:            public Set getWritePrincipals() {
191:                return write;
192:            }
193:
194:            public Set getCreatePrincipals() {
195:                return create;
196:            }
197:        } // SecurityMetadata
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.