01: /*
02: * (C) Copyright 2002 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package com.nabhinc.condition;
23:
24: import javax.portlet.PortletRequest;
25: import javax.servlet.http.HttpServletRequest;
26: import javax.xml.bind.annotation.XmlRootElement;
27:
28: import com.nabhinc.core.WebServiceRequest;
29:
30: /**
31: * Insert the type's description here.
32: *
33: * @author Padmanabh Dabke
34: * (c) 2002 Nabh Information Systems, Inc. All Rights Reserved.
35: */
36: @XmlRootElement(name="allow-roles")
37: public class AllowRoles extends RolesCondition implements Condition {
38: private static final long serialVersionUID = -5562465239728839830L;
39:
40: public AllowRoles() {
41: super ();
42: }
43:
44: public AllowRoles(String[] roles) {
45: super (roles);
46: }
47:
48: /**
49: * @see com.nabhinc.condition.Condition#isSatisfied(javax.servlet.http.HttpServletRequest)
50: */
51: public boolean isSatisfied(HttpServletRequest req, Object target) {
52:
53: for (int i = 0; i < this .roles.length; i++) {
54: if (req.isUserInRole(this .roles[i]))
55: return true;
56: }
57:
58: return false;
59: }
60:
61: public boolean isSatisfied(PortletRequest req, Object target) {
62:
63: for (int i = 0; i < this .roles.length; i++) {
64: if (req.isUserInRole(this .roles[i]))
65: return true;
66: }
67:
68: return false;
69: }
70:
71: public boolean isSatisfied(WebServiceRequest req, Object target) {
72:
73: for (int i = 0; i < this .roles.length; i++) {
74: if (req.isUserInRole(this .roles[i]))
75: return true;
76: }
77:
78: return false;
79: }
80:
81: }
|