-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quickstart: Add "API Explore" button
Signed-off-by: ricekot <[email protected]>
- Loading branch information
Showing
12 changed files
with
292 additions
and
9 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
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
119 changes: 119 additions & 0 deletions
119
...kstart/src/main/java/org/zaproxy/zap/extension/quickstart/apiexplore/ApiExplorePanel.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,119 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2023 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.zap.extension.quickstart.apiexplore; | ||
|
||
import java.awt.FlowLayout; | ||
import javax.swing.AbstractButton; | ||
import javax.swing.ImageIcon; | ||
import javax.swing.JButton; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import org.parosproxy.paros.Constant; | ||
import org.parosproxy.paros.control.Control; | ||
import org.zaproxy.zap.extension.api.API; | ||
import org.zaproxy.zap.extension.quickstart.ExtensionQuickStart; | ||
import org.zaproxy.zap.extension.quickstart.QuickStartBackgroundPanel; | ||
import org.zaproxy.zap.extension.quickstart.QuickStartHelper; | ||
import org.zaproxy.zap.extension.quickstart.QuickStartPanel; | ||
import org.zaproxy.zap.extension.quickstart.QuickStartSubPanel; | ||
import org.zaproxy.zap.extension.quickstart.launch.ExtensionQuickStartLaunch; | ||
import org.zaproxy.zap.utils.DisplayUtils; | ||
import org.zaproxy.zap.view.LayoutHelper; | ||
|
||
public class ApiExplorePanel extends QuickStartSubPanel { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private static final ImageIcon ICON = | ||
DisplayUtils.getScaledIcon( | ||
new ImageIcon( | ||
ApiExplorePanel.class.getResource( | ||
"/org/zaproxy/zap/extension/quickstart/resources/api-explore_64px.png"))); | ||
|
||
private JButton graphiQlButton; | ||
|
||
public ApiExplorePanel(ExtensionQuickStart extension, QuickStartPanel qsp) { | ||
super(extension, qsp); | ||
} | ||
|
||
@Override | ||
public String getTitleKey() { | ||
return "quickstart.apiExplore.panel.title"; | ||
} | ||
|
||
@Override | ||
public ImageIcon getIcon() { | ||
return ICON; | ||
} | ||
|
||
@Override | ||
public JPanel getDescriptionPanel() { | ||
JPanel panel = new QuickStartBackgroundPanel(); | ||
panel.add( | ||
QuickStartHelper.getWrappedLabel("quickstart.apiExplore.panel.message1"), | ||
LayoutHelper.getGBC(0, 0, 2, 1.0D, DisplayUtils.getScaledInsets(5, 5, 5, 5))); | ||
panel.add( | ||
new JLabel(" "), | ||
LayoutHelper.getGBC( | ||
0, 1, 2, 1.0D, DisplayUtils.getScaledInsets(5, 5, 5, 5))); // Spacer | ||
return panel; | ||
} | ||
|
||
@Override | ||
public JPanel getContentPanel() { | ||
JPanel panel = new JPanel(new FlowLayout()); | ||
panel.setBackground(getBackground()); | ||
panel.add(getGraphiQlButton()); | ||
return panel; | ||
} | ||
|
||
private JButton getGraphiQlButton() { | ||
if (graphiQlButton == null) { | ||
graphiQlButton = new JButton(); | ||
graphiQlButton.setText(Constant.messages.getString("quickstart.graphiql.button.name")); | ||
graphiQlButton.setIcon( | ||
DisplayUtils.getScaledIcon( | ||
getClass() | ||
.getResource( | ||
"/org/zaproxy/zap/extension/quickstart/resources/graphql_64px.png"))); | ||
graphiQlButton.setVerticalTextPosition(AbstractButton.BOTTOM); | ||
graphiQlButton.setHorizontalTextPosition(AbstractButton.CENTER); | ||
graphiQlButton.setToolTipText( | ||
Constant.messages.getString("quickstart.graphiql.button.tooltip")); | ||
graphiQlButton.setPreferredSize(DisplayUtils.getScaledDimension(150, 120)); | ||
var extQuickStartLaunch = | ||
Control.getSingleton() | ||
.getExtensionLoader() | ||
.getExtension(ExtensionQuickStartLaunch.class); | ||
graphiQlButton.addActionListener( | ||
e -> | ||
extQuickStartLaunch.launchBrowser( | ||
"http://zap/graphiql?" | ||
+ API.API_NONCE_PARAM | ||
+ '=' | ||
+ API.getInstance().getLongLivedNonce("/graphiql"))); | ||
} | ||
return graphiQlButton; | ||
} | ||
|
||
@Override | ||
public JPanel getFooterPanel() { | ||
return null; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...rt/src/main/java/org/zaproxy/zap/extension/quickstart/apiexplore/ExtensionApiExplore.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,115 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2023 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.zap.extension.quickstart.apiexplore; | ||
|
||
import java.awt.Component; | ||
import java.util.List; | ||
import javax.swing.AbstractButton; | ||
import javax.swing.JButton; | ||
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.graphql.ExtensionGraphQl; | ||
import org.zaproxy.zap.extension.quickstart.ExtensionQuickStart; | ||
import org.zaproxy.zap.extension.quickstart.launch.ExtensionQuickStartLaunch; | ||
import org.zaproxy.zap.utils.DisplayUtils; | ||
|
||
public class ExtensionApiExplore extends ExtensionAdaptor { | ||
|
||
private static final List<Class<? extends Extension>> DEPENDENCIES = | ||
List.of(ExtensionGraphQl.class, ExtensionQuickStartLaunch.class); | ||
|
||
private ApiExplorePanel apiExplorePanel; | ||
private JButton apiExploreButton; | ||
|
||
@Override | ||
public String getUIName() { | ||
return Constant.messages.getString("quickstart.apiExplore.extension.uiName"); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Constant.messages.getString("quickstart.apiExplore.extension.desc"); | ||
} | ||
|
||
@Override | ||
public List<Class<? extends Extension>> getDependencies() { | ||
return DEPENDENCIES; | ||
} | ||
|
||
@Override | ||
public void hook(ExtensionHook extensionHook) { | ||
super.hook(extensionHook); | ||
|
||
if (hasView()) { | ||
var buttonPanel = getExtQuickStart().getQuickStartPanel().getButtonPanel(); | ||
for (Component component : buttonPanel.getComponents()) { | ||
if (component instanceof JButton) { | ||
var button = (JButton) component; | ||
if (Constant.messages | ||
.getString("quickstart.apiExplore.button.name") | ||
.equals(button.getText())) { | ||
buttonPanel.remove(button); | ||
break; | ||
} | ||
} | ||
} | ||
var buttonCount = buttonPanel.getComponentCount(); | ||
buttonPanel.add(getApiExploreButton(), buttonCount - 1); | ||
buttonPanel.revalidate(); | ||
buttonPanel.repaint(); | ||
} | ||
} | ||
|
||
private JButton getApiExploreButton() { | ||
if (apiExploreButton == null) { | ||
apiExploreButton = new JButton(); | ||
apiExploreButton.setText( | ||
Constant.messages.getString("quickstart.apiExplore.button.name")); | ||
apiExploreButton.setIcon(getApiExplorePanel().getIcon()); | ||
apiExploreButton.setVerticalTextPosition(AbstractButton.BOTTOM); | ||
apiExploreButton.setHorizontalTextPosition(AbstractButton.CENTER); | ||
apiExploreButton.setToolTipText( | ||
Constant.messages.getString("quickstart.apiExplore.button.tooltip")); | ||
apiExploreButton.setPreferredSize(DisplayUtils.getScaledDimension(150, 120)); | ||
apiExploreButton.addActionListener( | ||
e -> | ||
getExtQuickStart() | ||
.getQuickStartPanel() | ||
.showSubPanel(getApiExplorePanel())); | ||
} | ||
return apiExploreButton; | ||
} | ||
|
||
private ApiExplorePanel getApiExplorePanel() { | ||
if (apiExplorePanel == null) { | ||
apiExplorePanel = | ||
new ApiExplorePanel( | ||
getExtQuickStart(), getExtQuickStart().getQuickStartPanel()); | ||
} | ||
return apiExplorePanel; | ||
} | ||
|
||
private ExtensionQuickStart getExtQuickStart() { | ||
return Control.getSingleton().getExtensionLoader().getExtension(ExtensionQuickStart.class); | ||
} | ||
} |
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
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
Binary file added
BIN
+15.5 KB
...n/resources/org/zaproxy/zap/extension/quickstart/resources/api-explore_64px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.81 KB
.../main/resources/org/zaproxy/zap/extension/quickstart/resources/graphql_64px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.