org.mortbay.http.handler

Class IPAccessHandler

Implemented Interfaces:
HttpHandler, LifeCycle, Serializable

public class IPAccessHandler
extends AbstractHttpHandler

Handler to authenticate access from certain IP-addresses.

A server configuration-XML-file can look something like this:
<Configure class="org.mortbay.jetty.Server">
...
<Call name="addContext">
...
<Call name="addHandler">
<Arg>
<New class="IPAccessHandler">
<Set name="Standard">deny</Set>
<Set name="AllowIP">192.168.0.103</Set>
<Set name="AllowIP">192.168.0.100</Set>
</New>
</Arg>
</Call>
...

This would deny access for everyone except the requests from the IPs 192.168.0.100 and 192.168.0.103.
Version:
v0.1 2002/03/20
Author:
Gösta Jonasson gosta@kth.se

Constructor Summary

IPAccessHandler()
Constructor for the class

Method Summary

boolean
checkIP(String ipstring)
Checks if the given ipstring (x.x.x.x) is authorized or not
void
handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response)
Handles the incoming request
void
setAllowIP(String ipstring)
Allow the given ip-address access
void
setDenyIP(String ipstring)
Deny the given ip-address access
void
setStandard(String s)
Set the standard action beeing taken when not registred IPs wants access

Methods inherited from class org.mortbay.http.handler.AbstractHttpHandler

getHttpContext, getName, handleTrace, initialize, isStarted, setName, start, stop, toString

Constructor Details

IPAccessHandler

public IPAccessHandler()
Constructor for the class

Method Details

checkIP

public boolean checkIP(String ipstring)
Checks if the given ipstring (x.x.x.x) is authorized or not
Parameters:
ipstring - The ip-address as a String
Returns:
True if the IP is allowed access, otherwise false.

handle

public void handle(String pathInContext,
                   String pathParams,
                   HttpRequest request,
                   HttpResponse response)
            throws HttpException,
                   IOException
Handles the incoming request
Specified by:
handle in interface HttpHandler
Parameters:
pathInContext -
pathParams -
request - The incoming HTTP-request
response - The outgoing HTTP-response

setAllowIP

public void setAllowIP(String ipstring)
Allow the given ip-address access
Parameters:
ipstring - The ip-address as a String on the format "x.x.x.x"

setDenyIP

public void setDenyIP(String ipstring)
Deny the given ip-address access
Parameters:
ipstring - The ip-address as a String on the format "x.x.x.x"

setStandard

public void setStandard(String s)
Set the standard action beeing taken when not registred IPs wants access
Parameters:
s - The standard-string (either 'allow' or 'deny')

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.