Source Code Cross Referenced for SupplyHandler.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:         * SupplyHandler.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.8
024:         * Created by suhler on 98/09/14
025:         * Last modified by suhler on 00/12/11 13:27:02
026:         */
027:
028:        package sunlabs.brazil.handler;
029:
030:        import java.io.FileInputStream;
031:        import java.util.Properties;
032:        import java.util.StringTokenizer;
033:        import sunlabs.brazil.server.Handler;
034:        import sunlabs.brazil.server.Request;
035:        import sunlabs.brazil.server.Server;
036:
037:        /**
038:         * Sample Handler for dispatching different users to different spots
039:         * This is a re-implementation of the supplier.net content server
040:         * using the new server apis (e.g. its not used for anything anymore).
041:         * This handler was originally designed to be a "virtual web site", where
042:         * credentials are passed in from an upstream proxy.  Those credentials are
043:         * used to provide different views based on the particular credentials supplied.
044:         *
045:         * The following configuration properties are used:
046:         * <dl class=props>
047:         *  <dt>mapFile	<dd> properties file
048:         *  <dt>prefix	<dd> url prefix
049:         *  <dt>default	<dd> default map
050:         *  <dt>header  <dd> http header (authentication)
051:         *  <dt>realm	<dd> The authentication realm (basic)
052:         * </dl>
053:         *
054:         * @author		Stephen Uhler
055:         * @version		1.8, 00/12/11
056:         */
057:
058:        public class SupplyHandler implements  Handler {
059:            private Properties map; // The authorization mapping table
060:            private String propsPrefix; // My prefix in the global properties file
061:            private String urlPrefix; // The prefix to look for to map
062:            private String authHeader; // header containing auth info
063:            private String realm; // The authentication realm
064:            private static final String MAP = "mapFile"; // properties file
065:            private static final String PREFIX = "prefix"; // url prefix
066:            private static final String DEFAULT = "default"; // default map
067:            private static final String HEADER = "header"; // http header
068:            private static final String REALM = "realm"; // realm to look for
069:
070:            public boolean init(Server server, String prefix) {
071:                propsPrefix = prefix;
072:                authHeader = server.props.getProperty(propsPrefix + HEADER,
073:                        "authorization");
074:                realm = server.props.getProperty(propsPrefix + REALM, "basic");
075:                urlPrefix = server.props.getProperty(propsPrefix + PREFIX, "");
076:                if (urlPrefix.equals("")) {
077:                    server.log(Server.LOG_WARNING, prefix,
078:                            "handler can't find " + PREFIX);
079:                    return false;
080:                }
081:                if (!urlPrefix.endsWith("/")) {
082:                    urlPrefix += "/";
083:                }
084:                String mapFile = server.props
085:                        .getProperty(propsPrefix + MAP, "");
086:                try {
087:                    FileInputStream in = new FileInputStream(mapFile);
088:                    map = new Properties();
089:                    map.load(in);
090:                    in.close();
091:                } catch (Exception e) {
092:                    server.log(Server.LOG_ERROR, propsPrefix + MAP, ": ("
093:                            + mapFile + ") " + e.toString());
094:                    return false;
095:                }
096:                return true;
097:            }
098:
099:            /** 
100:             * Dispatch and handle the request.
101:             * This version looks at the supplier id, rewrites the url based on
102:             * that supplier, then lets the default handler do it.
103:             */
104:
105:            public boolean respond(Request request) {
106:                if (!request.url.startsWith(urlPrefix)) {
107:                    return false;
108:                }
109:
110:                request.log(Server.LOG_INFORMATIONAL, propsPrefix
111:                        + "..  handling request");
112:                if (request.headers.get(authHeader) == null) {
113:                    request.sendError(404,
114:                            "Not Authorized - no credentials supplied", "");
115:                    return true;
116:                }
117:
118:                StringTokenizer auth = new StringTokenizer(
119:                        (String) request.headers.get(authHeader));
120:                String realm = auth.nextToken();
121:                if (!realm.equals(realm)) {
122:                    request.sendError(404, "Not Authorized - Invalid realm",
123:                            "Realm: " + auth + " need: " + realm);
124:                    return true;
125:                }
126:
127:                String src = auth.nextToken();
128:                String dst = map.getProperty(src, request.props.getProperty(
129:                        propsPrefix + DEFAULT, ""));
130:                if (dst.equals("")) {
131:                    request.sendError(404, "Not Authorized - Invalid id :"
132:                            + src, "");
133:                    return true;
134:                }
135:
136:                // If we have a supplier url, change it to the correct supplier, 
137:                // based on the id of the user, otherwise handle it as a normal url.
138:
139:                String url = "/" + dst
140:                        + request.url.substring(request.url.indexOf("/", 1));
141:                request.log(Server.LOG_INFORMATIONAL, propsPrefix
142:                        + ": mapping " + request.url + " -> " + url);
143:                request.url = url;
144:                return false;
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.