001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.dispatch;
030:
031: import com.caucho.log.Log;
032: import com.caucho.server.connection.CauchoRequest;
033:
034: import javax.servlet.FilterChain;
035: import javax.servlet.ServletException;
036: import javax.servlet.ServletRequest;
037: import javax.servlet.ServletRequestWrapper;
038: import javax.servlet.ServletResponse;
039: import java.io.IOException;
040: import java.util.HashMap;
041: import java.util.logging.Logger;
042:
043: /**
044: * Represents the next filter in a filter chain. The final filter will
045: * be the servlet itself.
046: */
047: public class SecurityRoleMapFilterChain implements FilterChain {
048: private static final Logger log = Log
049: .open(SecurityRoleMapFilterChain.class);
050:
051: // Next filter chain
052: private FilterChain _next;
053:
054: // app
055: private HashMap<String, String> _roleMap;
056:
057: /**
058: * Creates a new FilterChainFilter.
059: *
060: * @param next the next filterChain
061: * @param filter the user's filter
062: */
063: public SecurityRoleMapFilterChain(FilterChain next,
064: HashMap<String, String> roleMap) {
065: _next = next;
066: if (_next == null)
067: throw new NullPointerException();
068:
069: _roleMap = roleMap;
070: }
071:
072: /**
073: * Invokes the next filter in the chain or the final servlet at
074: * the end of the chain.
075: *
076: * @param request the servlet request
077: * @param response the servlet response
078: * @since Servlet 2.3
079: */
080: public void doFilter(ServletRequest request,
081: ServletResponse response) throws ServletException,
082: IOException {
083: // HashMap<String,String> oldMap = null;
084: ServletRequest ptr = request;
085: CauchoRequest req = null;
086:
087: while (ptr instanceof ServletRequestWrapper) {
088: ServletRequestWrapper wrapper;
089: wrapper = (ServletRequestWrapper) ptr;
090:
091: if (ptr instanceof CauchoRequest) {
092: break;
093: } else if (wrapper.getRequest() != null)
094: ptr = wrapper.getRequest();
095: else
096: break;
097: }
098:
099: if (ptr instanceof CauchoRequest) {
100: req = (CauchoRequest) ptr;
101:
102: // oldMap = req.setRoleMap(_roleMap);
103: }
104:
105: try {
106: _next.doFilter(request, response);
107: } finally {
108: /*
109: if (req != null)
110: req.setRoleMap(oldMap);
111: */
112: }
113: }
114: }
|