blob: 687ee20136621c0033b86d1ebfb93815d4e289a4 [file] [log] [blame]
Title: 5.1 - Blacklist Filter
NavPrev: ch5-filters.html
NavPrevText: Chapter 5 - Filters
NavUp: ch5-filters.html
NavUpText: Chapter 5 - Filters
NavNext: ch5.2-buffered-write-filter.html
NavNextText: 5.2 - Buffered Write Filter
Notice: Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
# 5.1 - Blacklist Filter
This filter blocks connnections from blacklisted remote addresses. Onee can block _Addresses_ or _Subnets_. In any case, when an event happens on a blocked session, the session will simply be closed. Here are the events this filter handles :
* _event_ (MINA 2.1)
* _messageReceived_
* _messageSent_
* _sessionCreated_
* _sessionIdle_
* _sessionOpened_
There is no need to handle any other event.
## Blocking an address
Any address or subnet can be blocked live, ie it does not matter if a session is already active or not, this dynamicaly activated.
It's enough to add the filter in the chain, and to set (or unset) the addresses to block:
:::Java
...
BlacklistFilter blackList = new BlacklistFilter();
blackList.block(InetAddress.getByName("1.2.3.4"));
acceptor.getFilterChain().addLast("blacklist", new BlacklistFilter());
...
Here, the "1.2.3.4" address will be blocked.
## Unblocking an address
It's possible to unblock an address, it's just a matter of fetching the filter and remove a previously blocked addres:
:::Java
...
BlacklistFilter blackList = (BlacklistFilter)session.getFilterChain().get(BlacklistFilter.class);
blackList.unblock(InetAddress.getByName("1.2.3.4"));
...
Here, the "1.2.3.4" address will be unblocked.
## Performances
Currently, the implementation is not really optimal... We use a _List_ to store the blocked addresses/subnet, so the more of them you have in the list the longer it will take to process any event.