/*
* (C) Copyright 2002 Nabh Information Systems, Inc.
*
* All copyright notices regarding Nabh's products MUST remain
* intact in the scripts and in the outputted HTML.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package com.nabhinc.condition;
import javax.portlet.PortletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.annotation.XmlRootElement;
import com.nabhinc.core.WebServiceRequest;
/**
* A pre-condition that is satisfied when the user connects from a
* set of IP addresses.
*
* @author Padmanabh Dabke
* (c) 2002 Nabh Information Systems, Inc. All Rights Reserved.
*/
@XmlRootElement(name="deny-ips")
public class DenyIP extends IPCondition implements Condition {
private static final long serialVersionUID = -3071172988797000202L;
public DenyIP() {
super();
}
public DenyIP(String[] ips) {
super(ips);
}
/**
* @see com.nabhinc.condition.Condition#isSatisfied(javax.servlet.http.HttpServletRequest)
*/
public boolean isSatisfied(HttpServletRequest req, Object target) {
String addr = req.getRemoteAddr();
return isSatisfiedHelper(addr);
}
public boolean isSatisfied(PortletRequest req, Object target) {
String addr = (String) req.getAttribute(addressAttribute);
return isSatisfiedHelper(addr);
}
public boolean isSatisfied(WebServiceRequest req, Object target) {
String addr = (String) req.getAttribute(addressAttribute);
return isSatisfiedHelper(addr);
}
public boolean isSatisfiedHelper(String addr) {
for (int i = 0; i < addresses.length; i++) {
if (addresses[i].equals(addr))
return false;
}
return true;
}
}
|