[java-identity-provider] branch master updated: IDP-1516 - Reduce Guava dependence
Scott Cantor
cantor.2 at osu.edu
Mon Nov 4 13:50:32 EST 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=49e1528ab8989f5da4808ce440e5b411862455ae
The following commit(s) were added to refs/heads/master by this push:
new 49e1528 IDP-1516 - Reduce Guava dependence
49e1528 is described below
commit 49e1528ab8989f5da4808ce440e5b411862455ae
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Nov 4 13:50:29 2019 -0500
IDP-1516 - Reduce Guava dependence
https://issues.shibboleth.net/jira/browse/IDP-1516
Optional sanitized from IdP.
---
.../impl/PopulateProfileInterceptorContext.java | 8 +++---
.../impl/PopulateBindingAndEndpointContexts.java | 18 ++++++-------
.../shibboleth/idp/session/AbstractIdPSession.java | 30 ++++++++++++++--------
.../idp/session/impl/StorageBackedIdPSession.java | 11 ++++----
.../impl/StorageBackedIdPSessionSerializer.java | 8 +++---
.../idp/session/impl/complexIdPSession.jdk8 | 2 +-
6 files changed, 41 insertions(+), 36 deletions(-)
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/PopulateProfileInterceptorContext.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/PopulateProfileInterceptorContext.java
index 68eda25..7e4dfbd 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/PopulateProfileInterceptorContext.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/PopulateProfileInterceptorContext.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.profile.interceptor.impl;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.function.Function;
import javax.annotation.Nonnull;
@@ -39,9 +40,6 @@ import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-
/**
* An profile interceptor action that populates a {@link ProfileInterceptorContext} with
* {@link ProfileInterceptorFlowDescriptor} objects based on flow IDs from a lookup function.
@@ -112,11 +110,11 @@ public class PopulateProfileInterceptorContext extends AbstractProfileIntercepto
for (final String id : activeFlows) {
final String flowId = ProfileInterceptorFlowDescriptor.FLOW_ID_PREFIX + id;
final Optional<ProfileInterceptorFlowDescriptor> flow =
- Iterables.tryFind(availableFlows, fd -> fd.getId().equals(flowId));
+ availableFlows.stream().filter(fd -> fd.getId().equals(flowId)).findFirst();
if (flow.isPresent()) {
log.debug("{} Installing flow {} into interceptor context", getLogPrefix(), flowId);
- interceptorContext.getAvailableFlows().put(flow.get().getId(), flow.get());
+ interceptorContext.getAvailableFlows().put(flow.orElseThrow().getId(), flow.orElseThrow());
} else {
log.error("{} Configured interceptor flow {} not available for use", getLogPrefix(), flowId);
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/PopulateBindingAndEndpointContexts.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/PopulateBindingAndEndpointContexts.java
index f592574..e62a399 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/PopulateBindingAndEndpointContexts.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/PopulateBindingAndEndpointContexts.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.saml.profile.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.function.Function;
import javax.annotation.Nonnull;
@@ -68,9 +69,6 @@ import org.opensaml.saml.saml2.metadata.IndexedEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-
/**
* Action that populates the outbound {@link SAMLBindingContext} and when appropriate the
* {@link SAMLEndpointContext} based on the inbound request.
@@ -441,10 +439,10 @@ public class PopulateBindingAndEndpointContexts extends AbstractProfileAction {
bindingCtx.setRelayState(SAMLBindingSupport.getRelayState(profileRequestContext.getInboundMessageContext()));
final Optional<BindingDescriptor> bindingDescriptor =
- Iterables.tryFind(bindingDescriptors, b -> b.getId().equals(bindingURI));
+ bindingDescriptors.stream().filter(b -> b.getId().equals(bindingURI)).findFirst();
if (bindingDescriptor.isPresent()) {
- bindingCtx.setBindingDescriptor(bindingDescriptor.get());
+ bindingCtx.setBindingDescriptor(bindingDescriptor.orElseThrow());
} else {
bindingCtx.setBindingUri(resolvedEndpoint.getBinding());
}
@@ -485,15 +483,17 @@ public class PopulateBindingAndEndpointContexts extends AbstractProfileAction {
profileRequestContext.getInboundMessageContext().getSubcontext(SAMLBindingContext.class);
if (bindingCtx != null && bindingCtx.getBindingUri() != null) {
final Optional<BindingDescriptor> binding =
- Iterables.tryFind(bindingDescriptors, b -> b.getId().equals(bindingCtx.getBindingUri()));
- if (binding.isPresent() && binding.get().isSynchronous()) {
+ bindingDescriptors.stream().filter(
+ b -> b.getId().equals(bindingCtx.getBindingUri())
+ ).findFirst();
+ if (binding.isPresent() && binding.orElseThrow().isSynchronous()) {
log.debug("{} Handling request via synchronous binding, preparing outbound binding context for {}",
- getLogPrefix(), binding.get().getId());
+ getLogPrefix(), binding.orElseThrow().getId());
final SAMLBindingContext outboundCtx = bindingContextLookupStrategy.apply(profileRequestContext);
outboundCtx.setRelayState(SAMLBindingSupport.getRelayState(
profileRequestContext.getInboundMessageContext()));
- outboundCtx.setBindingDescriptor(binding.get());
+ outboundCtx.setBindingDescriptor(binding.orElseThrow());
return true;
}
}
diff --git a/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java b/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java
index 08f6381..1857234 100644
--- a/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java
+++ b/idp-session-api/src/main/java/net/shibboleth/idp/session/AbstractIdPSession.java
@@ -20,9 +20,11 @@ package net.shibboleth.idp.session;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -41,8 +43,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableSet;
/**
* Abstract base for implementations of {@link IdPSession}, handles basic management of the
@@ -93,10 +93,10 @@ public abstract class AbstractIdPSession implements IdPSession {
@Nullable private String ipV6Address;
/** Tracks authentication results that have occurred during this session. */
- @Nonnull private final ConcurrentMap<String, Optional<AuthenticationResult>> authenticationResults;
+ @Nonnull private final ConcurrentMap<String,Optional<AuthenticationResult>> authenticationResults;
/** Tracks services which have been issued authentication tokens during this session. */
- @Nonnull private final ConcurrentMap<String, Optional<SPSession>> spSessions;
+ @Nonnull private final ConcurrentMap<String,Optional<SPSession>> spSessions;
/**
* Constructor.
@@ -248,13 +248,18 @@ public abstract class AbstractIdPSession implements IdPSession {
/** {@inheritDoc} */
@Nonnull @NonnullElements @NotLive @Unmodifiable public Set<AuthenticationResult> getAuthenticationResults() {
- return ImmutableSet.copyOf(Optional.presentInstances(authenticationResults.values()));
+ return Set.copyOf(
+ authenticationResults.values()
+ .stream()
+ .filter(Optional::isPresent)
+ .map(Optional::orElseThrow)
+ .collect(Collectors.toUnmodifiableSet()));
}
/** {@inheritDoc} */
@Nullable public AuthenticationResult getAuthenticationResult(@Nonnull @NotEmpty final String flowId) {
final Optional<AuthenticationResult> mapped = authenticationResults.get(StringSupport.trimOrNull(flowId));
- return (mapped != null) ? mapped.orNull() : null;
+ return (mapped != null) ? mapped.orElse(null) : null;
}
/** {@inheritDoc} */
@@ -311,20 +316,25 @@ public abstract class AbstractIdPSession implements IdPSession {
if (authenticationResults.remove(result.getAuthenticationFlowId(), Optional.of(result))) {
return true;
}
- return authenticationResults.remove(result.getAuthenticationFlowId(), Optional.absent());
+ return authenticationResults.remove(result.getAuthenticationFlowId(), Optional.empty());
}
/** {@inheritDoc} */
@Override
@Nonnull @NonnullElements @NotLive @Unmodifiable public Set<SPSession> getSPSessions() {
- return ImmutableSet.copyOf(Optional.presentInstances(spSessions.values()));
+ return Set.copyOf(
+ spSessions.values()
+ .stream()
+ .filter(Optional::isPresent)
+ .map(Optional::orElseThrow)
+ .collect(Collectors.toUnmodifiableSet()));
}
/** {@inheritDoc} */
@Override
@Nullable public SPSession getSPSession(@Nonnull @NotEmpty final String serviceId) {
final Optional<SPSession> mapped = spSessions.get(StringSupport.trimOrNull(serviceId));
- return (mapped != null) ? mapped.orNull() : null;
+ return (mapped != null) ? mapped.orElse(null) : null;
}
/** {@inheritDoc} */
@@ -379,7 +389,7 @@ public abstract class AbstractIdPSession implements IdPSession {
if (spSessions.remove(spSession.getId(), Optional.of(spSession))) {
return true;
}
- return spSessions.remove(spSession.getId(), Optional.absent());
+ return spSessions.remove(spSession.getId(), Optional.empty());
}
/** {@inheritDoc} */
diff --git a/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java b/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
index e3c25b1..86a7473 100644
--- a/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
+++ b/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.time.Instant;
import java.util.Iterator;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
@@ -46,8 +47,6 @@ import org.opensaml.storage.VersionMismatchException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-
/**
* Implementation of {@link net.shibboleth.idp.session.IdPSession} for use with {@link StorageBackedSessionManager}.
*/
@@ -169,11 +168,11 @@ public class StorageBackedIdPSession extends AbstractIdPSession {
@Nonnull @NonnullElements @NotLive @Unmodifiable public Set<AuthenticationResult> getAuthenticationResults() {
// Check for any sparse/null values in the map, which need to be loaded before returning a complete set.
- final Iterator<Map.Entry<String, Optional<AuthenticationResult>>> entries =
+ final Iterator<Map.Entry<String,Optional<AuthenticationResult>>> entries =
getAuthenticationResultMap().entrySet().iterator();
while (entries.hasNext()) {
- final Map.Entry<String, Optional<AuthenticationResult>> entry = entries.next();
- if (!entry.getValue().isPresent()) {
+ final Map.Entry<String,Optional<AuthenticationResult>> entry = entries.next();
+ if (entry.getValue().isEmpty()) {
try {
final AuthenticationResult result = loadAuthenticationResultFromStorage(entry.getKey());
if (result != null) {
@@ -341,7 +340,7 @@ public class StorageBackedIdPSession extends AbstractIdPSession {
getSPSessionMap().entrySet().iterator();
while (entries.hasNext()) {
final Map.Entry<String, Optional<SPSession>> entry = entries.next();
- if (!entry.getValue().isPresent()) {
+ if (entry.getValue().isEmpty()) {
try {
final SPSession result = loadSPSessionFromStorage(entry.getKey());
if (result != null) {
diff --git a/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSessionSerializer.java b/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSessionSerializer.java
index 42e9c09..6ad2349 100644
--- a/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSessionSerializer.java
+++ b/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSessionSerializer.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.time.Instant;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.Nonnull;
@@ -46,8 +47,6 @@ import org.opensaml.storage.StorageSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-
/**
* A serializer for instances of {@link StorageBackedIdPSession} designed in conjunction with the
* {@link org.opensaml.storage.StorageService}-backed {@link net.shibboleth.idp.session.SessionManager} implementation.
@@ -194,8 +193,7 @@ public class StorageBackedIdPSessionSerializer extends AbstractInitializableComp
if (flowIds != null) {
for (final JsonString flowId : flowIds.getValuesAs(JsonString.class)) {
// An absent mapping is used to signify the existence of a result not yet loaded.
- objectToPopulate.getAuthenticationResultMap().put(flowId.getString(),
- Optional.<AuthenticationResult> absent());
+ objectToPopulate.getAuthenticationResultMap().put(flowId.getString(), Optional.empty());
}
}
}
@@ -206,7 +204,7 @@ public class StorageBackedIdPSessionSerializer extends AbstractInitializableComp
if (svcIds != null) {
for (final JsonString svcId : svcIds.getValuesAs(JsonString.class)) {
// An absent mapping is used to signify the existence of a session not yet loaded.
- objectToPopulate.getSPSessionMap().put(svcId.getString(), Optional.<SPSession> absent());
+ objectToPopulate.getSPSessionMap().put(svcId.getString(), Optional.empty());
}
}
}
diff --git a/idp-session-impl/src/test/resources/net/shibboleth/idp/session/impl/complexIdPSession.jdk8 b/idp-session-impl/src/test/resources/net/shibboleth/idp/session/impl/complexIdPSession.jdk8
index 3493424..f2cdc88 100644
--- a/idp-session-impl/src/test/resources/net/shibboleth/idp/session/impl/complexIdPSession.jdk8
+++ b/idp-session-impl/src/test/resources/net/shibboleth/idp/session/impl/complexIdPSession.jdk8
@@ -1 +1 @@
-{"ts":1378827849463,"nam":"foo","v4":"127.0.0.1","flows":["a","b","c"],"svcs":["bar","baz"]}
\ No newline at end of file
+{"ts":1378827849463,"nam":"foo","v4":"127.0.0.1","flows":["c","b","a"],"svcs":["bar","baz"]}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list