KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > dispatch > SecurityRoleMapFilterChain


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.server.dispatch;
30
31 import com.caucho.log.Log;
32 import com.caucho.server.connection.CauchoRequest;
33
34 import javax.servlet.FilterChain JavaDoc;
35 import javax.servlet.ServletException JavaDoc;
36 import javax.servlet.ServletRequest JavaDoc;
37 import javax.servlet.ServletRequestWrapper JavaDoc;
38 import javax.servlet.ServletResponse JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * Represents the next filter in a filter chain. The final filter will
45  * be the servlet itself.
46  */

47 public class SecurityRoleMapFilterChain implements FilterChain JavaDoc {
48   private static final Logger JavaDoc log = Log.open(SecurityRoleMapFilterChain.class);
49   
50   // Next filter chain
51
private FilterChain JavaDoc _next;
52
53   // app
54
private HashMap JavaDoc<String JavaDoc,String JavaDoc> _roleMap;
55
56   /**
57    * Creates a new FilterChainFilter.
58    *
59    * @param next the next filterChain
60    * @param filter the user's filter
61    */

62   public SecurityRoleMapFilterChain(FilterChain JavaDoc next,
63                     HashMap JavaDoc<String JavaDoc,String JavaDoc> roleMap)
64   {
65     _next = next;
66     if (_next == null)
67       throw new NullPointerException JavaDoc();
68     
69     _roleMap = roleMap;
70   }
71   
72   /**
73    * Invokes the next filter in the chain or the final servlet at
74    * the end of the chain.
75    *
76    * @param request the servlet request
77    * @param response the servlet response
78    * @since Servlet 2.3
79    */

80   public void doFilter(ServletRequest JavaDoc request,
81                        ServletResponse JavaDoc response)
82     throws ServletException JavaDoc, IOException JavaDoc
83   {
84     // HashMap<String,String> oldMap = null;
85
ServletRequest JavaDoc ptr = request;
86     CauchoRequest req = null;
87
88     while (ptr instanceof ServletRequestWrapper JavaDoc) {
89       ServletRequestWrapper JavaDoc wrapper;
90       wrapper = (ServletRequestWrapper JavaDoc) ptr;
91
92       if (ptr instanceof CauchoRequest) {
93     break;
94       }
95       else if (wrapper.getRequest() != null)
96     ptr = wrapper.getRequest();
97       else
98     break;
99     }
100
101     if (ptr instanceof CauchoRequest) {
102       req = (CauchoRequest) ptr;
103
104       // oldMap = req.setRoleMap(_roleMap);
105
}
106     
107     try {
108       _next.doFilter(request, response);
109     } finally {
110       /*
111       if (req != null)
112     req.setRoleMap(oldMap);
113       */

114     }
115   }
116 }
117
Popular Tags