-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GUACAMOLE-1855: Use common code for checking for IP in list.
- Loading branch information
1 parent
c71f490
commit 986aa33
Showing
3 changed files
with
92 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
guacamole-ext/src/main/java/org/apache/guacamole/net/util/IPAddressUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.guacamole.net.util; | ||
|
||
import inet.ipaddr.IPAddress; | ||
import java.util.List; | ||
|
||
/** | ||
* A class for utility functions dealing with IP addresses and lists. | ||
*/ | ||
public class IPAddressUtil { | ||
|
||
/** | ||
* Return true if the provided address list contains the client address, | ||
* or false if no match is found. | ||
* | ||
* @param addrList | ||
* The address list to check for matches. | ||
* | ||
* @param ipAddr | ||
* The client address to look for in the list. | ||
* | ||
* @return | ||
* True if the client address is in the provided list, otherwise | ||
* false. | ||
*/ | ||
public static boolean addressListContains(List<IPAddress> addrList, IPAddress ipAddr) { | ||
|
||
// If either is null, return false | ||
if (ipAddr == null || addrList == null) | ||
return false; | ||
|
||
for (IPAddress ipEntry : addrList) | ||
|
||
// If version matches and entry contains it, return true | ||
if (ipEntry.getIPVersion().equals(ipAddr.getIPVersion()) | ||
&& ipEntry.contains(ipAddr)) | ||
return true; | ||
|
||
// No match, so return false | ||
return false; | ||
|
||
} | ||
|
||
} |