[java-sp-server] branch main updated: Null cleanup.
Scott Cantor
cantor.2 at osu.edu
Tue Jan 31 21:20:21 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-sp-server.
View the commit online:
http://git.shibboleth.net/view/?p=java-sp-server.git;a=commit;h=0731aa6156fd0bc6de67cc2b27f7fbcca869da2b
The following commit(s) were added to refs/heads/main by this push:
new 0731aa6 Null cleanup.
0731aa6 is described below
commit 0731aa6156fd0bc6de67cc2b27f7fbcca869da2b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jan 31 16:20:19 2023 -0500
Null cleanup.
---
.../net/shibboleth/sp/impl/BasicApplication.java | 14 +++++-----
.../impl/BasicApplicationEndpointManager.java | 7 ++---
.../sp/remoting/impl/BasicEndpointManager.java | 7 ++---
.../sp/remoting/impl/ReloadingEndpointManager.java | 7 ++---
.../sp/remoting/impl/RequestProcessor.java | 31 +++++++++++++---------
.../tcp/impl/TCPConnectionInterceptorFactory.java | 16 +++++------
.../sp/spring/impl/ByteArrayToDDFConverter.java | 7 +++--
.../sp/spring/impl/DDFToByteArrayConverter.java | 7 +++--
.../PropertiesApplicationContextInitializer.java | 12 ++++-----
.../sp/remoting/endpoint/impl/XMLParserTest.java | 7 +++--
10 files changed, 64 insertions(+), 51 deletions(-)
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java
index b53412b..d8069c8 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/impl/BasicApplication.java
@@ -19,7 +19,6 @@ import javax.annotation.Nonnull;
import org.opensaml.saml.metadata.resolver.MetadataResolver;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.idp.attribute.filter.AttributeFilter;
import net.shibboleth.idp.attribute.resolver.AttributeResolver;
@@ -28,6 +27,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.service.ReloadableService;
import net.shibboleth.sp.Application;
import net.shibboleth.sp.remoting.AbstractEndpoint;
@@ -156,17 +156,17 @@ public class BasicApplication extends AbstractEndpoint implements Application {
@Nonnull public DDF doReceive(@Nonnull final DDF input) throws RemoteProcessingException {
checkComponentActive();
- final DDF component = input.getmember(COMPONENT);
- if (!component.isstring()) {
- log.warn("{}: Received message without string-valued {} member", getId(), COMPONENT);
+ final String component = input.getmember(COMPONENT).string();
+ if (component == null || component.isEmpty()) {
+ log.warn("{}: Received message without component address", getId(), COMPONENT);
throw new RemoteProcessingException("No component identified in message");
}
- final ApplicationEndpoint endpoint = endpointManager.getApplicationEndpoint(component.string());
+ final ApplicationEndpoint endpoint = endpointManager.getApplicationEndpoint(component);
if (endpoint == null) {
- log.warn("{}: No registered component {}", getId(), component.string());
- throw new RemoteProcessingException("No registered component " + component.string());
+ log.warn("{}: No registered component {}", getId(), component);
+ throw new RemoteProcessingException("No registered component " + component);
}
return endpoint.receive(this, input);
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicApplicationEndpointManager.java b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicApplicationEndpointManager.java
index c5b3131..1ccd65d 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicApplicationEndpointManager.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicApplicationEndpointManager.java
@@ -15,7 +15,6 @@
package net.shibboleth.sp.remoting.impl;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
@@ -23,12 +22,14 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.springframework.beans.factory.annotation.Autowired;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.remoting.ApplicationEndpoint;
import net.shibboleth.sp.remoting.ApplicationEndpointManager;
@@ -55,7 +56,7 @@ public class BasicApplicationEndpointManager extends AbstractIdentifiableInitial
if (remotedObjects != null) {
addressMap = remotedObjects.stream().collect(Collectors.toMap(ApplicationEndpoint::getAddress, r -> r));
} else {
- addressMap = Collections.emptyMap();
+ addressMap = CollectionSupport.emptyMap();
}
log.debug("Registered addresses: {}", addressMap.keySet());
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicEndpointManager.java b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicEndpointManager.java
index f3fb145..7b28178 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicEndpointManager.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/BasicEndpointManager.java
@@ -15,7 +15,6 @@
package net.shibboleth.sp.remoting.impl;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
@@ -23,12 +22,14 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.springframework.beans.factory.annotation.Autowired;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.remoting.Endpoint;
import net.shibboleth.sp.remoting.EndpointManager;
@@ -54,7 +55,7 @@ public class BasicEndpointManager extends AbstractIdentifiableInitializableCompo
if (remotedObjects != null) {
addressMap = remotedObjects.stream().collect(Collectors.toMap(Endpoint::getAddress, r -> r));
} else {
- addressMap = Collections.emptyMap();
+ addressMap = CollectionSupport.emptyMap();
}
log.debug("Registered addresses: {}", addressMap.keySet());
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/ReloadingEndpointManager.java b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/ReloadingEndpointManager.java
index 3406649..a62723a 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/ReloadingEndpointManager.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/ReloadingEndpointManager.java
@@ -18,6 +18,7 @@
package net.shibboleth.sp.remoting.impl;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import net.shibboleth.shared.annotation.ParameterName;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
@@ -49,18 +50,18 @@ public class ReloadingEndpointManager extends AbstractServiceableComponent<Endpo
/** {@inheritDoc} */
@Override
protected void doInitialize() throws ComponentInitializationException {
- setId(service.getId());
+ setId(Constraint.isNotNull(service.getId(), "Service ID cannot be null"));
super.doInitialize();
}
/** {@inheritDoc} */
- public Endpoint getEndpoint(@Nonnull @NotEmpty final String address) {
+ @Nullable public Endpoint getEndpoint(@Nonnull @NotEmpty final String address) {
return service.getEndpoint(address);
}
/** {@inheritDoc} */
@Override
- public EndpointManager getComponent() {
+ @Nonnull public EndpointManager getComponent() {
return this;
}
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/RequestProcessor.java b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/RequestProcessor.java
index 16bb398..f628cd9 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/RequestProcessor.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/impl/RequestProcessor.java
@@ -17,25 +17,26 @@ package net.shibboleth.sp.remoting.impl;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.springframework.integration.ip.IpHeaders;
import org.springframework.messaging.Message;
import net.shibboleth.sp.remoting.RemoteProcessingException;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.net.IPRange;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.service.ReloadableService;
+import net.shibboleth.shared.service.ServiceException;
import net.shibboleth.shared.service.ServiceableComponent;
import net.shibboleth.sp.remoting.Endpoint;
import net.shibboleth.sp.remoting.EndpointManager;
@@ -56,6 +57,11 @@ public class RequestProcessor extends AbstractIdentifiableInitializableComponent
/** Address lookup service. */
@NonnullAfterInit ReloadableService<EndpointManager> service;
+
+ /** Constructor. */
+ public RequestProcessor() {
+ allowedRanges = CollectionSupport.emptyList();
+ }
/**
* Sets the {@link EndpointManager} to use.
@@ -77,9 +83,9 @@ public class RequestProcessor extends AbstractIdentifiableInitializableComponent
checkSetterPreconditions();
if (ranges != null) {
- allowedRanges = List.copyOf(ranges);
+ allowedRanges = CollectionSupport.copyToList(ranges);
} else {
- allowedRanges = Collections.emptyList();
+ allowedRanges = CollectionSupport.emptyList();
}
}
@@ -130,23 +136,22 @@ public class RequestProcessor extends AbstractIdentifiableInitializableComponent
log.trace("Input message: {}", input.toString());
- if (input.name() == null) {
+ final String name = input.name();
+ if (name == null) {
log.warn("Input message lacked an address");
throw new RemoteProcessingException("Input message lacked an address");
}
final Endpoint endpoint;
try (final ServiceableComponent<EndpointManager> component = service.getServiceableComponent()) {
- if (null == component) {
- log.error("Error accessing EndpointManager component: Invalid configuration");
- throw new RemoteProcessingException("Error accessing EndpointManager component: Invalid configuration");
- }
- endpoint = component.getComponent().getEndpoint(input.name());
+ endpoint = component.getComponent().getEndpoint(name);
+ } catch (final ServiceException e) {
+ throw new RemoteProcessingException("Error accessing EndpointManager component: Invalid configuration", e);
}
if (endpoint == null) {
- log.warn("No registered target for address {}", input.name());
- throw new RemoteProcessingException("No registered target for address " + input.name());
+ log.warn("No registered target for address {}", name);
+ throw new RemoteProcessingException("No registered target for address " + name);
}
final DDF output = endpoint.receive(input);
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/tcp/impl/TCPConnectionInterceptorFactory.java b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/tcp/impl/TCPConnectionInterceptorFactory.java
index 0fc6190..e4e25c1 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/tcp/impl/TCPConnectionInterceptorFactory.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/remoting/tcp/impl/TCPConnectionInterceptorFactory.java
@@ -16,14 +16,12 @@
package net.shibboleth.sp.remoting.tcp.impl;
import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactory;
@@ -32,7 +30,9 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.net.IPRange;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.remoting.RemoteProcessingException;
/**
@@ -53,21 +53,21 @@ public class TCPConnectionInterceptorFactory implements TcpConnectionInterceptor
*/
public TCPConnectionInterceptorFactory(@Nullable @NonnullElements final Collection<IPRange> ranges) {
if (ranges != null) {
- allowedRanges = List.copyOf(ranges);
+ allowedRanges = CollectionSupport.copyToList(ranges);
} else {
- allowedRanges = Collections.emptyList();
+ allowedRanges = CollectionSupport.emptyList();
}
}
/** {@inheritDoc} */
@Override
- public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
+ public void setApplicationEventPublisher(@Nonnull ApplicationEventPublisher publisher) {
applicationEventPublisher = publisher;
}
/** {@inheritDoc} */
@Override
- public TcpConnectionInterceptorSupport getInterceptor() {
+ @Nonnull public TcpConnectionInterceptorSupport getInterceptor() {
return new TCPConnectionInterceptor(applicationEventPublisher);
}
@@ -90,7 +90,7 @@ public class TCPConnectionInterceptorFactory implements TcpConnectionInterceptor
/** {@inheritDoc} */
@Override
- public boolean onMessage(Message<?> message) {
+ public boolean onMessage(@Nonnull final Message<?> message) {
if (allowedRanges.stream().anyMatch(range -> range.contains(getSocketInfo().getInetAddress()))) {
return super.onMessage(message);
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/ByteArrayToDDFConverter.java b/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/ByteArrayToDDFConverter.java
index f425848..d0ff2b6 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/ByteArrayToDDFConverter.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/ByteArrayToDDFConverter.java
@@ -20,6 +20,9 @@ package net.shibboleth.sp.spring.impl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.springframework.core.convert.converter.Converter;
import net.shibboleth.sp.ddf.DDF;
@@ -30,11 +33,11 @@ import net.shibboleth.sp.ddf.DDF;
public class ByteArrayToDDFConverter implements Converter<byte[], DDF> {
/** {@inheritDoc} */
- public DDF convert(final byte[] source) {
+ @Nullable public DDF convert(@Nonnull final byte[] source) {
try (final ByteArrayInputStream bais = new ByteArrayInputStream(source)) {
return DDF.deserialize(bais);
} catch (final IOException e) {
- throw new RuntimeException(e);
+ return null;
}
}
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/DDFToByteArrayConverter.java b/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/DDFToByteArrayConverter.java
index a00bedc..2a67a6c 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/DDFToByteArrayConverter.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/DDFToByteArrayConverter.java
@@ -20,6 +20,9 @@ package net.shibboleth.sp.spring.impl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.springframework.core.convert.converter.Converter;
import net.shibboleth.sp.ddf.DDF;
@@ -30,12 +33,12 @@ import net.shibboleth.sp.ddf.DDF;
public class DDFToByteArrayConverter implements Converter<DDF, byte[]> {
/** {@inheritDoc} */
- public byte[] convert(final DDF source) {
+ @Nullable public byte[] convert(@Nonnull final DDF source) {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
source.serialize(baos);
return baos.toByteArray();
} catch (final IOException e) {
- throw new RuntimeException(e);
+ return null;
}
}
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/PropertiesApplicationContextInitializer.java b/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/PropertiesApplicationContextInitializer.java
index ab63b6b..07b4ef6 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/PropertiesApplicationContextInitializer.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/spring/impl/PropertiesApplicationContextInitializer.java
@@ -46,37 +46,37 @@ public class PropertiesApplicationContextInitializer extends AbstractPropertiesA
/** {@inheritDoc} */
@Override
- protected String getHomePropertyName() {
+ @Nonnull @NotEmpty protected String getHomePropertyName() {
return SP_HOME_PROPERTY;
}
/** {@inheritDoc} */
@Override
- protected String getSearchTarget() {
+ @Nonnull @NotEmpty protected String getSearchTarget() {
return SP_PROPERTIES;
}
/** {@inheritDoc} */
@Override
- protected String getSearchLocation() {
+ @Nonnull @NotEmpty protected String getSearchLocation() {
return SEARCH_LOCATION;
}
/** {@inheritDoc} */
@Override
- protected String getFailFastPropertyName() {
+ @Nonnull @NotEmpty protected String getFailFastPropertyName() {
return FAILFAST_PROPERTY;
}
/** {@inheritDoc} */
@Override
- protected String getAdditionalPropertiesPropertyName() {
+ @Nonnull @NotEmpty protected String getAdditionalPropertiesPropertyName() {
return SP_ADDITIONAL_PROPERTY;
}
/** {@inheritDoc} */
@Override
- protected String getAutoSearchPropertyName() {
+ @Nonnull @NotEmpty protected String getAutoSearchPropertyName() {
return SP_AUTOSEARCH_PROPERTY;
}
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/remoting/endpoint/impl/XMLParserTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/remoting/endpoint/impl/XMLParserTest.java
index 3d5f23e..aa71283 100644
--- a/sp-server-impl/src/test/java/net/shibboleth/sp/remoting/endpoint/impl/XMLParserTest.java
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/remoting/endpoint/impl/XMLParserTest.java
@@ -20,8 +20,6 @@ package net.shibboleth.sp.remoting.endpoint.impl;
import java.io.IOException;
import java.io.InputStream;
-import javax.annotation.Nullable;
-
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -38,9 +36,9 @@ import net.shibboleth.sp.ddf.DDF;
*/
public class XMLParserTest {
- @Nullable private BasicParserPool parserPool;
+ private BasicParserPool parserPool;
- @Nullable private XMLParser endpoint;
+ private XMLParser endpoint;
/**
* Init parser.
@@ -54,6 +52,7 @@ public class XMLParserTest {
endpoint = new XMLParser();
endpoint.setId("test");
+ assert parserPool != null;
endpoint.setParserPool(parserPool);
endpoint.initialize();
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list