This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git
The following commit(s) were added to refs/heads/master by this push:
new a5303a3 SLING-10248 : Refactor: Move auth requirements handling into
separate component
a5303a3 is described below
commit a5303a3795e1457a1738cedcbed5b8a5855de565
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Mon Mar 22 08:13:50 2021 +0100
SLING-10248 : Refactor: Move auth requirements handling into separate
component
---
.../sling/auth/core/impl/SlingAuthenticator.java | 9 -----
.../auth/core/impl/SlingAuthenticatorTest.java | 45 ++++++++++++++--------
2 files changed, 30 insertions(+), 24 deletions(-)
diff --git
a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
index 45ba2e6..c441245 100644
--- a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
+++ b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
@@ -338,15 +338,6 @@ public class SlingAuthenticator implements Authenticator,
this.modified(config);
}
- /**
- * Constructor for unit tests
- */
- SlingAuthenticator() {
- this.resourceResolverFactory = null;
- this.metrics = null;
- this.serviceListener = null;
- }
-
@Modified
private void modified(final Config config) {
if (!config.auth_sudo_cookie().equals(this.sudoCookieName)) {
diff --git
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
index b315f45..23e3440 100644
--- a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
+++ b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
@@ -138,7 +138,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test/childnodetest";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -165,7 +166,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -192,7 +194,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test/";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -219,7 +222,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test.html";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -242,7 +246,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/";
final String REQUEST_CHILD_NODE = "/content/en/test";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -267,7 +272,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH_LONGER = "/resource1.test2";
final String REQUEST_CHILD_NODE = "/resource1.test2";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -308,7 +314,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_NOT_PROTECTED_PATH = "/content/en/test2";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
@@ -329,7 +336,8 @@ public class SlingAuthenticatorTest {
public void test_childNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test/test2";
final String handlerPath = "/content/test";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -338,7 +346,8 @@ public class SlingAuthenticatorTest {
public void test_siblingNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath =
"/content/test2.html/en/2016/09/19/test.html";
final String handlerPath = "/content/test";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertFalse(
(boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -347,7 +356,8 @@ public class SlingAuthenticatorTest {
public void test_actualNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test";
final String handlerPath = "/content/test";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -356,7 +366,8 @@ public class SlingAuthenticatorTest {
public void test_rootNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test";
final String handlerPath = "/";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -365,7 +376,8 @@ public class SlingAuthenticatorTest {
public void test_requestPathSelectorsAreTakenInConsideration() throws
Throwable {
final String requestPath =
"/content/test.selector1.selector2.html/en/2016/test.html";
final String handlerPath = "/content/test";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -374,7 +386,8 @@ public class SlingAuthenticatorTest {
public void test_requestPathSelectorsSiblingAreTakenInConsideration()
throws Throwable {
final String requestPath =
"/content/test.selector1.selector2.html/en/2016/09/19/test.html";
final String handlerPath = "/content/test2";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertFalse(
(boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -383,7 +396,8 @@ public class SlingAuthenticatorTest {
public void test_requestPathBackSlash() throws Throwable {
final String requestPath = "/page1\\somesubepage";
final String handlerPath = "/page";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertFalse(
(boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -392,7 +406,8 @@ public class SlingAuthenticatorTest {
public void test_emptyNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test";
final String handlerPath = "";
- SlingAuthenticator slingAuthenticator = new SlingAuthenticator();
+ SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class),
+ null, Mockito.mock(BundleContext.class), createDefaultConfig());
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}