Source Code Cross Referenced for AuthCheckFilter.java in  » Net » openfire » org » jivesoftware » admin » 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 » Net » openfire » org.jivesoftware.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $RCSfile$
003:         * $Revision: 4016 $
004:         * $Date: 2006-06-18 14:12:04 -0700 (Sun, 18 Jun 2006) $
005:         *
006:         * Copyright (C) 2004 Jive Software. All rights reserved.
007:         *
008:         * This software is published under the terms of the GNU Public License (GPL),
009:         * a copy of which is included in this distribution.
010:         */package org.jivesoftware.admin;
011:
012:        import org.jivesoftware.util.ConcurrentHashSet;
013:        import org.jivesoftware.util.Log;
014:        import org.jivesoftware.util.WebManager;
015:
016:        import javax.servlet.*;
017:        import javax.servlet.http.HttpServletRequest;
018:        import javax.servlet.http.HttpServletResponse;
019:        import java.io.IOException;
020:        import java.net.URLEncoder;
021:        import java.util.Set;
022:        import java.util.StringTokenizer;
023:
024:        /**
025:         * A simple filter which checks for the auth token in the user's session. If it's not there
026:         * the filter will redirect to the login page.
027:         */
028:        public class AuthCheckFilter implements  Filter {
029:
030:            private static Set<String> excludes = new ConcurrentHashSet<String>();
031:
032:            private ServletContext context;
033:            private String defaultLoginPage;
034:
035:            /**
036:             * Adds a new string that when present in the requested URL will skip
037:             * the "is logged" checking.
038:             *
039:             * @param exclude the string to exclude.
040:             */
041:            public static void addExclude(String exclude) {
042:                excludes.add(exclude);
043:            }
044:
045:            /**
046:             * Removes a string that when present in the requested URL will skip
047:             * the "is logged" checking.
048:             *
049:             * @param exclude the string that was being excluded.
050:             */
051:            public static void removeExclude(String exclude) {
052:                excludes.remove(exclude);
053:            }
054:
055:            public void init(FilterConfig config) throws ServletException {
056:                context = config.getServletContext();
057:                defaultLoginPage = config.getInitParameter("defaultLoginPage");
058:                String excludesProp = config.getInitParameter("excludes");
059:                if (excludesProp != null) {
060:                    StringTokenizer tokenizer = new StringTokenizer(
061:                            excludesProp, ",");
062:                    while (tokenizer.hasMoreTokens()) {
063:                        String tok = tokenizer.nextToken().trim();
064:                        excludes.add(tok);
065:                    }
066:                }
067:            }
068:
069:            public void doFilter(ServletRequest req, ServletResponse res,
070:                    FilterChain chain) throws IOException, ServletException {
071:                HttpServletRequest request = (HttpServletRequest) req;
072:                HttpServletResponse response = (HttpServletResponse) res;
073:                // Reset the defaultLoginPage variable
074:                String loginPage = defaultLoginPage;
075:                if (loginPage == null) {
076:                    loginPage = request.getContextPath() + "/login.jsp";
077:                }
078:                // Get the page we're on:
079:                String url = request.getRequestURL().toString();
080:                // See if it's contained in the exclude list. If so, skip filter execution
081:                boolean doExclude = false;
082:                for (String exclude : excludes) {
083:                    if (url.indexOf(exclude) > -1) {
084:                        doExclude = true;
085:                        break;
086:                    }
087:                }
088:                if (!doExclude) {
089:                    WebManager manager = new WebManager();
090:                    manager.init(request, response, request.getSession(),
091:                            context);
092:                    if (manager.getUser() == null) {
093:                        response.sendRedirect(getRedirectURL(request,
094:                                loginPage, null));
095:                        return;
096:                    }
097:                }
098:                chain.doFilter(req, res);
099:            }
100:
101:            public void destroy() {
102:            }
103:
104:            private String getRedirectURL(HttpServletRequest request,
105:                    String loginPage, String optionalParams) {
106:                StringBuilder buf = new StringBuilder();
107:                try {
108:                    buf.append(request.getRequestURI());
109:                    String qs = request.getQueryString();
110:                    if (qs != null) {
111:                        buf.append("?").append(qs);
112:                    }
113:                } catch (Exception e) {
114:                    Log.error(e);
115:                }
116:                try {
117:                    return loginPage
118:                            + "?url="
119:                            + URLEncoder.encode(buf.toString(), "ISO-8859-1")
120:                            + (optionalParams != null ? "&" + optionalParams
121:                                    : "");
122:                } catch (Exception e) {
123:                    Log.error(e);
124:                    return null;
125:                }
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.