[java-opensaml COMMIT] in /trunk/opensaml-profile-api/src: main/java/org/opensaml/profile/logic/IPRangePredicate.java...
noreply at shibboleth.net
noreply at shibboleth.net
Mon Oct 10 14:26:24 EDT 2016
Author: scantor
Date: Mon Oct 10 14:26:24 2016
New Revision: 4526
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4526&view=rev
Log:
OSJ-174 - IPRangePredicate is difficult to configure
https://issues.shibboleth.net/jira/browse/OSJ-174
Modified:
trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java
trunk/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
trunk/opensaml-profile-api/src/test/resources/iprange.xml
Modified: trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java?rev=4526&r1=4525&r2=4526&view=diff
==============================================================================
--- trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java (original)
+++ trunk/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java Mon Oct 10 14:26:24 2016
@@ -33,6 +33,7 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses;
@@ -55,7 +56,12 @@
/**
* Set the address ranges to check against.
*
+ * <p>This version is deprecated because Spring doesn't handle converting strings
+ * to Iterable.</p>
+ *
* @param ranges address ranges to check against
+ *
+ * @deprecated
*/
public void setAddressRanges(@Nonnull @NonnullElements Iterable<IPRange> ranges) {
Constraint.isNotNull(ranges, "Address range collection cannot be null");
@@ -64,6 +70,19 @@
for (final IPRange range : Iterables.filter(ranges, Predicates.notNull())) {
addressRanges.add(range);
}
+ }
+
+ /**
+ * Set the address ranges to check against.
+ *
+ * @param ranges address ranges to check against
+ *
+ * @since 3.3.0
+ */
+ public void setRanges(@Nonnull @NonnullElements Collection<IPRange> ranges) {
+ Constraint.isNotNull(ranges, "Address range collection cannot be null");
+
+ addressRanges = new ArrayList<>(Collections2.filter(ranges, Predicates.notNull()));
}
/**
@@ -76,14 +95,13 @@
}
/** {@inheritDoc} */
- @Override
public boolean apply(@Nullable final BaseContext input) {
- String address = httpRequest != null ? httpRequest.getRemoteAddr() : null;
+ final String address = httpRequest != null ? httpRequest.getRemoteAddr() : null;
if (address == null || !InetAddresses.isInetAddress(address)) {
return false;
}
- for (IPRange range : addressRanges) {
+ for (final IPRange range : addressRanges) {
if (range.contains(InetAddresses.forString(address))) {
return true;
}
Modified: trunk/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java?rev=4526&r1=4525&r2=4526&view=diff
==============================================================================
--- trunk/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java (original)
+++ trunk/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java Mon Oct 10 14:26:24 2016
@@ -37,7 +37,7 @@
*/
public class IPRangePredicateTest {
- @Test(enabled=false) public void testRanges() {
+ @Test public void testRanges() {
final GenericApplicationContext ctx = SpringSupport.newContext("IpRange", Collections.singletonList((Resource)new ClassPathResource("iprange.xml")),
Collections.<BeanFactoryPostProcessor> emptyList(),
Collections.<BeanPostProcessor> singletonList(new IdentifiableBeanPostProcessor()),
Modified: trunk/opensaml-profile-api/src/test/resources/iprange.xml
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-profile-api/src/test/resources/iprange.xml?rev=4526&r1=4525&r2=4526&view=diff
==============================================================================
--- trunk/opensaml-profile-api/src/test/resources/iprange.xml (original)
+++ trunk/opensaml-profile-api/src/test/resources/iprange.xml Mon Oct 10 14:26:24 2016
@@ -7,8 +7,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
- <bean id="theee" class="org.opensaml.profile.logic.IPRangePredicate">
- <property name="addressRanges">
+ <bean id="three" class="org.opensaml.profile.logic.IPRangePredicate">
[... 16 lines stripped ...]
More information about the commits
mailing list