-
-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Browser Based Authentication to Client Spider
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
- Loading branch information
1 parent
3894fe0
commit 6cb0096
Showing
12 changed files
with
370 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...authhelper/src/main/java/org/zaproxy/addon/authhelper/client/BrowserBasedAuthHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2024 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.addon.authhelper.client; | ||
|
||
import org.zaproxy.addon.authhelper.AuthUtils; | ||
import org.zaproxy.addon.authhelper.BrowserBasedAuthenticationMethodType; | ||
import org.zaproxy.addon.client.spider.AuthenticationHandler; | ||
import org.zaproxy.zap.model.Context; | ||
import org.zaproxy.zap.users.User; | ||
|
||
public class BrowserBasedAuthHandler implements AuthenticationHandler { | ||
|
||
@Override | ||
public void enableAuthentication(User user) { | ||
Context context = user.getContext(); | ||
if (context.getAuthenticationMethod() | ||
instanceof BrowserBasedAuthenticationMethodType.BrowserBasedAuthenticationMethod) { | ||
AuthUtils.enableBrowserAuthentication(context, user.getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void disableAuthentication(User user) { | ||
AuthUtils.disableBrowserAuthentication(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...thhelper/src/main/java/org/zaproxy/addon/authhelper/client/ExtensionAuthhelperClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2024 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.addon.authhelper.client; | ||
|
||
import java.util.List; | ||
import org.parosproxy.paros.Constant; | ||
import org.parosproxy.paros.control.Control; | ||
import org.parosproxy.paros.extension.Extension; | ||
import org.parosproxy.paros.extension.ExtensionAdaptor; | ||
import org.parosproxy.paros.extension.ExtensionHook; | ||
import org.zaproxy.addon.client.ExtensionClientIntegration; | ||
|
||
public class ExtensionAuthhelperClient extends ExtensionAdaptor { | ||
|
||
public static final String NAME = "ExtensionAuthhelperClient"; | ||
|
||
private static final List<Class<? extends Extension>> DEPENDENCIES = | ||
List.of(ExtensionClientIntegration.class); | ||
|
||
private BrowserBasedAuthHandler authHandler; | ||
|
||
public ExtensionAuthhelperClient() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public boolean supportsDb(String type) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void hook(ExtensionHook extensionHook) { | ||
super.hook(extensionHook); | ||
authHandler = new BrowserBasedAuthHandler(); | ||
getClientExtension().addAuthenticationHandler(authHandler); | ||
} | ||
|
||
private static ExtensionClientIntegration getClientExtension() { | ||
return Control.getSingleton() | ||
.getExtensionLoader() | ||
.getExtension(ExtensionClientIntegration.class); | ||
} | ||
|
||
@Override | ||
public boolean canUnload() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void unload() { | ||
getClientExtension().removeAuthenticationHandler(authHandler); | ||
} | ||
|
||
@Override | ||
public List<Class<? extends Extension>> getDependencies() { | ||
return DEPENDENCIES; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Constant.messages.getString("authhelper.client.desc"); | ||
} | ||
|
||
@Override | ||
public String getUIName() { | ||
return Constant.messages.getString("authhelper.client.name"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../src/test/java/org/zaproxy/addon/authhelper/client/ExtensionAuthhelperClientUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2024 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.addon.authhelper.client; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.zaproxy.addon.authhelper.ExtensionAuthhelper; | ||
import org.zaproxy.zap.testutils.TestUtils; | ||
|
||
class ExtensionAuthhelperClientUnitTest extends TestUtils { | ||
|
||
@Test | ||
void shouldHaveName() { | ||
// Given | ||
ExtensionAuthhelperClient cl = new ExtensionAuthhelperClient(); | ||
mockMessages(new ExtensionAuthhelper()); | ||
// When / Then | ||
assertThat(cl.getName(), is(equalTo("ExtensionAuthhelperClient"))); | ||
} | ||
|
||
@Test | ||
void shouldHaveUiName() { | ||
// Given | ||
ExtensionAuthhelperClient cl = new ExtensionAuthhelperClient(); | ||
mockMessages(new ExtensionAuthhelper()); | ||
// When / Then | ||
assertThat( | ||
cl.getUIName(), is(equalTo("Client Spider Browser Based Authentication Support"))); | ||
} | ||
|
||
@Test | ||
void shouldBeUnloadable() { | ||
// Given | ||
ExtensionAuthhelperClient cl = new ExtensionAuthhelperClient(); | ||
// When / Then | ||
assertThat(cl.canUnload(), is(equalTo(true))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
addOns/client/src/main/java/org/zaproxy/addon/client/spider/AuthenticationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2024 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.addon.client.spider; | ||
|
||
import org.zaproxy.zap.users.User; | ||
|
||
public interface AuthenticationHandler { | ||
|
||
/** | ||
* * Enables authentication handling for the given user, if the handler applies. | ||
* | ||
* @param user the user to authenticate for | ||
*/ | ||
void enableAuthentication(User user); | ||
|
||
/** | ||
* Disables authentication handling for the given user, if the handler applies. | ||
* | ||
* @param user the user | ||
*/ | ||
void disableAuthentication(User user); | ||
} |
Oops, something went wrong.