Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed Solution to Issue 171 #274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified misc/runTest.sh
100755 → 100644
Empty file.
Empty file modified src/Common/.classpath
100755 → 100644
Empty file.
Empty file modified src/Common/.project
100755 → 100644
Empty file.
Empty file modified src/HTML_Renderer/.classpath
100755 → 100644
Empty file.
Empty file modified src/HTML_Renderer/.project
100755 → 100644
Empty file.
Empty file modified src/HTML_Renderer/COBRA-ACK.txt
100755 → 100644
Empty file.
Empty file modified src/HTML_Renderer/COBRA-README.txt
100755 → 100644
Empty file.
Empty file modified src/HTML_Renderer/LICENSE.txt
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion src/HTML_Renderer/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}" encoding="UTF8">
<src path="."/>
<classpath refid="HTML_Renderer.classpath"/>
</javac>
Expand Down
Empty file modified src/HTML_Renderer/org/w3c/COPYRIGHT.html
100755 → 100644
Empty file.
3 changes: 3 additions & 0 deletions src/Platform_Core/org/lobobrowser/gui/FramePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ private void navigateLocal(final @NonNull URL url, final String method, final Re
}

private void navigateLocal(final NavigationEvent event) {
// request Manager reset!!!
requestManager.reset(event.getURL());
try {
this.dispatchBeforeLocalNavigate(event);
Expand Down Expand Up @@ -878,6 +879,7 @@ public NavigatorWindowImpl run() {
});

final FramePanel newFrame = wcontext.getFramePanel();
// ATTENTION!!! Frame Panel request manager reset!
newFrame.requestManager.reset(url);

final UserAgentContext uaContext = new SilentUserAgentContextImpl(newFrame);
Expand Down Expand Up @@ -1323,6 +1325,7 @@ private void updateContentProperties(final ComponentContent content) {
}
}

// New request manager.
private final RequestManager requestManager = new RequestManager(this);

public boolean isRequestPermitted(final Request request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.lobobrowser.ua.UserAgentContext.RequestKind;

public class PermissionSystem {

static enum Permission {
Allow, Deny, Undecided;

Expand Down Expand Up @@ -315,7 +316,12 @@ public void setPermission(final Permission permission) {
myPermission = permission;
store.storePermissions(hostPattern, requestHost, kindOpt, permission);
}


// A method that returns the permission in here.
public Permission getMyPermission() {
return myPermission;
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected int calculateTabWidth(final int tabPlacement, final int tabIndex, fina

private static JPanel makeBoardView(final PermissionBoard board, final String[] columnNames, final String[][] requestData,
final List<PermissionCellButton> buttons, final ChangeListener listener) {

final JPanel grid = new JPanel(new GridBagLayout());
final GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
Expand All @@ -72,6 +73,9 @@ private static JPanel makeBoardView(final PermissionBoard board, final String[]
for (int i = 0, numRows = board.getRowCount(); i < numRows; i++) {
gbc.gridy = i + 1;
final PermissionRow row = rows.get(i).getValue();

// calculate the values

addRowToGrid(grid, gbc, row, requestData[i], listener, buttons);
}
}
Expand All @@ -88,6 +92,7 @@ private static void addRowToGrid(final JPanel grid, final GridBagConstraints gbc
if (j == 0) {
gbc.weightx = 1d;
cell = row.getHostCell();

} else {
gbc.weightx = 0d;
cell = row.getRequestCell(j - 1);
Expand Down
41 changes: 36 additions & 5 deletions src/Platform_Core/org/lobobrowser/security/RequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.lobobrowser.security.PermissionSystem.Permission;
import org.lobobrowser.security.PermissionSystem.PermissionBoard.PermissionRow;
Expand All @@ -41,7 +43,10 @@ public final class RequestManager {
private static final Logger logger = Logger.getLogger(RequestManager.class.getName());

private final NavigatorFrame frame;


// Values that track whether or not a request is accepted or rejected.
int accepted;
int rejected;

public RequestManager(final NavigatorFrame frame) {
this.frame = frame;
Expand Down Expand Up @@ -110,6 +115,7 @@ private Request rewriteRequest(final Request request) {
}
}

// A method that determines whether or not a given request is permitted.
public boolean isRequestPermitted(final Request request) {

final Request finalRequest = rewriteRequest(request);
Expand All @@ -125,22 +131,36 @@ public boolean isRequestPermitted(final Request request) {
if (protocolTest.equals("http") && frameProtocol.equals("https")) {
updateCounter(finalRequest.url.getHost(), RequestKind.UnsecuredHTTP);
if (!httpPermitted) {
// The request isn't permitted, so it's rejected.
rejected++;
return false;
}
}
}

// dumpCounters();

if (permitted == true) {
// The request is permitted, so we increment accepted.
accepted++;
} else {
// The request is not permitted, so we increment rejected.
rejected++;
}
return permitted;
} else {
logger.severe("Unexpected permission system state. Request without context!");
// The request is not permitted, so we increment rejected.
rejected++;
return false;
}
}

private void setupPermissionSystem(final String frameHost) {
final RequestRuleStore permissionStore = RequestRuleStore.getStore();
final PermissionSystem system = new PermissionSystem(frameHost, permissionStore);

// Initialize the accept and reject details.
accepted = 0;
rejected = 0;

// Prime the boards with atleast one row
system.getLastBoard().getRow(frameHost);
Expand Down Expand Up @@ -174,14 +194,12 @@ public synchronized void reset(final URL frameUrl) {
}

public void manageRequests(final JComponent initiatorComponent) {
// permissionSystemOpt.ifPresent(r -> r.dump());
final ManageDialog dlg = new ManageDialog(new JFrame(), getFrameURL().map(u -> u.toExternalForm()).orElse("Empty!"),
initiatorComponent);
dlg.setVisible(true);
}

private synchronized String[][] getRequestData() {
// hostToCounterMap.keySet().stream().forEach(System.out::println);

return hostToCounterMap.entrySet().stream().map(entry -> {
final List<String> rowElements = new LinkedList<>();
Expand Down Expand Up @@ -219,7 +237,15 @@ public ManageDialog(final JFrame parent, final String title, final JComponent in

final JPanel buttonPane = new JPanel();
final JButton button = new JButton("OK");

JLabel aLabel = new JLabel("Accepted Requests: " + accepted);
buttonPane.add(aLabel);
buttonPane.add(button);

// Add relevant statistics to button pane.
JLabel oLabel = new JLabel("Total Requests: " + (accepted + rejected));
buttonPane.add(oLabel);

button.addActionListener(this);
getContentPane().add(buttonPane, BorderLayout.SOUTH);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Expand Down Expand Up @@ -296,6 +322,11 @@ public void windowActivated(final WindowEvent e) {
public void allowAllFirstPartyRequests() {
permissionSystemOpt.ifPresent(p -> {
final PermissionRow row = p.getLastBoard().getRow(getFrameHost().get());
// Was the request we are changing initially denied?
if (row.getHostCell().getMyPermission() == Permission.Deny) {
rejected--;
}
accepted++;
row.getHostCell().setPermission(Permission.Allow);
});
}
Expand Down
Empty file modified src/XAMJ_Build/.externalToolBuilders/API_Doc_Builder.launch
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/.externalToolBuilders/Ant Builder.launch
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/.externalToolBuilders/Installer Builder.launch
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/.project
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/build.xml.disabled
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/default-shortcut-spec.xml
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/install.xml
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/re_manifest.mf
100755 → 100644
Empty file.
Empty file modified src/XAMJ_Build/windows-shortcut-spec.xml
100755 → 100644
Empty file.