Source Code Cross Referenced for RolesHandler.java in  » Web-Server » Brazil » sunlabs » brazil » handler » 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 » Web Server » Brazil » sunlabs.brazil.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * RolesHandler.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1998-2000 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): cstevens, suhler.
022:         *
023:         * Version:  1.11
024:         * Created by suhler on 98/09/30
025:         * Last modified by suhler on 00/07/07 17:01:22
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import java.io.FileInputStream;
031:        import java.io.IOException;
032:        import java.util.Enumeration;
033:        import java.util.Hashtable;
034:        import java.util.Properties;
035:        import sunlabs.brazil.server.Handler;
036:        import sunlabs.brazil.server.Request;
037:        import sunlabs.brazil.server.Server;
038:
039:        /**
040:         * Handler for associating roles with an id.  This is a placeholder
041:         * until the SunEconomy gets integrated in.  It looks for an "id" in the 
042:         * request, looks it up in a property file, then add the value of the
043:         * id into the request.  It may be used in conjuntion with
044:         * {@link AclSwitchHandler} to provide role based web access.
045:         *
046:         * @author		Stephen Uhler
047:         * @version		 @(#) RolesHandler.java 1.11 00/07/07 17:01:22
048:         */
049:
050:        public class RolesHandler implements  Handler {
051:            Properties map; // The authorization mapping table
052:            String propsPrefix; // My prefix in the global properties file
053:            String urlPrefix; // The prefix to look for to map
054:            String idKey; // The property name for the token id
055:            String roleKey; // The property name for the roles
056:            boolean check = true; // only put results in request, don't return
057:
058:            /**
059:             * Handler configuration property <b>SessionID</b>.
060:             * The request property name to find the id string.
061:             * Defaults to id.
062:             */
063:
064:            public static final String ID_KEY = "SessionID"; // property key for token id
065:
066:            /**
067:             * Handler configuration property <b>roleName</b>.
068:             * The request property name to place the roles into.
069:             * Defaults to roles.
070:             */
071:
072:            public static final String ROLE_KEY = "roleName"; // property key for token roles
073:
074:            /**
075:             * Handler configuration property <b>mapFile</b>.
076:             * The path to the java properties file containing the id
077:             * to roles mapping.  The roles are a whitespace delimited list
078:             * of ascii role names.
079:             */
080:
081:            public static final String MAP = "mapFile"; // properties file
082:
083:            /**
084:             * Handler configuration property <b>prefix</b>.
085:             * Only URL's that begin with this string are considered by this handler.
086:             * The default is (/).
087:             */
088:
089:            static final String PREFIX = "prefix"; // url prefix
090:
091:            /**
092:             * Handler configuration property <b>check</b>.
093:             * If true, the results are out into the request object.
094:             * Otherwise, they are returned in a text/plain java properties
095:             * formatted document, which can be used with the
096:             * @see RemoteStsHandler.
097:             */
098:
099:            static final String CHECK = "check"; // how results are returned
100:
101:            public boolean init(Server server, String prefix) {
102:                propsPrefix = prefix;
103:                urlPrefix = server.props.getProperty(propsPrefix + PREFIX, "/");
104:                String mapFile = server.props
105:                        .getProperty(propsPrefix + MAP, "");
106:                map = new Properties();
107:                try {
108:                    FileInputStream in = new FileInputStream(mapFile);
109:                    map.load(in);
110:                    in.close();
111:                } catch (Exception e) {
112:                    server.log(Server.LOG_ERROR, prefix, propsPrefix + MAP
113:                            + ": (" + mapFile + ") " + e.toString());
114:                    return false;
115:                }
116:                idKey = server.props.getProperty(propsPrefix + ID_KEY, "id");
117:                roleKey = server.props.getProperty(propsPrefix + ROLE_KEY,
118:                        "roles");
119:                check = server.props.getProperty(propsPrefix + CHECK, "y")
120:                        .startsWith("y");
121:                return true;
122:            }
123:
124:            /** 
125:             * Dispatch and handle the request.
126:             * This version looks at the request for the id, looks it up in the
127:             * table, and adds the value, if available
128:             */
129:
130:            public boolean respond(Request request) throws IOException {
131:                if (!request.url.startsWith(urlPrefix)) {
132:                    return false;
133:                }
134:                String id = (String) request.props.get(idKey);
135:                // System.out.println("ids: " + map);
136:                // System.out.println("props: " + request.props);
137:                if (id != null && map.containsKey(id)) {
138:                    String value = (String) map.get(id);
139:                    request.log(Server.LOG_DIAGNOSTIC, "Mapping: " + id + "->"
140:                            + value);
141:                    request.props.put(roleKey, value);
142:                }
143:                if (!check) {
144:                    StringBuffer result = new StringBuffer("");
145:                    Enumeration keys = request.props.keys();
146:                    while (keys.hasMoreElements()) {
147:                        String key = (String) keys.nextElement();
148:                        result
149:                                .append(key + "=" + request.props.get(key)
150:                                        + "\n");
151:                    }
152:                    request.sendResponse(result.toString(), "text/plain");
153:                    return true;
154:                } else {
155:                    return false;
156:                }
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.