[java-identity-provider] 02/02: IDP-1793 Use Suppliers for HttpRequest/Response
Rod Widdowson
rdw at steadingsoftware.com
Sun Aug 14 15:24:55 UTC 2022
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=36ffa5267a55055fe96df5cbb94d1af3c497aed1
commit 36ffa5267a55055fe96df5cbb94d1af3c497aed1
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Aug 7 20:17:17 2022 +0100
IDP-1793 Use Suppliers for HttpRequest/Response
https://shibboleth.atlassian.net/browse/IDP-1793
net.shibboleth.idp.authn.impl.StorageBackedAccountLockoutManager.UsernameIPLockoutKeyStrategy
Gains a setter/getter for a Supplier for the HttpServletRequest
and loses the setter for the raw object.
---
.../impl/StorageBackedAccountLockoutManager.java | 29 ++++++++++++++++------
.../StorageBackedAccountLockoutManagerTest.java | 4 ++-
.../net/shibboleth/idp/conf/global-system.xml | 2 +-
3 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManager.java b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManager.java
index b767d1709..a43571c1c 100644
--- a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManager.java
+++ b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManager.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.function.Function;
+import java.util.function.Supplier;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -375,16 +376,28 @@ public class StorageBackedAccountLockoutManager extends AbstractIdentifiableInit
*/
public static class UsernameIPLockoutKeyStrategy implements Function<ProfileRequestContext,String> {
- /** Servlet request to pull client ip from. **/
- @Nullable private HttpServletRequest httpRequest;
+ /** Supplier for the Servlet request to pull client ip from. **/
+ @Nullable private Supplier<HttpServletRequest> httpRequestSupplier;
/**
- * Set the servlet request to read from.
+ * Set the Supplier for the servlet request to read from.
*
- * @param request servlet request
+ * @param requestSupplier servlet request Supplier
*/
- public void setHttpServletRequest(@Nonnull final HttpServletRequest request) {
- httpRequest = Constraint.isNotNull(request, "HttpServletRequest cannot be null");
+ public void setHttpServletRequestSupplier(@Nonnull final Supplier<HttpServletRequest> requestSupplier) {
+ httpRequestSupplier = Constraint.isNotNull(requestSupplier, "HttpServletRequest cannot be null");
+ }
+
+ /**
+ * Get the current HTTP request if available.
+ *
+ * @return current HTTP request
+ */
+ @Nullable private HttpServletRequest getHttpServletRequest() {
+ if (httpRequestSupplier == null) {
+ return null;
+ }
+ return httpRequestSupplier.get();
}
/** {@inheritDoc} */
@@ -399,7 +412,7 @@ public class StorageBackedAccountLockoutManager extends AbstractIdentifiableInit
return lockoutManagerContext.getKey();
}
- if (httpRequest == null) {
+ if (getHttpServletRequest() == null) {
return null;
}
@@ -416,7 +429,7 @@ public class StorageBackedAccountLockoutManager extends AbstractIdentifiableInit
}
final String username = upContext.getUsername();
- final String ipAddr = HttpServletSupport.getRemoteAddr(httpRequest);
+ final String ipAddr = HttpServletSupport.getRemoteAddr(getHttpServletRequest());
if (username == null || username.isEmpty() || ipAddr == null || ipAddr.isEmpty()) {
return null;
}
diff --git a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java
index 8fcbe8f31..018426d2f 100644
--- a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java
+++ b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/impl/StorageBackedAccountLockoutManagerTest.java
@@ -19,6 +19,7 @@ package net.shibboleth.idp.authn.impl;
import java.time.Duration;
+import java.util.function.Supplier;
import org.opensaml.storage.impl.MemoryStorageService;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -46,7 +47,8 @@ public class StorageBackedAccountLockoutManagerTest extends BaseAuthenticationCo
ss.initialize();
final UsernameIPLockoutKeyStrategy keyStrategy = new UsernameIPLockoutKeyStrategy();
- keyStrategy.setHttpServletRequest((HttpServletRequest) src.getExternalContext().getNativeRequest());
+ final HttpServletRequest request = (HttpServletRequest) src.getExternalContext().getNativeRequest();
+ keyStrategy.setHttpServletRequestSupplier(new Supplier<>() {public HttpServletRequest get() {return request;}});
manager = new StorageBackedAccountLockoutManager();
manager.setId("test");
manager.setStorageService(ss);
diff --git a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/global-system.xml b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/global-system.xml
index 439aad8f7..0a39b7267 100644
--- a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/global-system.xml
+++ b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/global-system.xml
@@ -274,7 +274,7 @@
p:storageService-ref="shibboleth.StorageService">
<property name="lockoutKeyStrategy">
<bean class="net.shibboleth.idp.authn.impl.StorageBackedAccountLockoutManager.UsernameIPLockoutKeyStrategy"
- p:httpServletRequest-ref="shibboleth.HttpServletRequest" />
+ p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier" />
</property>
</bean>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list