KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > chain > servlet > AuthorizeAction


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.chain.servlet;
18
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import org.apache.commons.chain.Context;
22 import org.apache.commons.chain.web.servlet.ServletWebContext;
23 import org.apache.struts.chain.AbstractAuthorizeAction;
24 import org.apache.struts.config.ActionConfig;
25
26
27 /**
28  * <p>Determine if the action is authorized for the given roles.</p>
29  *
30  * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
31  */

32
33 public class AuthorizeAction extends AbstractAuthorizeAction {
34
35
36     // ------------------------------------------------------- Protected Methods
37

38
39     protected boolean isAuthorized(Context context, String JavaDoc[] roles,
40                                    ActionConfig mapping) throws Exception JavaDoc {
41         
42         // Identify the HTTP request object
43
ServletWebContext swcontext = (ServletWebContext) context;
44         HttpServletRequest JavaDoc request = swcontext.getRequest();
45         
46         // Check the current user against the list of required roles
47
for (int i = 0; i < roles.length; i++) {
48             if (request.isUserInRole(roles[i])) {
49                 return (true);
50             }
51         }
52         
53         // Default to unauthorized
54
return (false);
55
56     }
57
58 }
59
Popular Tags