Mercurial > hg > release > icedtea-web-1.7
changeset 1241:0afcc93fb7fb
Implemented general solution for remembering of various dialogues
line wrap: on
line diff
--- a/ChangeLog Thu Jun 11 13:24:54 2015 +0200 +++ b/ChangeLog Fri Jun 12 16:49:07 2015 +0200 @@ -1,3 +1,8 @@ +2015-06-12 Jiri Vanek <jvanek@redhat.com> + + Implemented general solution for remembering of various dialogues + * todo: changelog and javadoc and news + 2015-06-11 Jiri Vanek <jvanek@redhat.com> AppletSecurityActions, ExecuteAppletAction, AppletSecurityActionsTest moved to remember package
--- a/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletActionTableModel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletActionTableModel.java Fri Jun 12 16:49:07 2015 +0200 @@ -39,17 +39,16 @@ import javax.swing.event.TableModelEvent; import javax.swing.table.AbstractTableModel; import net.sourceforge.jnlp.runtime.Translator; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UrlRegEx; import net.sourceforge.jnlp.security.appletextendedsecurity.impl.UnsignedAppletActionStorageExtendedImpl; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; public class UnsignedAppletActionTableModel extends AbstractTableModel { final UnsignedAppletActionStorageExtendedImpl back; - private final String[] columns = new String[]{Translator.R("APPEXTSECguiTableModelTableColumnActionUA"), - Translator.R("APPEXTSECguiTableModelTableColumnActionMatchALACA"), + private final String[] columns = new String[]{Translator.R("APPEXTSECguiTableModelTableColumnRD"), Translator.R("APPEXTSECguiTableModelTableColumnDateOfAction"), Translator.R("APPEXTSECguiTableModelTableColumnDocumentBase"), Translator.R("APPEXTSECguiTableModelTableColumnCodeBase"), @@ -80,18 +79,15 @@ return AppletSecurityActions.class; } if (columnIndex == 1) { - return AppletSecurityActions.class; + return Date.class; } if (columnIndex == 2) { - return Date.class; + return UrlRegEx.class; } if (columnIndex == 3) { return UrlRegEx.class; } if (columnIndex == 4) { - return UrlRegEx.class; - } - if (columnIndex == 5) { return String.class; } return Object.class; @@ -102,11 +98,12 @@ if (back.isReadOnly()) { return false; } - if (columnIndex == 2) { + if (columnIndex == 1) { return false; } + //FIXME add editor if (columnIndex == 0) { - return true; + return true; } if (getValueAt(rowIndex, columnIndex - 1) == null || getValueAt(rowIndex, columnIndex - 1).toString().trim().isEmpty()) { return false; @@ -119,21 +116,18 @@ UnsignedAppletActionEntry source = back.toArray()[rowIndex]; if (columnIndex == 0) { - return source.getAppletSecurityActions().getUnsignedAppletAction(); + return source.getAppletSecurityActions(); } if (columnIndex == 1) { - return source.getAppletSecurityActions().getMatchingAlacaAction(); - } - if (columnIndex == 2) { return source.getTimeStamp(); } + if (columnIndex == 2) { + return source.getDocumentBase(); + } if (columnIndex == 3) { - return source.getDocumentBase(); + return source.getCodeBase(); } if (columnIndex == 4) { - return source.getCodeBase(); - } - if (columnIndex == 5) { return UnsignedAppletActionEntry.createArchivesString(source.getArchives()); } return null; @@ -150,7 +144,7 @@ int i = getRowCount()-1; String s = "\\Qhttp://localhost:80/\\E.*"; back.add(new UnsignedAppletActionEntry( - AppletSecurityActions.createDefault(), + new AppletSecurityActions(), new Date(), new UrlRegEx(s), new UrlRegEx(s),
--- a/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletsTrustingListPanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletsTrustingListPanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -47,6 +47,7 @@ import java.io.OutputStreamWriter; import java.text.DateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -87,13 +88,13 @@ import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.config.PathsAndFiles; import net.sourceforge.jnlp.runtime.Translator; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.ExtendedAppletSecurityHelp; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UrlRegEx; import net.sourceforge.jnlp.security.appletextendedsecurity.impl.UnsignedAppletActionStorageExtendedImpl; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.util.ScreenFinder; import net.sourceforge.jnlp.util.logging.OutputController; @@ -729,20 +730,16 @@ @Override public TableCellEditor getCellEditor(int row, int column) { int columnx = convertColumnIndexToModel(column); - if (columnx == 0 || columnx == 1) { - return new DefaultCellEditor(new JComboBox<>(new ExecuteAppletAction[] { - ExecuteAppletAction.ALWAYS, - ExecuteAppletAction.NEVER, - ExecuteAppletAction.YES, - ExecuteAppletAction.NO, - ExecuteAppletAction.UNSET })); + if (columnx == 0) { + //FIXME add proper editor her egoes jbutton, popupr dialog + return new DefaultCellEditor(new JTextField()); } - if (columnx == 3) { + if (columnx == 2) { column = convertColumnIndexToModel(column); row = convertRowIndexToModel(row); return new DefaultCellEditor(new MyTextField((UrlRegEx) (model.getValueAt(row, column)))); } - if (columnx == 4) { + if (columnx == 3) { column = convertColumnIndexToModel(column); row = convertRowIndexToModel(row); return new DefaultCellEditor(new MyTextField((UrlRegEx) (model.getValueAt(row, column)))); @@ -753,19 +750,19 @@ @Override public TableCellRenderer getCellRenderer(int row, int column) { int columnx = convertColumnIndexToModel(column); - if (columnx == 2) { + if (columnx == 1) { column = convertColumnIndexToModel(column); row = convertRowIndexToModel(row); return new UrlRegexCellRenderer.MyDateCellRenderer((Date) (model.getValueAt(row, column))); } - if (columnx == 3) { + if (columnx == 2) { if (!filterRegexesCheckBox.isSelected()) { column = convertColumnIndexToModel(column); row = convertRowIndexToModel(row); return new UrlRegexCellRenderer((UrlRegEx) (model.getValueAt(row, column))); } } - if (columnx == 4) { + if (columnx == 3) { if (!filterRegexesCheckBox.isSelected()) { column = convertColumnIndexToModel(column); row = convertRowIndexToModel(row); @@ -799,10 +796,10 @@ for (UnsignedAppletActionEntry unsignedAppletActionEntry : items) { AppletSecurityActions actions = unsignedAppletActionEntry.getAppletSecurityActions(); for (int j = 0; j < actions.getRealCount(); j++) { - ExecuteAppletAction action = actions.getAction(j); - if (action == unsignedAppletAction) { - toBeDeleted.add(unsignedAppletActionEntry); - } +// ExecuteAppletAction action = actions.getAction(j); +// if (action == unsignedAppletAction) { +// toBeDeleted.add(unsignedAppletActionEntry); +// } } } String s = Translator.R("APPEXTSECguiPanelConfirmDeletionOf", toBeDeleted.size()) + ": \n"; @@ -940,8 +937,9 @@ @Override public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) { - for (int i = 0; i < AppletSecurityActions.REMEMBER_COLUMNS_COUNT; i++) { - ExecuteAppletAction o = (ExecuteAppletAction) entry.getModel().getValueAt(entry.getIdentifier(), i); + AppletSecurityActions as = (AppletSecurityActions) entry.getModel().getValueAt(entry.getIdentifier(), 0); + Collection<ExecuteAppletAction> l = as.getActions(); + for (ExecuteAppletAction o : l) { if (o.equals(ExecuteAppletAction.ALWAYS) || o.equals(ExecuteAppletAction.NEVER)) { return true; } @@ -954,8 +952,9 @@ @Override public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) { - for (int i = 0; i < AppletSecurityActions.REMEMBER_COLUMNS_COUNT; i++) { - ExecuteAppletAction o = (ExecuteAppletAction) entry.getModel().getValueAt(entry.getIdentifier(), i); + AppletSecurityActions as = (AppletSecurityActions) entry.getModel().getValueAt(entry.getIdentifier(), 0); + Collection<ExecuteAppletAction> l = as.getActions(); + for (ExecuteAppletAction o : l) { if (o.equals(ExecuteAppletAction.ALWAYS)) { return true; } @@ -969,8 +968,9 @@ @Override public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) { - for (int i = 0; i < AppletSecurityActions.REMEMBER_COLUMNS_COUNT; i++) { - ExecuteAppletAction o = (ExecuteAppletAction) entry.getModel().getValueAt(entry.getIdentifier(), i); + AppletSecurityActions as = (AppletSecurityActions) entry.getModel().getValueAt(entry.getIdentifier(), 0); + Collection<ExecuteAppletAction> l = as.getActions(); + for (ExecuteAppletAction o : l) { if (o.equals(ExecuteAppletAction.NEVER)) { return true; } @@ -983,8 +983,9 @@ @Override public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) { - for (int i = 0; i < AppletSecurityActions.REMEMBER_COLUMNS_COUNT; i++) { - ExecuteAppletAction o = (ExecuteAppletAction) entry.getModel().getValueAt(entry.getIdentifier(), i); + AppletSecurityActions as = (AppletSecurityActions) entry.getModel().getValueAt(entry.getIdentifier(), 0); + Collection<ExecuteAppletAction> l = as.getActions(); + for (ExecuteAppletAction o : l) { if (o.equals(ExecuteAppletAction.YES) || o.equals(ExecuteAppletAction.NO)) { return true; } @@ -997,8 +998,9 @@ @Override public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) { - for (int i = 0; i < AppletSecurityActions.REMEMBER_COLUMNS_COUNT; i++) { - ExecuteAppletAction o = (ExecuteAppletAction) entry.getModel().getValueAt(entry.getIdentifier(), i); + AppletSecurityActions as = (AppletSecurityActions) entry.getModel().getValueAt(entry.getIdentifier(), 0); + Collection<ExecuteAppletAction> l = as.getActions(); + for (ExecuteAppletAction o : l) { if (o.equals(ExecuteAppletAction.YES)) { return true; } @@ -1012,8 +1014,9 @@ @Override public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) { - for (int i = 0; i < AppletSecurityActions.REMEMBER_COLUMNS_COUNT; i++) { - ExecuteAppletAction o = (ExecuteAppletAction) entry.getModel().getValueAt(entry.getIdentifier(), i); + AppletSecurityActions as = (AppletSecurityActions) entry.getModel().getValueAt(entry.getIdentifier(), 0); + Collection<ExecuteAppletAction> l = as.getActions(); + for (ExecuteAppletAction o : l) { if (o.equals(ExecuteAppletAction.NO)) { return true; }
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Fri Jun 12 16:49:07 2015 +0200 @@ -1092,10 +1092,8 @@ APPEXTSECunsignedAppletActionYes=This applet was visited and allowed APPEXTSecunsignedAppletActionSandbox=This applet was visited and allowed to run with restricted privileges APPEXTSECunsignedAppletActionNo=This applet was visited and denied -APPEXTSECunsetAppletAction=This applet has not yet asked for this action APPEXTSECControlPanelExtendedAppletSecurityTitle=Extended applet security -APPEXTSECguiTableModelTableColumnActionUA=Unsigned applet Action -APPEXTSECguiTableModelTableColumnActionMatchALACA=Library Action +APPEXTSECguiTableModelTableColumnRD=Remembered decisions APPEXTSECguiTableModelTableColumnDateOfAction=Date of action APPEXTSECguiTableModelTableColumnDocumentBase=Document-base APPEXTSECguiTableModelTableColumnCodeBase=Code-base
--- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java Fri Jun 12 16:49:07 2015 +0200 @@ -185,7 +185,7 @@ return; } AccessWarningPaneComplexReturn ics = getComplexReturn(sd); - if (ics.toBoolean()) { + if (ics !=null && ics.toBoolean()) { entry.createDesktopShortcuts(ics.getMenu(), ics.getDekstop(), isSigned()); }
--- a/netx/net/sourceforge/jnlp/security/SecurityDialogMessageHandler.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogMessageHandler.java Fri Jun 12 16:49:07 2015 +0200 @@ -41,6 +41,10 @@ import java.awt.event.ActionListener; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; +import net.sourceforge.jnlp.security.dialogs.remember.RememberDialog; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; +import net.sourceforge.jnlp.security.dialogs.remember.SavedRememberAction; import sun.awt.AppContext; @@ -63,7 +67,7 @@ * {@link SecurityDialogMessage#userResponse} to the appropriate value. * </p> */ -public final class SecurityDialogMessageHandler implements Runnable { +public class SecurityDialogMessageHandler implements Runnable { /** the queue of incoming messages to show security dialogs */ private BlockingQueue<SecurityDialogMessage> queue = new LinkedBlockingQueue<SecurityDialogMessage>(); @@ -96,31 +100,50 @@ * @param message the message indicating what type of security dialog to * show */ - private void handleMessage(SecurityDialogMessage message) { - final SecurityDialogMessage msg = message; + protected void handleMessage(final SecurityDialogMessage message) { final SecurityDialog dialog = new SecurityDialog(message.dialogType, message.accessType, message.file, message.certVerifier, message.certificate, message.extras); - - dialog.addActionListener(new ActionListener() { + + final RememberableDialog found = RememberDialog.getInstance().findRememberablePanel(dialog); + SavedRememberAction action = null; + if (found!=null){ + action = RememberDialog.getInstance().getRememberedState(found); + } + if (action != null && action.isRemember()) { + message.userResponse = found.readValue(action.getSavedValue()); + UnsignedAppletTrustConfirmation.updateAppletAction(found.getFile(), action, null, (Class<RememberableDialog>) found.getClass()); + unlockMessagesClient(message); + } else { + dialog.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - msg.userResponse = dialog.getValue(); - /* Allow the client to continue on the other side */ - if (msg.toDispose != null) { - msg.toDispose.dispose(); + @Override + public void actionPerformed(ActionEvent e) { + if (found == null) { + message.userResponse = dialog.getValue(); + } else { + message.userResponse = found.getValue(); + RememberDialog.getInstance().setOrUpdateRememberedState(dialog); + } + unlockMessagesClient(message); } - if (msg.lock != null) { - msg.lock.release(); - } - } - }); - dialog.setVisible(true); + + }); + dialog.setVisible(true); + } } - /** + protected void unlockMessagesClient(final SecurityDialogMessage msg) { + /* Allow the client to continue on the other side */ + if (msg.toDispose != null) { + msg.toDispose.dispose(); + } + if (msg.lock != null) { + msg.lock.release(); + } + } + /** * Post a message to the security event queue. This message will be picked * up by the security thread and used to show the appropriate security * dialog.
--- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Fri Jun 12 16:49:07 2015 +0200 @@ -54,16 +54,12 @@ import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPClassLoader.SecurityDelegate; import net.sourceforge.jnlp.runtime.JNLPRuntime; -import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; -import static net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation.getStoredAction; import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; import net.sourceforge.jnlp.security.dialogresults.DialogResult; import net.sourceforge.jnlp.security.dialogresults.NamePassword; +import net.sourceforge.jnlp.security.dialogresults.YesNo; import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; -import net.sourceforge.jnlp.security.dialogs.remember.AppSigningWarningAction; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; -import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandboxLimited; import net.sourceforge.jnlp.util.UrlUtils; import net.sourceforge.jnlp.util.logging.OutputController; @@ -150,21 +146,23 @@ * @param file the file to be base as information source for this dialogue * @return true if permission was granted by the user, false otherwise. */ - public static AppSigningWarningAction showUnsignedWarningDialog(JNLPFile file) { + public static YesNoSandboxLimited showUnsignedWarningDialog(JNLPFile file) { if (!shouldPromptUser()) { if (JNLPRuntime.isTrustAll()) { - return new AppSigningWarningAction(ExecuteAppletAction.YES, false); + return YesNoSandboxLimited.yes(); } else { - return new AppSigningWarningAction(ExecuteAppletAction.NO, false); + return YesNoSandboxLimited.no(); } } final SecurityDialogMessage message = new SecurityDialogMessage(file); message.dialogType = DialogType.UNSIGNED_WARNING; message.accessType = AccessType.UNSIGNED; + + DialogResult r = getUserResponse(message); - return ((RememberPanel.Garbage) getUserResponse(message)).getAction(); + return (YesNoSandboxLimited) r; } /** @@ -212,14 +210,14 @@ * @param securityDelegate the delegate for security atts. * @return true if permission was granted by the user, false otherwise. */ - public static AppSigningWarningAction showPartiallySignedWarningDialog(JNLPFile file, CertVerifier certVerifier, + public static YesNoSandbox showPartiallySignedWarningDialog(JNLPFile file, CertVerifier certVerifier, SecurityDelegate securityDelegate) { if (!shouldPromptUser()) { if (JNLPRuntime.isTrustAll()) { - return new AppSigningWarningAction(ExecuteAppletAction.YES, false); + return YesNoSandbox.yes(); } else { - return new AppSigningWarningAction(ExecuteAppletAction.NO, false); + return YesNoSandbox.no(); } } @@ -229,7 +227,8 @@ message.certVerifier = certVerifier; message.extras = new Object[] { securityDelegate }; - return ((RememberPanel.Garbage) getUserResponse(message)).getAction(); + DialogResult r = getUserResponse(message); + return (YesNoSandbox) r; } /** @@ -263,6 +262,7 @@ message.extras = new Object[] { host, port, prompt, type }; DialogResult response = getUserResponse(message); + OutputController.getLogger().log(OutputController.Level.MESSAGE_DEBUG, "Decided action for matching alaca at was " + response); return (NamePassword) response; } @@ -286,24 +286,17 @@ } message.extras = new Object[]{urlToShow, UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; DialogResult selectedValue = getUserResponse(message); + + OutputController.getLogger().log(OutputController.Level.MESSAGE_DEBUG, "Decided action for matching alaca at " + file.getCodeBase() + " was " + selectedValue); + + if (selectedValue == null){ + return false; + } return selectedValue.toBoolean(); } public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, Set<URL> remoteUrls) { - ExecuteAppletAction storedAction = getStoredAction(file, AppletSecurityActions.MATCHING_ALACA_ACTION); - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Stored action for matching alaca at " + file.getCodeBase() +" was " + storedAction); - - if (storedAction != null){ - if (storedAction == ExecuteAppletAction.ALWAYS){ - return true; - } - if (storedAction == ExecuteAppletAction.NEVER){ - return false; - } - } - - if (!shouldPromptUser()) { if (JNLPRuntime.isTrustAll()) { return true; @@ -312,18 +305,17 @@ } } - SecurityDialogMessage message = new SecurityDialogMessage(file); - message.dialogType = DialogType.MATCHING_ALACA; - message.extras = new Object[]{documentBase.toString(), UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; - AppSigningWarningAction selectedValue = ((RememberPanel.Garbage) getUserResponse(message)).getAction(); + SecurityDialogMessage message = new SecurityDialogMessage(file); + message.dialogType = DialogType.MATCHING_ALACA; + message.extras = new Object[]{documentBase.toString(), UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; + DialogResult selectedValue = getUserResponse(message); + OutputController.getLogger().log(OutputController.Level.MESSAGE_DEBUG, "Decided action for matching alaca at " + file.getCodeBase() + " was " + selectedValue); + if (selectedValue != null) { - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for matching alaca at " + file.getCodeBase() + " was " + selectedValue.getAction()); - UnsignedAppletTrustConfirmation.updateAppletAction(file, selectedValue.getAction(), selectedValue.rememberForCodeBase(), AppletSecurityActions.MATCHING_ALACA_ACTION); - return selectedValue.getAction() == ExecuteAppletAction.ALWAYS || selectedValue.getAction() == ExecuteAppletAction.YES; + return selectedValue.toBoolean(); } - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for matching alaca at " + file.getCodeBase() + " was " + null); return false; } @@ -341,7 +333,13 @@ SecurityDialogMessage message = new SecurityDialogMessage(file); message.dialogType = DialogType.UNSIGNED_EAS_NO_PERMISSIONS_WARNING; DialogResult selectedValue = getUserResponse(message); - return selectedValue.toBoolean(); + OutputController.getLogger().log(OutputController.Level.MESSAGE_DEBUG, "Decided action for missing permissions at " + file.getCodeBase() + " was " + selectedValue); + + if (selectedValue != null) { + return selectedValue.toBoolean(); + } + + return false; } /** * Posts the message to the SecurityThread and gets the response. Blocks
--- a/netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java Fri Jun 12 16:49:07 2015 +0200 @@ -59,6 +59,7 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; import net.sourceforge.jnlp.util.logging.OutputController; import sun.security.util.HostnameChecker; import sun.security.validator.ValidatorException; @@ -414,11 +415,15 @@ return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { - return SecurityDialogs.showCertWarningDialog( + YesNoSandbox r = SecurityDialogs.showCertWarningDialog( AccessType.UNVERIFIED, null, new HttpsCertVerifier(chain, authType, - isTrusted, hostMatched, - hostName), null).compareValue(BasicDialogValue.Primitive.YES); + isTrusted, hostMatched, + hostName), null); + if (r == null) { + return false; + } + return r.compareValue(BasicDialogValue.Primitive.YES); } }); }
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionEntry.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionEntry.java Fri Jun 12 16:49:07 2015 +0200 @@ -35,13 +35,13 @@ */ package net.sourceforge.jnlp.security.appletextendedsecurity; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Date; import java.util.List; import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; /** *
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionStorage.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionStorage.java Fri Jun 12 16:49:07 2015 +0200 @@ -36,6 +36,7 @@ package net.sourceforge.jnlp.security.appletextendedsecurity; import java.util.List; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; /** * This is abstract access to white/blacklist created from some permanent storage. @@ -69,7 +70,7 @@ * @param id of AppletSecurityAction's ExecuteAppletAction to be used for "strong" search * @return a matching unsigned applet action entry */ - public UnsignedAppletActionEntry getMatchingItem(String documentBase, String codeBase, List<String> archives, Integer id); + public UnsignedAppletActionEntry getMatchingItem(String documentBase, String codeBase, List<String> archives, Class<? extends RememberableDialog> id); /** * Shortcut {@code getMatchingItem(documentBase, null, null, null)} @@ -78,7 +79,7 @@ * @param id of AppletSecurityAction's ExecuteAppletAction to be used for "strong" search * @return a matching unsigned applet action entry */ - public UnsignedAppletActionEntry getMatchingItemByDocumentBase(String documentBase, Integer id); + public UnsignedAppletActionEntry getMatchingItemByDocumentBase(String documentBase, Class<? extends RememberableDialog> id); /** * Shortcut {@code getMatchingItem(null, codeBase, null, null)} @@ -87,7 +88,7 @@ * @param id of AppletSecurityAction's ExecuteAppletAction to be used for "strong" search * @return a matching unsigned applet action entry */ - public UnsignedAppletActionEntry getMatchingItemByCodeBase(String codeBase, Integer id); + public UnsignedAppletActionEntry getMatchingItemByCodeBase(String codeBase, Class<? extends RememberableDialog> id); /** * Shortcut {@code getMatchingItem(documentBase, codeBase, null, null)} @@ -97,7 +98,7 @@ * @param id of AppletSecurityAction's ExecuteAppletAction to be used for "strong" search * @return a matching unsigned applet action entry */ - public UnsignedAppletActionEntry getMatchingItemByBases(String documentBase, String codeBase, Integer id); + public UnsignedAppletActionEntry getMatchingItemByBases(String documentBase, String codeBase, Class<? extends RememberableDialog> id); /** * Will add new record. Note that regexes are stored for bases matching.
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Fri Jun 12 16:49:07 2015 +0200 @@ -36,8 +36,6 @@ package net.sourceforge.jnlp.security.appletextendedsecurity; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import static net.sourceforge.jnlp.runtime.Translator.R; import java.net.URL; @@ -54,7 +52,13 @@ import net.sourceforge.jnlp.runtime.JNLPClassLoader.SecurityDelegate; import net.sourceforge.jnlp.security.CertVerifier; import net.sourceforge.jnlp.security.SecurityDialogs; -import net.sourceforge.jnlp.security.dialogs.remember.AppSigningWarningAction; +import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.YesNo; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; +import net.sourceforge.jnlp.security.dialogs.remember.SavedRememberAction; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import net.sourceforge.jnlp.util.UrlUtils; import net.sourceforge.jnlp.util.logging.OutputController; @@ -83,7 +87,7 @@ * @param id of wonted action * @return the remembered decision */ - public static UnsignedAppletActionEntry getStoredEntry(JNLPFile file, int id) { + public static UnsignedAppletActionEntry getStoredEntry(JNLPFile file, Class<? extends RememberableDialog> id) { UnsignedAppletActionStorage userActionStorage = securitySettings.getUnsignedAppletActionCustomStorage(); UnsignedAppletActionStorage globalActionStorage = securitySettings.getUnsignedAppletActionGlobalStorage(); @@ -101,7 +105,7 @@ return userEntry; } } - public static ExecuteAppletAction getStoredAction(JNLPFile file, int id) { + public static ExecuteAppletAction getStoredAction(JNLPFile file, Class<? extends RememberableDialog> id) { UnsignedAppletActionEntry x = getStoredEntry(file, id); if (x != null) { return x.getAppletSecurityActions().getAction(id); @@ -109,7 +113,7 @@ return null; } - private static UnsignedAppletActionEntry getMatchingItem(UnsignedAppletActionStorage actionStorage, JNLPFile file, int id) { + private static UnsignedAppletActionEntry getMatchingItem(UnsignedAppletActionStorage actionStorage, JNLPFile file, Class<? extends RememberableDialog> id) { return actionStorage.getMatchingItem( UrlUtils.normalizeUrlAndStripParams(file.getSourceLocation(), true /* encode local files */).toString(), UrlUtils.normalizeUrlAndStripParams(file.getCodeBase(), true /* encode local files */).toString(), @@ -129,7 +133,7 @@ return fileNames; } - public static void updateAppletAction(JNLPFile file, ExecuteAppletAction behaviour, boolean rememberForCodeBase, int id) { + public static void updateAppletAction(JNLPFile file, SavedRememberAction behaviour, Boolean rememberForCodeBase, Class<RememberableDialog> id) { UnsignedAppletActionStorage userActionStorage = securitySettings.getUnsignedAppletActionCustomStorage(); userActionStorage.lock(); // We should ensure this operation is atomic @@ -139,27 +143,37 @@ URL codebase = UrlUtils.normalizeUrlAndStripParams(file.getCodeBase(), true /* encode local files */); URL documentbase = UrlUtils.normalizeUrlAndStripParams(file.getSourceLocation(), true /* encode local files */); - /* Else, create a new entry */ - UrlRegEx codebaseRegex = new UrlRegEx("\\Q" + codebase + "\\E"); - UrlRegEx documentbaseRegex = new UrlRegEx(".*"); // Match any from codebase - List<String> archiveMatches = null; // Match any from codebase + UrlRegEx codebaseRegex = null; + UrlRegEx documentbaseRegex = null; + List<String> archiveMatches = null; + + if (rememberForCodeBase != null) { + + codebaseRegex = new UrlRegEx("\\Q" + codebase + "\\E"); + documentbaseRegex = new UrlRegEx(".*"); // Match any from codebase - if (!rememberForCodeBase) { - documentbaseRegex = new UrlRegEx("\\Q" + documentbase + "\\E"); // Match only this applet - archiveMatches = toRelativePaths(getJars(file), file.getCodeBase().toString()); // Match only this applet + if (!rememberForCodeBase) { + documentbaseRegex = new UrlRegEx("\\Q" + documentbase + "\\E"); // Match only this applet + archiveMatches = toRelativePaths(getJars(file), file.getCodeBase().toString()); // Match only this applet + } } /* Update, if entry exists */ if (oldEntry != null) { oldEntry.getAppletSecurityActions().setAction(id, behaviour); oldEntry.setTimeStamp(new Date()); - oldEntry.setDocumentBase(documentbaseRegex); - oldEntry.setCodeBase(codebaseRegex); + if (rememberForCodeBase != null) { + oldEntry.setDocumentBase(documentbaseRegex); + oldEntry.setCodeBase(codebaseRegex); + } oldEntry.setArchives(archiveMatches); userActionStorage.update(oldEntry); return; } - + if (rememberForCodeBase == null){ + throw new RuntimeException("Trying to create new entry without codebase. Thats forbidden."); + } + /* Else, create a new entry */ UnsignedAppletActionEntry entry = new UnsignedAppletActionEntry( AppletSecurityActions.fromAction(id, behaviour), new Date(), @@ -198,30 +212,11 @@ return; } - ExecuteAppletAction storedAction = getStoredAction(file, AppletSecurityActions.UNSIGNED_APPLET_ACTION); - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Stored action for unsigned applet at " + file.getCodeBase() +" was " + storedAction); - - boolean appletOK; + YesNo warningResponse = SecurityDialogs.showUnsignedWarningDialog(file); - if (storedAction == ExecuteAppletAction.ALWAYS) { - appletOK = true; - } else if (storedAction == ExecuteAppletAction.NEVER) { - appletOK = false; - } else { - // No remembered decision, prompt the user - AppSigningWarningAction warningResponse = SecurityDialogs.showUnsignedWarningDialog(file); - ExecuteAppletAction executeAction = warningResponse.getAction(); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for unsigned applet at " + file.getCodeBase() + " was " + warningResponse); - appletOK = (executeAction == ExecuteAppletAction.YES || executeAction == ExecuteAppletAction.ALWAYS); - - if (executeAction != null) { - updateAppletAction(file, executeAction, warningResponse.rememberForCodeBase(), AppletSecurityActions.UNSIGNED_APPLET_ACTION); - } - - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for unsigned applet at " + file.getCodeBase() +" was " + executeAction); - } - - if (!appletOK) { + if (warningResponse == null || !warningResponse.compareValue(BasicDialogValue.Primitive.YES)) { throw new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LUnsignedApplet"), R("LUnsignedAppletUserDenied")); } @@ -245,36 +240,17 @@ return; } - ExecuteAppletAction storedAction = getStoredAction(file, AppletSecurityActions.UNSIGNED_APPLET_ACTION); - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Stored action for partially signed applet at " + file.getCodeBase() + " was " + storedAction); - - boolean appletOK; - - if (storedAction == ExecuteAppletAction.ALWAYS) { - appletOK = true; - } else if (storedAction == ExecuteAppletAction.NEVER) { - appletOK = false; - } else { - // No remembered decision, prompt the user - AppSigningWarningAction warningResponse = SecurityDialogs.showPartiallySignedWarningDialog(file, certVerifier, securityDelegate); - ExecuteAppletAction executeAction = warningResponse.getAction(); + YesNoSandbox warningResponse = SecurityDialogs.showPartiallySignedWarningDialog(file, certVerifier, securityDelegate); - if (executeAction == ExecuteAppletAction.SANDBOX) { - securityDelegate.setRunInSandbox(); - } - - appletOK = (executeAction == ExecuteAppletAction.YES || executeAction == ExecuteAppletAction.ALWAYS - || executeAction == ExecuteAppletAction.SANDBOX); - - if (executeAction != null) { - updateAppletAction(file, executeAction, warningResponse.rememberForCodeBase(),AppletSecurityActions.UNSIGNED_APPLET_ACTION); - } - - OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for unsigned applet at " + file.getCodeBase() + " was " + executeAction); + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for unsigned applet at " + file.getCodeBase() + " was " + warningResponse); + + if (warningResponse == null || warningResponse.compareValue(BasicDialogValue.Primitive.NO)) { + throw new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LPartiallySignedApplet"), R("LPartiallySignedAppletUserDenied")); } - - if (!appletOK) { - throw new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LPartiallySignedApplet"), R("LPartiallySignedAppletUserDenied")); + + //this is due to possible YesNoSandboxLimited + if (YesNoSandbox.sandbox().compareValue(warningResponse)) { + securityDelegate.setRunInSandbox(); } }
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java Fri Jun 12 16:49:07 2015 +0200 @@ -38,10 +38,10 @@ import java.io.File; import java.io.IOException; import java.util.Date; +import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; +import net.sourceforge.jnlp.security.appletextendedsecurity.UrlRegEx; import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; -import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; -import net.sourceforge.jnlp.security.appletextendedsecurity.UrlRegEx; import net.sourceforge.jnlp.util.lockingfile.StorageIoException; public class UnsignedAppletActionStorageExtendedImpl extends UnsignedAppletActionStorageImpl { @@ -90,12 +90,12 @@ UnsignedAppletActionEntry unsignedAppletActionEntry = items.get(i); AppletSecurityActions actions = unsignedAppletActionEntry.getAppletSecurityActions(); for (int j = 0; j < actions.getRealCount(); j++) { - ExecuteAppletAction action = actions.getAction(j); - if (action == unsignedAppletAction) { - items.remove(i); - i--; - break; //actions loop - } +// ExecuteAppletAction action = actions.getAction(j); +// if (action == unsignedAppletAction) { +// items.remove(i); +// i--; +// break; //actions loop +// } } } writeContents(); @@ -155,6 +155,7 @@ public void modify(final UnsignedAppletActionEntry source, final int columnIndex, final Object aValue) { Runnable r = new Runnable() { + @Override public void run() { try { @@ -163,21 +164,18 @@ } if (columnIndex == 0) { - source.getAppletSecurityActions().setUnsignedAppletAction((ExecuteAppletAction) aValue); + source.getAppletSecurityActions().refresh((String) aValue); } if (columnIndex == 1) { - source.getAppletSecurityActions().setMatchingAlacaAction((ExecuteAppletAction) aValue); - } - if (columnIndex == 2) { source.setTimeStamp((Date) aValue); } + if (columnIndex == 2) { + source.setDocumentBase(new UrlRegEx((String) aValue)); + } if (columnIndex == 3) { - source.setDocumentBase(new UrlRegEx((String) aValue)); + source.setCodeBase(new UrlRegEx((String) aValue)); } if (columnIndex == 4) { - source.setCodeBase(new UrlRegEx((String) aValue)); - } - if (columnIndex == 5) { source.setArchives(UnsignedAppletActionEntry.createArchivesList((String) aValue)); }
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImpl.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImpl.java Fri Jun 12 16:49:07 2015 +0200 @@ -41,9 +41,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionStorage; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import net.sourceforge.jnlp.util.lockingfile.LockingReaderWriter; import net.sourceforge.jnlp.util.lockingfile.StorageIoException; @@ -131,7 +132,7 @@ } @Override - public UnsignedAppletActionEntry getMatchingItem(String documentBase, String codeBase, List<String> archives, Integer id) { + public UnsignedAppletActionEntry getMatchingItem(String documentBase, String codeBase, List<String> archives, Class<? extends RememberableDialog> id) { List<UnsignedAppletActionEntry> results = getMatchingItems(documentBase, codeBase, archives); if (results == null || results.isEmpty()) { return null; @@ -155,7 +156,7 @@ } public List<UnsignedAppletActionEntry> getMatchingItems(String documentBase, String codeBase, List<String> archives) { - List<UnsignedAppletActionEntry> result = new ArrayList<UnsignedAppletActionEntry>(); + List<UnsignedAppletActionEntry> result = new ArrayList<>(); lock(); try { readContents(); @@ -232,17 +233,17 @@ } @Override - public UnsignedAppletActionEntry getMatchingItemByDocumentBase(String documentBase, Integer id) { + public UnsignedAppletActionEntry getMatchingItemByDocumentBase(String documentBase, Class<? extends RememberableDialog> id) { return getMatchingItem(documentBase, null, null, id); } - + @Override - public UnsignedAppletActionEntry getMatchingItemByCodeBase(String codeBase, Integer id) { + public UnsignedAppletActionEntry getMatchingItemByCodeBase(String codeBase, Class<? extends RememberableDialog> id) { return getMatchingItem(null, codeBase, null, id); } @Override - public UnsignedAppletActionEntry getMatchingItemByBases(String documentBase, String codeBase, Integer id) { + public UnsignedAppletActionEntry getMatchingItemByBases(String documentBase, String codeBase, Class<? extends RememberableDialog> id) { return getMatchingItem(documentBase, codeBase, null, id); } }
--- a/netx/net/sourceforge/jnlp/security/dialogresults/AccessWarningPaneComplexReturn.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/AccessWarningPaneComplexReturn.java Fri Jun 12 16:49:07 2015 +0200 @@ -1,7 +1,3 @@ -package net.sourceforge.jnlp.security.dialogresults; - -import java.util.Objects; - /* Copyright (C) 2008 Red Hat, Inc. @@ -38,6 +34,10 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ +package net.sourceforge.jnlp.security.dialogresults; + +import java.util.Objects; + public class AccessWarningPaneComplexReturn implements DialogResult { public static AccessWarningPaneComplexReturn readValue(String s) { @@ -45,8 +45,14 @@ BasicDialogValue.Primitive regularReturn = BasicDialogValue.Primitive.valueOf(sq[0]); //the replace is fixing case of not existing shortcuts at all sq = s.replace("()", "( )").split("[()]"); - ShortcutResult d = ShortcutResult.readValue(sq[1]); - ShortcutResult m = ShortcutResult.readValue(sq[3]); + ShortcutResult d = null; + if (sq.length > 1) { + d = ShortcutResult.readValue(sq[1]); + } + ShortcutResult m = null; + if (sq.length > 3) { + m = ShortcutResult.readValue(sq[3]); + } AccessWarningPaneComplexReturn a = new AccessWarningPaneComplexReturn(regularReturn); a.dekstop = d; a.menu = m; @@ -71,7 +77,7 @@ public static class ShortcutResult { public static ShortcutResult readValue(String s) { - if (s.trim().isEmpty()){ + if (s.trim().isEmpty()) { return null; } String[] sq = s.split(","); @@ -100,12 +106,12 @@ @Override public boolean equals(Object obj) { - if (!(obj instanceof ShortcutResult)){ + if (!(obj instanceof ShortcutResult)) { return false; } - ShortcutResult sr = (ShortcutResult) obj; + ShortcutResult sr = (ShortcutResult) obj; return this.create == sr.create && this.fixHref == sr.fixHref - && this.browser.equals(sr.browser) && this.shortcutType == sr.shortcutType; + && this.browser.equals(sr.browser) && this.shortcutType == sr.shortcutType; } @Override @@ -117,20 +123,19 @@ hash = 89 * hash + (this.create ? 1 : 0); return hash; } - private String browser = "not_found_browser"; private boolean fixHref = false; private Shortcut shortcutType = null; private final boolean create; - ShortcutResult(String browser, boolean fixHref,Shortcut shortcutType, boolean create){ + ShortcutResult(String browser, boolean fixHref, Shortcut shortcutType, boolean create) { this.browser = browser; this.fixHref = fixHref; this.shortcutType = shortcutType; this.create = create; } - + public ShortcutResult(boolean create) { this.create = create; } @@ -171,9 +176,9 @@ public AccessWarningPaneComplexReturn(boolean b) { if (b) { - this.regularReturn = YesNo.yes(); + this.regularReturn = YesNo.yes(); } else { - this.regularReturn = YesNo.no(); + this.regularReturn = YesNo.no(); } } @@ -202,7 +207,7 @@ if (regularReturn == null) { return false; } - return regularReturn.toBoolean(); + return regularReturn.toBoolean(); } public YesNo getRegularReturn() { @@ -218,15 +223,4 @@ } } - public static enum RemeberType { -//TODO - remove! - REMEMBER_BY_APP, REMEMBER_BY_DOMAIN, REMEMBER_DONT; - } - //same - private RemeberType rember; -//same - public void setRember(RemeberType rember) { - this.rember = rember; - } - }
--- a/netx/net/sourceforge/jnlp/security/dialogresults/BasicDialogValue.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/BasicDialogValue.java Fri Jun 12 16:49:07 2015 +0200 @@ -34,7 +34,6 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package net.sourceforge.jnlp.security.dialogresults; import java.util.EnumSet; @@ -94,20 +93,40 @@ public BasicDialogValue.Primitive getValue() { return value; } - + public boolean compareValue(Primitive with) { - if (getValue() == null && with ==null){ + if (getValue() == null && with == null) { return true; } checkValue(with); return getValue() == with; } + public boolean compareValue(PrimitivesSubset with) { + if (with == null) { + return false; + } + return compareValue(with.getValue()); + } + @Override public int getButtonIndex() { return BasicDialogValue.Primitive.NO.getLegacyButton(); } + @Override + public boolean equals(Object obj) { + if (obj instanceof PrimitivesSubset) { + return this.compareValue(((PrimitivesSubset) obj)); + } + return false; + } + + @Override + public int hashCode() { + return getValue().hashCode(); + } + } public static final EnumSet<Primitive> Yes = EnumSet.of(Primitive.YES);
--- a/netx/net/sourceforge/jnlp/security/dialogresults/Yes.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/Yes.java Fri Jun 12 16:49:07 2015 +0200 @@ -53,6 +53,15 @@ public Yes() { super(BasicDialogValue.Primitive.YES); } + + /** + * To allow inheritance. + * Overriders have to override getAllowedValues to work. + * This one fails with anything else then Yes + */ + protected Yes(BasicDialogValue.Primitive p) { + super(p); + } @Override public int getButtonIndex() { @@ -64,4 +73,11 @@ return BasicDialogValue.Yes; } + @Override + public String toString() { + return writeValue(); + } + + + }
--- a/netx/net/sourceforge/jnlp/security/dialogresults/YesCancel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesCancel.java Fri Jun 12 16:49:07 2015 +0200 @@ -38,12 +38,12 @@ import java.util.EnumSet; -public class YesCancel extends BasicDialogValue.PrimitivesSubset { +public class YesCancel extends Yes { public static YesCancel yes() { return new YesCancel(BasicDialogValue.Primitive.YES); } - + public static YesCancel cancel() { return new YesCancel(BasicDialogValue.Primitive.CANCEL); }
--- a/netx/net/sourceforge/jnlp/security/dialogresults/YesNo.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNo.java Fri Jun 12 16:49:07 2015 +0200 @@ -38,7 +38,7 @@ import java.util.EnumSet; -public class YesNo extends BasicDialogValue.PrimitivesSubset { +public class YesNo extends Yes { public static YesNo yes() { return new YesNo(BasicDialogValue.Primitive.YES);
--- a/netx/net/sourceforge/jnlp/security/dialogresults/YesNoCancel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNoCancel.java Fri Jun 12 16:49:07 2015 +0200 @@ -38,7 +38,7 @@ import java.util.EnumSet; -public class YesNoCancel extends BasicDialogValue.PrimitivesSubset { +public class YesNoCancel extends YesNo { public static YesNoCancel yes() { return new YesNoCancel(BasicDialogValue.Primitive.YES);
--- a/netx/net/sourceforge/jnlp/security/dialogresults/YesNoSandbox.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNoSandbox.java Fri Jun 12 16:49:07 2015 +0200 @@ -38,7 +38,7 @@ import java.util.EnumSet; -public class YesNoSandbox extends BasicDialogValue.PrimitivesSubset { +public class YesNoSandbox extends YesNo { public static YesNoSandbox yes() { return new YesNoSandbox(BasicDialogValue.Primitive.YES); @@ -56,7 +56,7 @@ return new YesNoSandbox(BasicDialogValue.Primitive.valueOf(s)); } - private YesNoSandbox(BasicDialogValue.Primitive valueOf) { + protected YesNoSandbox(BasicDialogValue.Primitive valueOf) { super(valueOf); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNoSandboxLimited.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,75 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ +package net.sourceforge.jnlp.security.dialogresults; + +import java.util.EnumSet; + +/** + * Special case for AppTrustWarningPanel extensions. + * Its behaviour is same as YesNo, but if soem extension Need sandbox, it can safely use + * YesNoSandbox, and it will be correctly eaten. + * + */ + +public class YesNoSandboxLimited extends YesNoSandbox { + + public static YesNoSandboxLimited yes() { + return new YesNoSandboxLimited(BasicDialogValue.Primitive.YES); + } + + public static YesNoSandboxLimited no() { + return new YesNoSandboxLimited(BasicDialogValue.Primitive.NO); + } + + public static YesNoSandboxLimited sandbox() { + return new YesNoSandboxLimited(BasicDialogValue.Primitive.SANDBOX); + } + + public static YesNoSandboxLimited readValue(String s) { + return new YesNoSandboxLimited(BasicDialogValue.Primitive.valueOf(s)); + } + + private YesNoSandboxLimited(BasicDialogValue.Primitive valueOf) { + super(valueOf); + } + + @Override + public EnumSet<BasicDialogValue.Primitive> getAllowedValues() { + return BasicDialogValue.YesNo; + } + +}
--- a/netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPane.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPane.java Fri Jun 12 16:49:07 2015 +0200 @@ -73,6 +73,9 @@ import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanelResult; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import net.sourceforge.jnlp.util.FileUtils; import net.sourceforge.jnlp.util.XDesktopEntry; @@ -84,7 +87,7 @@ * * @author <a href="mailto:jsumali@redhat.com">Joshua Sumali</a> */ -public class AccessWarningPane extends SecurityDialogPanel { +public class AccessWarningPane extends SecurityDialogPanel implements RememberableDialog{ private Object[] extras; private JCheckBox desktopCheck; @@ -294,8 +297,6 @@ } } ); - //override the createSetValueListener mechanism - //TODO get rid of createSetValueListener completely. run.addActionListener(new ActionListener() { @Override @@ -349,17 +350,10 @@ ar.setMenu(new AccessWarningPaneComplexReturn.ShortcutResult(menuCheck.isSelected())); } } - if (rememberPanel != null) { - ar.setRember(rememberPanel.getShortcutResult()); - } return ar; } private class RememberPanel extends JPanel { - // TODO: somehow tell the ApplicationInstance - // to stop asking for permission - // will be implemented likeALACAcanrember decission - // must be encoded in similar way as AWP is doing final JRadioButton byApp = new JRadioButton(R("EXAWrememberByApp")); final JRadioButton byPage = new JRadioButton(R("EXAWrememberByPage")); @@ -382,16 +376,15 @@ } - public AccessWarningPaneComplexReturn.RemeberType getShortcutResult() { - if (byApp.isSelected()) { - return AccessWarningPaneComplexReturn.RemeberType.REMEMBER_BY_APP; - } else if (byPage.isSelected()) { - return AccessWarningPaneComplexReturn.RemeberType.REMEMBER_BY_DOMAIN; - } else if (dont.isSelected()) { - return AccessWarningPaneComplexReturn.RemeberType.REMEMBER_DONT; - } else { - return AccessWarningPaneComplexReturn.RemeberType.REMEMBER_DONT; - } + private boolean isRemembered(){ + return !dont.isSelected(); + } + private boolean isRememebredForCodebase(){ + return byPage.isSelected(); + } + + private RememberPanelResult getResult() { + return new RememberPanelResult(isRemembered(), isRememebredForCodebase()); } } @@ -494,5 +487,29 @@ } } + + + @Override + public RememberPanelResult getRemeberAction() { + return rememberPanel.getResult(); + } + + @Override + public DialogResult getValue() { + return parent.getValue(); + } + + @Override + public JNLPFile getFile() { + return parent.getFile(); + } + + @Override + public DialogResult readValue(String s) { + return AccessWarningPaneComplexReturn.readValue(s); + } + + + }
--- a/netx/net/sourceforge/jnlp/security/dialogs/MissingALACAttributePanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/MissingALACAttributePanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -62,18 +62,25 @@ import javax.swing.SwingConstants; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.security.SecurityDialog; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; import net.sourceforge.jnlp.security.dialogresults.YesNo; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanelResult; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import net.sourceforge.jnlp.util.UrlUtils; import net.sourceforge.jnlp.util.logging.OutputController; /** * http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/manifest.html#app_library */ -public class MissingALACAttributePanel extends SecurityDialogPanel { +public class MissingALACAttributePanel extends SecurityDialogPanel implements RememberableDialog{ + private RememberPanel rememberPanel; + public MissingALACAttributePanel(SecurityDialog x, String title, String codebase, String remoteUrls) { super(x); try { @@ -134,6 +141,7 @@ Dimension d = new Dimension(buttonWidth, buttonHeight); yes.setPreferredSize(d); no.setPreferredSize(d); + rememberPanel = new RememberPanel(codebase); yes.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.yes())); no.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.no())); initialFocusComponent = no; @@ -145,7 +153,9 @@ add(topPanel); add(infoPanel); add(buttonPanel); - + + + add(rememberPanel); } public static void main(String[] args) throws MalformedURLException { @@ -159,4 +169,26 @@ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } + + + @Override + public RememberPanelResult getRemeberAction() { + return rememberPanel.getRememberAction(); + } + + @Override + public DialogResult getValue() { + return parent.getValue(); + } + + + @Override + public JNLPFile getFile() { + return parent.getFile(); + } + + @Override + public DialogResult readValue(String s) { + return YesNo.readValue(s); + } }
--- a/netx/net/sourceforge/jnlp/security/dialogs/MissingPermissionsAttributePanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/MissingPermissionsAttributePanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -59,15 +59,22 @@ import javax.swing.SwingConstants; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.security.SecurityDialog; import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; import net.sourceforge.jnlp.security.dialogresults.YesNo; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanelResult; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import net.sourceforge.jnlp.util.logging.OutputController; -public class MissingPermissionsAttributePanel extends SecurityDialogPanel { +public class MissingPermissionsAttributePanel extends SecurityDialogPanel implements RememberableDialog{ + private RememberPanel rememberPanel; + public MissingPermissionsAttributePanel(SecurityDialog x, String title, String codebase) { super(x); try { @@ -76,7 +83,7 @@ throw new RuntimeException(ex); } if (x != null) { - x.setMinimumSize(new Dimension(400, 300)); + x.setMinimumSize(new Dimension(400, 400)); } } @@ -130,6 +137,7 @@ Dimension d = new Dimension(buttonWidth, buttonHeight); yes.setPreferredSize(d); no.setPreferredSize(d); + rememberPanel = new RememberPanel(codebase); yes.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.yes())); no.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.no())); initialFocusComponent = no; @@ -141,15 +149,39 @@ add(topPanel); add(infoPanel); add(buttonPanel); + add(rememberPanel); + validate(); } public static void main(String[] args) { MissingPermissionsAttributePanel w = new MissingPermissionsAttributePanel(null, "HelloWorld", "http://nbblah.url"); JFrame f = new JFrame(); - f.setSize(400, 300); + f.setSize(400, 400); f.add(w, BorderLayout.CENTER); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } + + @Override + public RememberPanelResult getRemeberAction() { + return rememberPanel.getRememberAction(); + } + + @Override + public DialogResult getValue() { + return parent.getValue(); + } + + @Override + public JNLPFile getFile() { + return parent.getFile(); + } + + @Override + public DialogResult readValue(String s) { + return YesNo.readValue(s); + } + + }
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -65,9 +65,15 @@ import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.PluginBridge; import static net.sourceforge.jnlp.runtime.Translator.R; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.SecurityDialog; import net.sourceforge.jnlp.security.appletextendedsecurity.ExtendedAppletSecurityHelp; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.YesNo; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandboxLimited; import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanelResult; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import net.sourceforge.jnlp.util.ScreenFinder; import net.sourceforge.jnlp.util.logging.OutputController; @@ -79,7 +85,7 @@ * plugin applets. New implementations should be added to the unit test at * unit/net/sourceforge/jnlp/security/AppTrustWarningPanelTest */ -public abstract class AppTrustWarningPanel extends JPanel { +public abstract class AppTrustWarningPanel extends JPanel implements RememberableDialog{ protected int PANE_WIDTH = 500; @@ -94,16 +100,15 @@ protected JButton helpButton; protected RememberPanel rememberPanel; - protected JNLPFile file; - - + protected SecurityDialog parent; /* * Subclasses should call addComponents() IMMEDIATELY after calling the super() constructor! */ - public AppTrustWarningPanel(JNLPFile file) { + public AppTrustWarningPanel(JNLPFile file, SecurityDialog securityDialog) { this.file = file; + this.parent = securityDialog; rememberPanel = new RememberPanel(file.getCodeBase()); this.buttons = new ArrayList<>(); @@ -111,9 +116,12 @@ rejectButton = new JButton(R("ButCancel")); helpButton = new JButton(R("APPEXTSECguiPanelHelpButton")); - allowButton.addActionListener(rememberPanel.chosenActionSetter(ExecuteAppletAction.YES)); - rejectButton.addActionListener(rememberPanel.chosenActionSetter(ExecuteAppletAction.NO)); + allowButton.addActionListener(SetValueHandler.createSetValueListener(parent, + YesNoSandboxLimited.yes())); + rejectButton.addActionListener(SetValueHandler.createSetValueListener(parent, + YesNoSandboxLimited.no())); + helpButton.addActionListener(getHelpButtonAction()); buttons.add(allowButton); @@ -162,8 +170,6 @@ }; } - - private void setupTopPanel() { final String topLabelText = getTopPanelText(); @@ -240,7 +246,6 @@ add(questionPanel); } - private JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); @@ -263,8 +268,9 @@ } /** - * Creates the actual GUI components, and adds it to this panel. This should be called by all subclasses - * IMMEDIATELY after calling the super() constructor! + * Creates the actual GUI components, and adds it to this panel. This should + * be called by all subclasses IMMEDIATELY after calling the super() + * constructor! */ protected final void addComponents() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); @@ -275,4 +281,23 @@ setupButtonAndCheckBoxPanel(); } + @Override + public RememberPanelResult getRemeberAction() { + return rememberPanel.getRememberAction(); + } + + @Override + public JNLPFile getFile() { + return file; + } + + @Override + public DialogResult getValue() { + return parent.getValue(); + } + + @Override + public DialogResult readValue(String s) { + return YesNoSandboxLimited.readValue(s); + } }
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/MatchingALACAttributePanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/MatchingALACAttributePanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -50,10 +50,9 @@ import net.sourceforge.jnlp.runtime.Translator; import static net.sourceforge.jnlp.runtime.Translator.R; import net.sourceforge.jnlp.security.SecurityDialog; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; import net.sourceforge.jnlp.util.UrlUtils; @@ -66,15 +65,15 @@ private final String codebase; private final String remoteUrls; - public MatchingALACAttributePanel(SecurityDialog x, JNLPFile file, String codebase, String remoteUrls) { - super(file); + public MatchingALACAttributePanel(SecurityDialog securityDialog, JNLPFile file, String codebase, String remoteUrls) { + super(file, securityDialog); this.title = super.getAppletTitle(); this.codebase = codebase; this.remoteUrls = remoteUrls; TOP_PANEL_HEIGHT = 250; addComponents(); - if (x != null) { - x.setMinimumSize(new Dimension(600, 400)); + if (securityDialog != null) { + securityDialog.setMinimumSize(new Dimension(600, 400)); } } @@ -92,9 +91,9 @@ @Override protected String getInfoPanelText() { String r = Translator.R("ALACAMatchingInfo"); - UnsignedAppletActionEntry rememberedEntry = UnsignedAppletTrustConfirmation.getStoredEntry(file, AppletSecurityActions.MATCHING_ALACA_ACTION); + UnsignedAppletActionEntry rememberedEntry = UnsignedAppletTrustConfirmation.getStoredEntry(file, this.getClass()); if (rememberedEntry != null) { - ExecuteAppletAction rememberedAction = rememberedEntry.getAppletSecurityActions().getMatchingAlacaAction(); + ExecuteAppletAction rememberedAction = rememberedEntry.getAppletSecurityActions().getAction(this.getClass()); if (rememberedAction == ExecuteAppletAction.YES) { r += "<br>" + R("SUnsignedAllowedBefore", rememberedEntry.getLocalisedTimeStamp()); } else if (rememberedAction == ExecuteAppletAction.NO) {
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -36,9 +36,9 @@ package net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel; -import java.awt.Dimension; import static net.sourceforge.jnlp.runtime.Translator.R; +import java.awt.Dimension; import java.security.cert.Certificate; import java.security.cert.X509Certificate; @@ -52,8 +52,10 @@ import net.sourceforge.jnlp.security.SecurityUtil; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; import net.sourceforge.jnlp.security.dialogs.TemporaryPermissionsButton; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; import net.sourceforge.jnlp.tools.CertInformation; @@ -66,14 +68,14 @@ private final JButton advancedOptionsButton; public PartiallySignedAppTrustWarningPanel(JNLPFile file, SecurityDialog securityDialog, SecurityDelegate securityDelegate) { - super(file); + super(file, securityDialog); this.jcv = (JarCertVerifier) securityDialog.getCertVerifier(); this.INFO_PANEL_HEIGHT = 250; sandboxButton = new JButton(); sandboxButton.setText(R("ButSandbox")); - sandboxButton.addActionListener(rememberPanel.chosenActionSetter(ExecuteAppletAction.SANDBOX)); - + sandboxButton.addActionListener(SetValueHandler.createSetValueListener(parent, + YesNoSandbox.sandbox())); advancedOptionsButton = new TemporaryPermissionsButton(file, securityDelegate, sandboxButton); buttons.add(1, sandboxButton); @@ -148,9 +150,9 @@ String text = getAppletInfo(); text += "<br><br>" + R(getInfoPanelTextKey(), file.getCodeBase(), file.getSourceLocation()); text += "<br><br>" + getSigningInfo(); - UnsignedAppletActionEntry rememberedEntry = UnsignedAppletTrustConfirmation.getStoredEntry(file, AppletSecurityActions.UNSIGNED_APPLET_ACTION); + UnsignedAppletActionEntry rememberedEntry = UnsignedAppletTrustConfirmation.getStoredEntry(file, this.getClass()); if (rememberedEntry != null) { - ExecuteAppletAction rememberedAction = rememberedEntry.getAppletSecurityActions().getUnsignedAppletAction(); + ExecuteAppletAction rememberedAction = rememberedEntry.getAppletSecurityActions().getAction(this.getClass()); if (rememberedAction == ExecuteAppletAction.YES) { text += "<br>" + R("SUnsignedAllowedBefore", rememberedEntry.getLocalisedTimeStamp()); } else if (rememberedAction == ExecuteAppletAction.NO) { @@ -164,5 +166,10 @@ protected String getQuestionPanelText() { return RememberPanel.htmlWrap(R(getQuestionPanelTextKey())); } + + @Override + public DialogResult readValue(String s) { + return YesNoSandbox.readValue(s); + } }
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/UnsignedAppletTrustWarningPanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/UnsignedAppletTrustWarningPanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -36,16 +36,17 @@ package net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel; +import static net.sourceforge.jnlp.runtime.Translator.R; + import java.awt.BorderLayout; import java.awt.Dimension; import java.net.URL; -import static net.sourceforge.jnlp.runtime.Translator.R; import javax.swing.ImageIcon; import javax.swing.JFrame; + import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.security.SecurityDialog; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; @@ -55,7 +56,7 @@ public class UnsignedAppletTrustWarningPanel extends AppTrustWarningPanel { public UnsignedAppletTrustWarningPanel(SecurityDialog securityDialog, final JNLPFile file) { - super(file); + super(file, securityDialog); this.INFO_PANEL_HEIGHT = 250; addComponents(); if (securityDialog != null) { @@ -89,9 +90,9 @@ @Override protected String getInfoPanelText() { String text = R(getInfoPanelTextKey(), file.getCodeBase(), file.getSourceLocation()); - UnsignedAppletActionEntry rememberedEntry = UnsignedAppletTrustConfirmation.getStoredEntry(file, AppletSecurityActions.UNSIGNED_APPLET_ACTION); + UnsignedAppletActionEntry rememberedEntry = UnsignedAppletTrustConfirmation.getStoredEntry(file, this.getClass()); if (rememberedEntry != null) { - ExecuteAppletAction rememberedAction = rememberedEntry.getAppletSecurityActions().getUnsignedAppletAction(); + ExecuteAppletAction rememberedAction = rememberedEntry.getAppletSecurityActions().getAction(this.getClass()); if (rememberedAction == ExecuteAppletAction.YES) { text += "<br>" + R("SUnsignedAllowedBefore", rememberedEntry.getLocalisedTimeStamp()); } else if (rememberedAction == ExecuteAppletAction.NO) {
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/ActionChoiceListener.java Thu Jun 11 13:24:54 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - Copyright (C) 2008-2010 Red Hat, Inc. - - This file is part of IcedTea. - - IcedTea is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, version 2. - - IcedTea is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with IcedTea; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. - */ - -package net.sourceforge.jnlp.security.dialogs.remember; - -/* - * Callback for when action is decided. - */ -public interface ActionChoiceListener { - - void actionChosen(AppSigningWarningAction action); - -}
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/AppSigningWarningAction.java Thu Jun 11 13:24:54 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - Copyright (C) 2008-2010 Red Hat, Inc. - - This file is part of IcedTea. - - IcedTea is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, version 2. - - IcedTea is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with IcedTea; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. - */ -package net.sourceforge.jnlp.security.dialogs.remember; - -/* - * Details of decided action. - */ -public class AppSigningWarningAction { - private final ExecuteAppletAction action; - private final boolean applyToCodeBase; - - public AppSigningWarningAction(ExecuteAppletAction action, boolean applyToCodeBase) { - this.action = action; - this.applyToCodeBase = applyToCodeBase; - } - - public ExecuteAppletAction getAction() { - return action; - } - - public boolean rememberForCodeBase() { - return applyToCodeBase; - } - -}
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActions.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActions.java Fri Jun 12 16:49:07 2015 +0200 @@ -36,44 +36,75 @@ package net.sourceforge.jnlp.security.dialogs.remember; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; +import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; - -public class AppletSecurityActions implements Iterable<ExecuteAppletAction>{ +import java.util.Map; +import java.util.Map.Entry; +import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.MatchingALACAttributePanel; +import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.UnsignedAppletTrustWarningPanel; +import net.sourceforge.jnlp.util.logging.OutputController; - private final List<ExecuteAppletAction> actions = new ArrayList<>(); - public static final int UNSIGNED_APPLET_ACTION = 0; - public static final int MATCHING_ALACA_ACTION = 1; - /** well this si not nice. We can iterate through all the records to find - * longest remembered item, but it is unnecessary overhead. The new record is - * added willingly with some effort. Should be easy to inc also this - */ - public static final int REMEMBER_COLUMNS_COUNT = /*2*/ - Collections.max(Arrays.asList(UNSIGNED_APPLET_ACTION, MATCHING_ALACA_ACTION))+1; +//from legacy, just wrapper around map +public class AppletSecurityActions implements Iterable<SavedRememberAction> { + private final Map<String, SavedRememberAction> actions = new HashMap<>(); - public static AppletSecurityActions createDefault() { - AppletSecurityActions asas = new AppletSecurityActions(); - asas.setUnsignedAppletAction(ExecuteAppletAction.UNSET); - asas.setMatchingAlacaAction(ExecuteAppletAction.UNSET); - return asas; - } /* * quick setup method when new item , with one action, is added */ - public static AppletSecurityActions fromAction(int id, ExecuteAppletAction s) { - if (s == null){ - s = ExecuteAppletAction.UNSET; - } + public static AppletSecurityActions fromAction(Class<? extends RememberableDialog> id, SavedRememberAction s) { AppletSecurityActions asas = new AppletSecurityActions(); asas.setAction(id, s); return asas; } + /** + * + * ClassName:ACTION{savedvalue};ClassName:ACTION{savedvalue};... eg + * MatchingALACAttributePanel:A{true};PartiallySignedAppTrustWarningPanel:a{S}; + * + * @param s + * @return + */ + public static AppletSecurityActions fromString(String s) { + if (s == null) { + s = ""; + } + s = s.trim(); + AppletSecurityActions asas = new AppletSecurityActions(); + if (s.isEmpty()) { + return asas; + } + if (s.contains(";") || s.contains(":") || s.contains("{") || s.contains("}")) { + String[] ss = s.split("};"); + for (String string : ss) { + string = string.trim(); + if (string.isEmpty()) { + continue; + } + int nameIndex = string.indexOf(":"); + int valueIndex = string.indexOf("{"); + if (nameIndex < 0 || valueIndex < 0) { + continue; + } + String name = string.substring(0, nameIndex); + String action = string.substring(nameIndex + 1, valueIndex); + String value = string.substring(valueIndex + 1); //rather null if empty? if it si null, and expected, then NPE should never be thrown + if (value.isEmpty()) { + value = null; //or empty string is better. What if saved value really is empty string? + //Special sequence for null? + } + asas.actions.put(name, new SavedRememberAction(ExecuteAppletAction.fromChar(action.charAt(0)), value)); + } + return asas; + } else { + return readLegacySave(s); + } + } - public static AppletSecurityActions fromString(String s) { + private static AppletSecurityActions readLegacySave(String s) { if (s == null) { s = ""; } @@ -82,45 +113,87 @@ //does " A" means UNSET(1)+ALWAYS(2) or ALWAYS(1)+UNSET(2) //or UNSET(1)+UNSET(2)? AppletSecurityActions asas = new AppletSecurityActions(); - for (char x : s.toCharArray()){ - if (Character.isWhitespace(x)){ + int i = 0; + for (char x : s.toCharArray()) { + if (Character.isWhitespace(x)) { + break; + } + if (x == 2) { + //only two elements were known for 1.6 or older break; } - asas.actions.add(ExecuteAppletAction.fromChar(x)); + //unset is no op now + if (x == 'X') { + i++; + continue; + } + if (x == 's' || x == 'S') { + continue; + } + char nwX = x; + if (x == 's') { + nwX = 'y'; + } + if (x == 'S') { + nwX = 'A'; + } + ExecuteAppletAction q = ExecuteAppletAction.fromChar(nwX); + if (i == 0) { + SavedRememberAction sa = new SavedRememberAction(q, legacyToCurrent(x));//maybe better switch then toChar? + asas.actions.put(classToKey(UnsignedAppletTrustWarningPanel.class), sa); + } else if (i == 1) { + SavedRememberAction sa = new SavedRememberAction(q, legacyToCurrent(x));//maybe better switch then toChar? + asas.actions.put(classToKey(MatchingALACAttributePanel.class), sa); + } else { + OutputController.getLogger().log("Unknown saved legacy item on position " + i + " of char: " + x); + } + i++; } return asas; } - public ExecuteAppletAction getAction(int i) { - if (i>= actions.size()){ - return ExecuteAppletAction.UNSET; + private static String legacyToCurrent(char q) { + switch (q) { + case 'y': + case 'A': + return "YES"; + case 'n': + case 'N': + return "NO"; + case 's': + case 'S': + return "SANDBOX"; } - return actions.get(i); + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - - public void setAction(int i, ExecuteAppletAction a) { - while (actions.size() <= i){ - actions.add(ExecuteAppletAction.UNSET); - } - actions.set(i,a); + + public ExecuteAppletAction getAction(Class clazz) { + return getAction(classToKey(clazz)); } + public ExecuteAppletAction getAction(String clazz) { + SavedRememberAction o = getActionEntry(clazz); + if (o == null) { + return null; + } + return o.getAction(); + } - public ExecuteAppletAction getUnsignedAppletAction() { - return getAction(UNSIGNED_APPLET_ACTION); + public SavedRememberAction getActionEntry(Class clazz) { + return getActionEntry(classToKey(clazz)); } - public void setUnsignedAppletAction(ExecuteAppletAction a) { - setAction(UNSIGNED_APPLET_ACTION,a); + public SavedRememberAction getActionEntry(String clazz) { + return actions.get(clazz); + } - - public ExecuteAppletAction getMatchingAlacaAction() { - return getAction(MATCHING_ALACA_ACTION); + public void setAction(Class clazz, SavedRememberAction a) { + setAction(classToKey(clazz), a); } - - public void setMatchingAlacaAction(ExecuteAppletAction a) { - setAction(MATCHING_ALACA_ACTION, a); + + public void setAction(String i, SavedRememberAction a) { + actions.put(i, a); } @Override @@ -130,17 +203,18 @@ public String toLongString() { StringBuilder sb = new StringBuilder(); - for (ExecuteAppletAction executeAppletAction : actions) { - sb.append(executeAppletAction.toString()).append("; "); + Collection<Entry<String, SavedRememberAction>> l = getEntries(); + for (Entry<String, SavedRememberAction> a : l) { + sb.append(a.getKey()).append(":").append(a.getValue().toLongString()); } return sb.toString(); } - public String toShortString() { StringBuilder sb = new StringBuilder(); - for (ExecuteAppletAction executeAppletAction : actions) { - sb.append(executeAppletAction.toChar()); + Collection<Entry<String, SavedRememberAction>> l = getEntries(); + for (Entry<String, SavedRememberAction> a : l) { + sb.append(a.getKey()).append(":").append(a.getValue().toShortString()).append(";"); } return sb.toString(); } @@ -149,18 +223,40 @@ return actions.size(); } + /** + * stub for testing + * + * @return + */ + public Collection<ExecuteAppletAction> getActions() { + Collection<SavedRememberAction> col = actions.values(); + List<ExecuteAppletAction> l = new ArrayList<>(col.size()); + for (SavedRememberAction savedRememberAction : col) { + l.add(savedRememberAction.getAction()); + } + return l; + } - /** - * stub for testing - * @return - */ - List<ExecuteAppletAction> getActions() { - return actions; + public Collection<Entry<String, SavedRememberAction>> getEntries() { + return actions.entrySet(); } @Override - public Iterator<ExecuteAppletAction> iterator() { - return actions.iterator(); + public Iterator<SavedRememberAction> iterator() { + return actions.values().iterator(); + } + + /* + Simple wrapper. What there wil be need of changing this logic + */ + private static String classToKey(Class clazz) { + return clazz.getSimpleName(); + } + + public void refresh(String aValue) { + AppletSecurityActions nev = fromString(aValue); + actions.clear(); + actions.putAll(nev.actions); } }
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/ExecuteAppletAction.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/ExecuteAppletAction.java Fri Jun 12 16:49:07 2015 +0200 @@ -39,22 +39,18 @@ public enum ExecuteAppletAction { - ALWAYS, NEVER, YES, SANDBOX, NO, UNSET; + ALWAYS, NEVER, YES, NO; public String toChar() { switch (this) { case ALWAYS: return "A"; - case NEVER: - return "N"; case YES: return "y"; - case SANDBOX: - return "s"; + case NEVER: + return "N"; case NO: return "n"; - case UNSET: - return "X"; } throw new RuntimeException("Unknown ExecuteUnsignedApplet"); } @@ -67,24 +63,21 @@ return Translator.R("APPEXTSECunsignedAppletActionNever"); case YES: return Translator.R("APPEXTSECunsignedAppletActionYes"); - case SANDBOX: - return Translator.R("APPEXTSECunsignedAppletActionSandbox"); +// return Translator.R("APPEXTSECunsignedAppletActionSandbox"); deal with this string later case NO: return Translator.R("APPEXTSECunsignedAppletActionNo"); - case UNSET: - return Translator.R("APPEXTSECunsetAppletAction"); } throw new RuntimeException("Unknown UnsignedAppletAction"); } public static ExecuteAppletAction fromString(String s) { - if (s.length() == 0){ - throw new RuntimeException("Undefined zero-length ExecuteAppletAction String representatio"); + if (s.length() == 0) { + throw new RuntimeException("Undefined zero-length ExecuteAppletAction String representatio"); } return fromChar(s.charAt(0)); - + } - + public static ExecuteAppletAction fromChar(char s) { switch (s) { case 'A': @@ -93,12 +86,8 @@ return ExecuteAppletAction.NEVER; case 'y': return ExecuteAppletAction.YES; - case 's': - return ExecuteAppletAction.SANDBOX; case 'n': return ExecuteAppletAction.NO; - case 'X': - return ExecuteAppletAction.UNSET; } throw new RuntimeException("Unknown ExecuteUnsignedApplet for " + s); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RemeberActionProvider.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,45 @@ +/* + Copyright (C) 2008-2010 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ + +package net.sourceforge.jnlp.security.dialogs.remember; + + +public interface RemeberActionProvider { + + public RememberPanelResult getRememberAction(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberDialog.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,129 @@ +/* + Copyright (C) 2008-2010 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ +package net.sourceforge.jnlp.security.dialogs.remember; + +import java.awt.Component; +import java.awt.Container; +import net.sourceforge.jnlp.security.SecurityDialog; +import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; +import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; +import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; + +public class RememberDialog { + + public void setOrUpdateRememberedState(SecurityDialog dialog) { + RememberableDialog found = findRememberablePanel(dialog); + String value = BasicDialogValue.writeNUll(); + if (found.getValue()!=null){ + value = found.getValue().writeValue(); + } + SavedRememberAction action = new SavedRememberAction(createAction(found.getRemeberAction().isRemember(), found.getValue()), value); + UnsignedAppletTrustConfirmation.updateAppletAction(found.getFile(), action, found.getRemeberAction().isCodebase(), (Class<RememberableDialog>) found.getClass()); + } + + public SavedRememberAction getRememberedState(SecurityDialog dialog) { + RememberableDialog found = findRememberablePanel(dialog); + if (found != null) { + return getRememberedState(found); + } + return null; + } + + public SavedRememberAction getRememberedState(RememberableDialog found) { + UnsignedAppletActionEntry entry = UnsignedAppletTrustConfirmation.getStoredEntry(found.getFile(), (found.getClass())); + //was saved for this class of found + if (entry != null) { + SavedRememberAction action = entry.getAppletSecurityActions().getActionEntry(found.getClass()); + return action; + } + return null; + } + + public RememberableDialog findRememberablePanel(Container search) { + //Breadth-first important + for (Component comp : search.getComponents()) { + if (comp instanceof RememberableDialog) { + return (RememberableDialog) comp; + } + } + for (Component comp : search.getComponents()) { + if (comp instanceof Container) { + RememberableDialog candidate = findRememberablePanel((Container) comp); + if (candidate != null) { + return candidate; + } + } + } + return null; + } + + private ExecuteAppletAction createAction(boolean pernament, DialogResult value) { + if (value == null){ + return ExecuteAppletAction.NO; + } + if (value.toBoolean()){ + if (pernament){ + return ExecuteAppletAction.ALWAYS; + } else { + return ExecuteAppletAction.YES; + } + } else { + if (pernament){ + return ExecuteAppletAction.NEVER; + } else { + return ExecuteAppletAction.NO; + } + } + } + + private static class RememberDialogueHolder { + + //https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java + //https://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom + private static final RememberDialog INSTANCE = new RememberDialog(); + + private static RememberDialog getRememberDialogue() { + return RememberDialogueHolder.INSTANCE; + } + } + + public static RememberDialog getInstance() { + return RememberDialogueHolder.getRememberDialogue(); + } + +}
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java Fri Jun 12 16:49:07 2015 +0200 @@ -37,11 +37,11 @@ package net.sourceforge.jnlp.security.dialogs.remember; import java.awt.BorderLayout; -import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.net.MalformedURLException; import java.net.URL; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; @@ -49,25 +49,30 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import static net.sourceforge.jnlp.runtime.Translator.R; -import net.sourceforge.jnlp.security.SecurityDialog; -import net.sourceforge.jnlp.security.dialogresults.DialogResult; +import net.sourceforge.jnlp.util.logging.OutputController; -public class RememberPanel extends JPanel { +public class RememberPanel extends JPanel implements RemeberActionProvider { protected JCheckBox permanencyCheckBox; protected JRadioButton applyToAppletButton; protected JRadioButton applyToCodeBaseButton; private final URL codebase; - protected ActionChoiceListener actionChoiceListener; public RememberPanel(URL codebase) { + this((codebase == null) ? null : codebase.toExternalForm()); + + } + + public RememberPanel(String codebase) { super(new GridLayout(2 /*rows*/, 1 /*column*/)); - this.codebase = codebase; - this.actionChoiceListener = getActionChoiceListener(); + this.codebase = initCodebase(codebase); this.add(createCheckBoxPanel(), BorderLayout.WEST); this.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); this.add(createMatchOptionsPanel()); this.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); + if (this.codebase == null) { + applyToCodeBaseButton.setVisible(false); + } } @@ -124,81 +129,21 @@ return applyToCodeBaseButton.isSelected(); } - public ActionListener chosenActionSetter(final ExecuteAppletAction action) { - return new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - ExecuteAppletAction realAction; - if (action == ExecuteAppletAction.YES) { - realAction = isAlwaysSelected() ? ExecuteAppletAction.ALWAYS : ExecuteAppletAction.YES; - } else if (action == ExecuteAppletAction.NO) { - realAction = isAlwaysSelected() ? ExecuteAppletAction.NEVER : ExecuteAppletAction.NO; - } else { - realAction = action; - } - - boolean applyToCodeBase = isCodebaseSelected(); - actionChoiceListener.actionChosen(new AppSigningWarningAction(realAction, applyToCodeBase)); + private URL initCodebase(String codebase) { + if (codebase != null) { + try { + return new URL(codebase); + } catch (MalformedURLException ex) { + OutputController.getLogger().log(ex); } - }; - } - - private ActionChoiceListener getActionChoiceListener() { - if (actionChoiceListener == null) { - actionChoiceListener = createActionChoiceListener(); } - return actionChoiceListener; + return null; } - private ActionChoiceListener createActionChoiceListener() { - return new ActionChoiceListener() { - @Override - public void actionChosen(final AppSigningWarningAction action) { - //in this moment, panel is placed on some dialogue - Container p = RememberPanel.this.getParent(); - while (p != null) { - if (p instanceof SecurityDialog) { - //TODO this must not set value, this must return something absolutely different - ((SecurityDialog) p).setValue(new Garbage(action)); - ((SecurityDialog) p).dispose(); - break; - } - p = p.getParent(); - } - } - }; + @Override + public RememberPanelResult getRememberAction() { + return new RememberPanelResult(permanencyCheckBox.isSelected(), applyToCodeBaseButton.isSelected()); } - - //TODO remove this wrapper! - public static class Garbage implements DialogResult{ - - final AppSigningWarningAction action; - public Garbage(AppSigningWarningAction action) { - this.action = action; - } - - public AppSigningWarningAction getAction() { - return action; - } - - - - @Override - public int getButtonIndex() { - return 2; - } - - @Override - public boolean toBoolean() { - return action.getAction() == ExecuteAppletAction.ALWAYS || action.getAction() == ExecuteAppletAction.YES; - } - - @Override - public String writeValue() { - throw new UnsupportedOperationException("never supported yet."); - } - - } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanelResult.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,64 @@ +/* + Copyright (C) 2008-2010 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. +*/ + +package net.sourceforge.jnlp.security.dialogs.remember; + + +public class RememberPanelResult { + + //when null, then information was not available + private final Boolean remember; + private final Boolean codebase; + + public RememberPanelResult(Boolean remember, Boolean codebase) { + this.remember = remember; + this.codebase = codebase; + } + + public boolean isRemember() { + return remember; + } + + public boolean isCodebase() { + return codebase; + } + + + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberableDialog.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,52 @@ +/* +Copyright (C) 2008-2010 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + + +package net.sourceforge.jnlp.security.dialogs.remember; + +import net.sourceforge.jnlp.JNLPFile; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; + +public interface RememberableDialog { + + + public RememberPanelResult getRemeberAction(); + public DialogResult getValue(); + public JNLPFile getFile(); + public DialogResult readValue(String s); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/SavedRememberAction.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,85 @@ +/* + Copyright (C) 2008-2010 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ +package net.sourceforge.jnlp.security.dialogs.remember; + + + +public class SavedRememberAction { + private final ExecuteAppletAction action; + private final String savedValue; + + public SavedRememberAction(ExecuteAppletAction action, String savedValue) { + this.action = action; + this.savedValue = savedValue; + } + + public ExecuteAppletAction getAction() { + return action; + } + + public String getSavedValue() { + return savedValue; + } + + @Override + public String toString() { + return toShortString(); + } + + public String toLongString() { + String s=sanitizeSavedValue(); + return action.toString()+"{"+s+"}"; + } + + private String sanitizeSavedValue() { + String s=savedValue; + if (savedValue==null || savedValue.trim().isEmpty()){ + s=""; + } + return s; + } + + public String toShortString() { + String s=sanitizeSavedValue(); + return action.toChar()+"{"+s+"}"; + } + + public boolean isRemember() { + return action == ExecuteAppletAction.ALWAYS || action == ExecuteAppletAction.NEVER; + } + +}
--- a/netx/net/sourceforge/jnlp/services/ServiceUtil.java Thu Jun 11 13:24:54 2015 +0200 +++ b/netx/net/sourceforge/jnlp/services/ServiceUtil.java Fri Jun 12 16:49:07 2015 +0200 @@ -42,6 +42,7 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.SecurityDialogs; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; +import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; import net.sourceforge.jnlp.util.logging.OutputController; /** @@ -260,9 +261,12 @@ Boolean b = AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { - boolean b = SecurityDialogs.showAccessWarningDialog(tmpType, - tmpApp.getJNLPFile(), tmpExtras).toBoolean(); - return b; + AccessWarningPaneComplexReturn r = SecurityDialogs.showAccessWarningDialog(tmpType, + tmpApp.getJNLPFile(), tmpExtras); + if (r == null) { + return false; + } + return r.toBoolean(); } });
--- a/tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java Thu Jun 11 13:24:54 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java Fri Jun 12 16:49:07 2015 +0200 @@ -38,10 +38,12 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; import java.net.MalformedURLException; import java.net.URL; import java.util.HashSet; import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.browsertesting.browsers.firefox.FirefoxProfilesOperator; import net.sourceforge.jnlp.config.DeploymentConfiguration; @@ -49,13 +51,13 @@ import net.sourceforge.jnlp.mock.DummyJNLPFileWithJar; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; import net.sourceforge.jnlp.security.dialogresults.NamePassword; +import net.sourceforge.jnlp.security.dialogresults.YesNo; import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; -import net.sourceforge.jnlp.security.dialogs.remember.AppSigningWarningAction; +import net.sourceforge.jnlp.util.FileUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; @@ -72,6 +74,13 @@ private static URL url; private static File appletSecurityBackup; private static String seclevel; + private static final String urlstr1 = "http://must.not.be.in/"; + private static final String urlstr2 = ".appletSecurity"; + private static final String urlstr = urlstr1 + urlstr2; + + private JNLPFile crtJnlpF() throws MalformedURLException { + return new DummyJnlpWithTitleAndUrls(); + } private static class DummyJnlpWithTitleAndUrls extends DummyJNLPFileWithJar { @@ -105,14 +114,14 @@ private static class ExpectedResults { - public static ExpectedResults PositiveResults = new ExpectedResults(BasicDialogValue.Primitive.YES, ExecuteAppletAction.YES, null, true); - public static ExpectedResults NegativeResults = new ExpectedResults(BasicDialogValue.Primitive.NO, ExecuteAppletAction.NO, null, false); + public static ExpectedResults PositiveResults = new ExpectedResults(BasicDialogValue.Primitive.YES, YesNo.yes(), null, true); + public static ExpectedResults NegativeResults = new ExpectedResults(BasicDialogValue.Primitive.NO, YesNo.no(), null, false); public final BasicDialogValue.Primitive p; - public final ExecuteAppletAction ea; + public final YesNo ea; public final NamePassword np; public final boolean b; - public ExpectedResults(BasicDialogValue.Primitive p, ExecuteAppletAction ea, NamePassword np, boolean b) { + public ExpectedResults(BasicDialogValue.Primitive p, YesNo ea, NamePassword np, boolean b) { this.p = p; this.ea = ea; this.np = np; @@ -123,13 +132,15 @@ @BeforeClass public static void initUrl() throws MalformedURLException { - url = new URL("http://must.not.be.in/.appletSecurity"); + url = new URL(urlstr); } @BeforeClass public static void backupAppletSecurity() throws IOException { - appletSecurityBackup = File.createTempFile("appletSecurity", "itwTestBAckup"); - FirefoxProfilesOperator.copyFile(PathsAndFiles.APPLET_TRUST_SETTINGS_USER.getFile(), appletSecurityBackup); + if (PathsAndFiles.APPLET_TRUST_SETTINGS_USER.getFile().exists()) { + appletSecurityBackup = File.createTempFile("appletSecurity", "itwTestBackup"); + FirefoxProfilesOperator.copyFile(PathsAndFiles.APPLET_TRUST_SETTINGS_USER.getFile(), appletSecurityBackup); + } } @Before @@ -138,14 +149,14 @@ } public static void removeAppletSecurityImpl() throws IOException { - if (appletSecurityBackup.exists()) { + if (appletSecurityBackup != null && appletSecurityBackup.exists()) { PathsAndFiles.APPLET_TRUST_SETTINGS_USER.getFile().delete(); } } @AfterClass public static void restoreAppletSecurity() throws IOException { - if (appletSecurityBackup.exists()) { + if (appletSecurityBackup != null && appletSecurityBackup.exists()) { removeAppletSecurityImpl(); FirefoxProfilesOperator.copyFile(appletSecurityBackup, PathsAndFiles.APPLET_TRUST_SETTINGS_USER.getFile()); appletSecurityBackup.delete(); @@ -264,17 +275,17 @@ //shortcut AccessWarningPaneComplexReturn r2 = SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.CREATE_DESTKOP_SHORTCUT, null, null); Assert.assertEquals(r.p, r2.getRegularReturn().getValue()); - AppSigningWarningAction r3 = SecurityDialogs.showUnsignedWarningDialog(null); - Assert.assertEquals(r.ea, r3.getAction()); + YesNo r3 = SecurityDialogs.showUnsignedWarningDialog(null); + Assert.assertEquals(r.ea, r3); YesNoSandbox r4 = SecurityDialogs.showCertWarningDialog(SecurityDialogs.AccessType.UNVERIFIED, null, null, null); Assert.assertEquals(r.p, r4.getValue()); - AppSigningWarningAction r5 = SecurityDialogs.showPartiallySignedWarningDialog(null, null, null); - Assert.assertEquals(r.ea, r5.getAction()); + YesNo r5 = SecurityDialogs.showPartiallySignedWarningDialog(null, null, null); + Assert.assertEquals(r.ea, r5); NamePassword r6 = SecurityDialogs.showAuthenicationPrompt(null, 123456, null, null); Assert.assertEquals(r.np, r6); boolean r7 = SecurityDialogs.showMissingALACAttributePanel(null, null, null); Assert.assertEquals(r.b, r7); - boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(new DummyJnlpWithTitleAndUrls(), url, new HashSet<URL>()); + boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>()); Assert.assertEquals(r.b, r8); boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(null); Assert.assertEquals(r.b, r9); @@ -296,7 +307,7 @@ private boolean testUnsignedBehaviour() throws MalformedURLException { try { - UnsignedAppletTrustConfirmation.checkUnsignedWithUserIfRequired(new DummyJnlpWithTitleAndUrls()); + UnsignedAppletTrustConfirmation.checkUnsignedWithUserIfRequired(crtJnlpF()); return true; } catch (LaunchException ex) { return false; @@ -305,7 +316,7 @@ private boolean testPartiallySignedBehaviour() throws MalformedURLException { try { - UnsignedAppletTrustConfirmation.checkPartiallySignedWithUserIfRequired(null, new DummyJnlpWithTitleAndUrls(), null); + UnsignedAppletTrustConfirmation.checkPartiallySignedWithUserIfRequired(null, crtJnlpF(), null); return true; } catch (LaunchException ex) { return false; @@ -321,37 +332,41 @@ //if it have X, it have to show gui, terminate itself, and then verify that gui was really running private void countNPES() throws MalformedURLException { + countNPES(0); + } + + private void countNPES(int allowedRuns) throws MalformedURLException { int npecounter = 0; int metcounter = 0; try { metcounter++; //anything but shoertcut - SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.PRINTER, null, null); + SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.PRINTER, crtJnlpF(), null); } catch (NullPointerException ex) { npecounter++; } try { metcounter++; //shortcut - SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.CREATE_DESTKOP_SHORTCUT, null, null); + SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.CREATE_DESTKOP_SHORTCUT, crtJnlpF(), null); } catch (NullPointerException ex) { npecounter++; } try { metcounter++; - SecurityDialogs.showUnsignedWarningDialog(null); + SecurityDialogs.showUnsignedWarningDialog(crtJnlpF()); } catch (NullPointerException ex) { npecounter++; } try { metcounter++; - SecurityDialogs.showCertWarningDialog(SecurityDialogs.AccessType.UNVERIFIED, null, null, null); + SecurityDialogs.showCertWarningDialog(SecurityDialogs.AccessType.UNVERIFIED, crtJnlpF(), null, null); } catch (NullPointerException ex) { npecounter++; } try { metcounter++; - AppSigningWarningAction r5 = SecurityDialogs.showPartiallySignedWarningDialog(null, null, null); + SecurityDialogs.showPartiallySignedWarningDialog(crtJnlpF(), null, null); } catch (NullPointerException ex) { npecounter++; } @@ -363,23 +378,23 @@ } try { metcounter++; - SecurityDialogs.showMissingALACAttributePanel(null, null, null); + SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, null); } catch (NullPointerException ex) { npecounter++; } try { metcounter++; - SecurityDialogs.showMatchingALACAttributePanel(new DummyJnlpWithTitleAndUrls(), url, new HashSet<URL>()); + SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>()); } catch (NullPointerException ex) { npecounter++; } try { metcounter++; - SecurityDialogs.showMissingPermissionsAttributeDialogue(null); + SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF()); } catch (NullPointerException ex) { npecounter++; } - Assert.assertEquals(metcounter, npecounter); + Assert.assertEquals(metcounter, npecounter + allowedRuns); } private void checkUnsignedNPE(boolean b) throws MalformedURLException { @@ -494,9 +509,8 @@ Assert.assertEquals(false, r12); checkUnsignedNPE(true, false); } - - - @Test + + @Test public void testUnsignedDialogsNotHeadlessPrompt() throws Exception { JNLPRuntime.setHeadless(false); JNLPRuntime.setTrustAll(false); @@ -516,4 +530,99 @@ checkUnsignedNPE(true, false); } + //ending/mising spaces are important separators! + //if new rememberable interface implementation is added, then tests using this sentence should start to fail, + //and so this sentence should be updated for it + private static final String appletSecurityContent + = "MissingALACAttributePanel:A{YES};" + + "MatchingALACAttributePanel:A{YES};" + + "UnsignedAppletTrustWarningPanel:A{YES};" + + "AccessWarningPane:A{YES};" + + "MissingPermissionsAttributePanel:A{YES};" + + "PartiallySignedAppTrustWarningPanel:A{YES}; " + + "1434098834574 " + + ".* \\Q" + urlstr + "\\E "; + + private void runRememeberableClasses(ExpectedResults r) throws MalformedURLException { + boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet<URL>()); + Assert.assertEquals(r.b, r7); + boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>()); + Assert.assertEquals(r.b, r8); + boolean r9 = testUnsignedBehaviour(); + Assert.assertEquals(r.b, r9); + //skiping this one, ahrd to mock certVerifier + // boolean r5 = testPartiallySignedBehaviour(); + //Assert.assertEquals(r.b, r5); + boolean r6 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF()); + Assert.assertEquals(r.b, r6); + AccessWarningPaneComplexReturn r1 = SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.PRINTER, crtJnlpF(), null); + Assert.assertEquals(r.p, r1.getRegularReturn().getValue()); + AccessWarningPaneComplexReturn r2 = SecurityDialogs.showAccessWarningDialog(SecurityDialogs.AccessType.CREATE_DESTKOP_SHORTCUT, crtJnlpF(), null); + Assert.assertEquals(r.p, r2.getRegularReturn().getValue()); + + } + + @Test + public void testRemeberBehaviour() throws Exception { + File f = PathsAndFiles.APPLET_TRUST_SETTINGS_USER.getFile(); + try { + JNLPRuntime.setHeadless(false); + JNLPRuntime.setTrustAll(false); + JNLPRuntime.setTrustNone(false); + setPrompt(true); //ignored + setAS(AppletSecurityLevel.ASK_UNSIGNED); + /*Everything is on default, which means ask always everywhere*/ + countNPES(); + checkUnsignedNPE(true); + //no we fake queue + fakeQueue(); + //file exists our 6 rememberable dialogues should pass + FileUtils.saveFile(appletSecurityContent, f); + runRememeberableClasses(ExpectedResults.PositiveResults); + FileUtils.saveFile(appletSecurityContent.replace("{YES}", "{NO}"), f); + runRememeberableClasses(ExpectedResults.NegativeResults); + } finally { + resetQueue(); + f.delete(); + } + + } + + private void fakeQueue() throws Exception { + Field field = JNLPRuntime.class.getDeclaredField("securityDialogMessageHandler"); + field.setAccessible(true); + SecurityDialogMessageHandler sd = new SecurityDialogMessageHandler() { + private SecurityDialogMessage currentMessage; + + @Override + protected void handleMessage(SecurityDialogMessage message) { + this.currentMessage = message; + super.handleMessage(message); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void run() { + while (true) { + try { + super.run(); + } catch (Exception ex) { + ex.printStackTrace(); + unlockMessagesClient(currentMessage); + } + } + } + + }; + field.set(null, sd); + Thread t = new Thread(sd); + t.setDaemon(true); + t.start(); + } + + private void resetQueue() throws Exception { + Field field = JNLPRuntime.class.getDeclaredField("securityDialogMessageHandler"); + field.setAccessible(true); + field.set(null, null); + } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/LegacyUnsignedAppletActionStorageImplTest.java Fri Jun 12 16:49:07 2015 +0200 @@ -0,0 +1,228 @@ +/* Copyright (C) 2013 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ +package net.sourceforge.jnlp.security.appletextendedsecurity.impl; + +import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import net.sourceforge.jnlp.ServerAccess; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActionsTest; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LegacyUnsignedAppletActionStorageImplTest { + + private static File f1; + private static File f2; + private static File f3; + private static File ff1; + private static File ff2; + private static File ff3; + private static File ff4; + + @BeforeClass + public static void preapreTestFiles() throws IOException { + f1 = File.createTempFile("itwMatching", "testFile1"); + f2 = File.createTempFile("itwMatching", "testFile2"); + f3 = File.createTempFile("itwMatching", "testFile3"); + ServerAccess.saveFile("A 123456 .* .* jar1,jar2", f1); + ServerAccess.saveFile("N 123456 .* \\Qbla\\E jar1,jar2", f2); + ServerAccess.saveFile("" + + "A 1 \\Qhttp://jmol.sourceforge.net/demo/atoms/\\E \\Qhttp://jmol.sourceforge.net/jmol/\\E JmolApplet0.jar\n" + + "N 1363278653454 \\Qhttp://www.walter-fendt.de/ph14e\\E.* \\Qhttp://www.walter-fendt.de\\E.*\n" + + "n 1363281783104 \\Qhttp://www.walter-fendt.de/ph14e/inclplane.htm\\E \\Qhttp://www.walter-fendt.de/ph14_jar/\\E Ph14English.jar,SchiefeEbene.jar" + + "yA 1 \\Qhttp://jmol.sourceforge.net/demo/atoms/\\E \\Qhttp://jmol.sourceforge.net/jmol/\\E JmolApplet0.jar\n" + + "Ay 1363278653454 \\Qhttp://www.walter-fendt.de/ph14e\\E.* \\Qhttp://www.walter-fendt.de\\E.*\n" + + "nn 1363281783104 \\Qhttp://www.walter-fendt.de/ph14e/inclplane.htm\\E \\Qhttp://www.walter-fendt.de/ph14_jar/\\E Ph14English.jar,SchiefeEbene.jar" + + "", f3); + + ff1 = File.createTempFile("itwMatching", "testFile1"); + ff2 = File.createTempFile("itwMatching", "testFile2"); + ff3 = File.createTempFile("itwMatching", "testFile3"); + ff4 = File.createTempFile("itwMatching", "testFile3"); + ServerAccess.saveFile("AXn 123456 .* .* jar1,jar2", ff1); + ServerAccess.saveFile("XXXXXy 123456 .* \\Qbla\\E jar1,jar2", ff2); + ServerAccess.saveFile("XXXXXA 123456 .* \\Qbla\\E jar1,jar2", ff4); + ServerAccess.saveFile("" + + "XA 1 \\Qa\\E \\Qb\\E jar1\n" + + "NNA 2 \\Qc\\E \\Qd\\E\n" + + "nyXyn 3 \\Qe\\E \\Qf\\E j1,j2" + + "", ff3); + } + + @AfterClass + public static void removeTestFiles() throws IOException { + f1.delete(); + f2.delete(); + f3.delete(); + ff1.delete(); + ff2.delete(); + ff3.delete(); + ff4.delete(); + } + + @Test + public void multipleActionsf4JustLoad() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff4); + //pass + } + + private abstract static class cN implements RememberableDialog { + }; + + @Test + public void multipleActionsf4() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff4); + //reed whatever + UnsignedAppletActionEntry r1 = i1.getMatchingItem("a", "b", Arrays.asList(new String[]{"jar1"}), cN.class); + //nonmapped return null + Assert.assertEquals(null, r1); + } + + @Test + public void multipleActionsf3() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff3); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("a", "b", Arrays.asList(new String[]{"jar1"}), AppletSecurityActionsTest.MACA); + UnsignedAppletActionEntry r2 = i1.getMatchingItem("c", "d", Arrays.asList(new String[]{}), AppletSecurityActionsTest.MACA); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("e", "f", Arrays.asList(new String[]{"j1", "j2"}), AppletSecurityActionsTest.MACA); + + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, null, ExecuteAppletAction.ALWAYS); + + Assert.assertNotNull("r2 should be found", r2); + checkValues(r2, ExecuteAppletAction.NEVER, ExecuteAppletAction.NEVER); + + Assert.assertNotNull("r3 should be found", r3); + checkValues(r3, ExecuteAppletAction.NO, ExecuteAppletAction.YES); + } + + @Test + public void multipleActionsf2() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff2); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("whatever", "bla", Arrays.asList(new String[]{"jar1", "jar2"}), AppletSecurityActionsTest.MACA); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, null, null); + } + + @Test + public void multipleActionsf1() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff1); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar1", "jar2"}), AppletSecurityActionsTest.MACA); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, ExecuteAppletAction.ALWAYS, null); + + } + + @Test + public void wildcards1() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f3); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("http://www.walter-fendt.de/ph14e/inclplane.htm", "http://www.walter-fendt.de/ph14_jar/", Arrays.asList(new String[]{"Ph14English.jar", "SchiefeEbene.jar"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r1 should be found", r1); + ServerAccess.logOutputReprint(r1.toString()); + checkValues(r1, ExecuteAppletAction.NEVER, null); + } + + @Test + public void allMatchingDocAndCode() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f1); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar1", "jar2"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, ExecuteAppletAction.ALWAYS, null); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("blah", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), AppletSecurityActionsTest.UATWA); + checkValues(r3, ExecuteAppletAction.ALWAYS, null); + Assert.assertNotNull("r3 should be found", r3); + UnsignedAppletActionEntry r4 = i1.getMatchingItem("blha", "blaBlam", Arrays.asList(new String[]{"jar2", "wrong_jar"}), AppletSecurityActionsTest.UATWA); + Assert.assertNull("r4 should NOT be found", r4); + UnsignedAppletActionEntry r5 = i1.getMatchingItem("blaBla", "blaBlaBla", Arrays.asList(new String[]{"jar2"}), AppletSecurityActionsTest.UATWA); + Assert.assertNull("r5 should NOT be found", r5); + + } + + @Test + public void allMatchingDocAndStrictCode() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f2); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("whatever", "bla", Arrays.asList(new String[]{"jar1", "jar2"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, ExecuteAppletAction.NEVER, null); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("whatever", null, Arrays.asList(new String[]{"jar2", "jar1"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r3 should be found", r3); + checkValues(r3, ExecuteAppletAction.NEVER, null); + UnsignedAppletActionEntry r2 = i1.getMatchingItem("bla", "blaBlam", Arrays.asList(new String[]{"jar1", "jar2"}), AppletSecurityActionsTest.UATWA); + Assert.assertNull("r2 should NOT be found", r2); + UnsignedAppletActionEntry r4 = i1.getMatchingItem(null, "blaBlam", null, AppletSecurityActionsTest.UATWA); + Assert.assertNull("r4 should NOT be found", r4); + + } + + @Test + public void allMatchingDocAndCodeWithNulls() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f1); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", null, AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, ExecuteAppletAction.ALWAYS, null); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("bla", "whatever", null, AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r3 should be found", r3); + checkValues(r3, ExecuteAppletAction.ALWAYS, null); + UnsignedAppletActionEntry r2 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r2 should be found", r2); + checkValues(r2, ExecuteAppletAction.ALWAYS, null); + UnsignedAppletActionEntry r4 = i1.getMatchingItem("bla", "blaBla", null, AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r4 should be found", r4); + checkValues(r2, ExecuteAppletAction.ALWAYS, null); + UnsignedAppletActionEntry r5 = i1.getMatchingItem("", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r5 should be found", r5); + UnsignedAppletActionEntry r6 = i1.getMatchingItem(null, null, Arrays.asList(new String[]{"jar2", "jar1"}), AppletSecurityActionsTest.UATWA); + Assert.assertNotNull("r6 should be found", r6); + UnsignedAppletActionEntry r7 = i1.getMatchingItem(null, null, Arrays.asList(new String[]{"jar2", "jar11"}), AppletSecurityActionsTest.UATWA); + Assert.assertNull("r7 should NOT be found", r7); + + } + + private void checkValues(UnsignedAppletActionEntry item, ExecuteAppletAction uaca, ExecuteAppletAction maca) { + AppletSecurityActions as = item.getAppletSecurityActions(); + ExecuteAppletAction q1 = item.getAppletSecurityActions().getAction(AppletSecurityActionsTest.UATWA); + ExecuteAppletAction q2 = item.getAppletSecurityActions().getAction(AppletSecurityActionsTest.MACA); + Assert.assertEquals(uaca, q1); + Assert.assertEquals(maca, q2); + } + +}
--- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java Thu Jun 11 13:24:54 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java Fri Jun 12 16:49:07 2015 +0200 @@ -1,38 +1,38 @@ -/* Copyright (C) 2013 Red Hat, Inc. +/* Copyright (C) 2015 Red Hat, Inc. -This file is part of IcedTea. + This file is part of IcedTea. -IcedTea is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 2. + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. -IcedTea is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. -You should have received a copy of the GNU General Public License -along with IcedTea; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. -*/ + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ package net.sourceforge.jnlp.security.appletextendedsecurity.impl; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; @@ -40,8 +40,8 @@ import java.io.IOException; import java.util.Arrays; import net.sourceforge.jnlp.ServerAccess; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.RememberableDialog; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -57,36 +57,54 @@ private static File ff3; private static File ff4; - public static final int ZERO = AppletSecurityActions.UNSIGNED_APPLET_ACTION; - public static final int ONE = AppletSecurityActions.MATCHING_ALACA_ACTION; + private abstract static class c1 implements RememberableDialog { + }; + + private abstract static class c2 implements RememberableDialog { + }; + + private abstract static class c3 implements RememberableDialog { + }; + + private abstract static class c4 implements RememberableDialog { + }; + + private abstract static class c5 implements RememberableDialog { + }; + + private abstract static class c6 implements RememberableDialog { + }; + + private abstract static class c7 implements RememberableDialog { + }; @BeforeClass public static void preapreTestFiles() throws IOException { f1 = File.createTempFile("itwMatching", "testFile1"); f2 = File.createTempFile("itwMatching", "testFile2"); f3 = File.createTempFile("itwMatching", "testFile3"); - ServerAccess.saveFile("A 123456 .* .* jar1,jar2", f1); - ServerAccess.saveFile("N 123456 .* \\Qbla\\E jar1,jar2", f2); + ServerAccess.saveFile("c1:A{YES}; 123456 .* .* jar1,jar2", f1); + ServerAccess.saveFile("c1:N{NO}; 123456 .* \\Qbla\\E jar1,jar2", f2); ServerAccess.saveFile("" - + "A 1 \\Qhttp://jmol.sourceforge.net/demo/atoms/\\E \\Qhttp://jmol.sourceforge.net/jmol/\\E JmolApplet0.jar\n" - + "N 1363278653454 \\Qhttp://www.walter-fendt.de/ph14e\\E.* \\Qhttp://www.walter-fendt.de\\E.*\n" - + "n 1363281783104 \\Qhttp://www.walter-fendt.de/ph14e/inclplane.htm\\E \\Qhttp://www.walter-fendt.de/ph14_jar/\\E Ph14English.jar,SchiefeEbene.jar" - + "yA 1 \\Qhttp://jmol.sourceforge.net/demo/atoms/\\E \\Qhttp://jmol.sourceforge.net/jmol/\\E JmolApplet0.jar\n" - + "Ay 1363278653454 \\Qhttp://www.walter-fendt.de/ph14e\\E.* \\Qhttp://www.walter-fendt.de\\E.*\n" - + "nn 1363281783104 \\Qhttp://www.walter-fendt.de/ph14e/inclplane.htm\\E \\Qhttp://www.walter-fendt.de/ph14_jar/\\E Ph14English.jar,SchiefeEbene.jar" + + "c1:A{YES}; 1 \\Qhttp://jmol.sourceforge.net/demo/atoms/\\E \\Qhttp://jmol.sourceforge.net/jmol/\\E JmolApplet0.jar\n" + + "c1:N{NO}; 1363278653454 \\Qhttp://www.walter-fendt.de/ph14e\\E.* \\Qhttp://www.walter-fendt.de\\E.*\n" + + "c1:n{NO}; 1363281783104 \\Qhttp://www.walter-fendt.de/ph14e/inclplane.htm\\E \\Qhttp://www.walter-fendt.de/ph14_jar/\\E Ph14English.jar,SchiefeEbene.jar" + + "c1:y{YES};c2:A{YES}; 1 \\Qhttp://jmol.sourceforge.net/demo/atoms/\\E \\Qhttp://jmol.sourceforge.net/jmol/\\E JmolApplet0.jar\n" + + "c1:A{YES};c2:A{YES}; 1363278653454 \\Qhttp://www.walter-fendt.de/ph14e\\E.* \\Qhttp://www.walter-fendt.de\\E.*\n" + + "c1:n{NO};c2:n{NO}; 1363281783104 \\Qhttp://www.walter-fendt.de/ph14e/inclplane.htm\\E \\Qhttp://www.walter-fendt.de/ph14_jar/\\E Ph14English.jar,SchiefeEbene.jar" + "", f3); ff1 = File.createTempFile("itwMatching", "testFile1"); ff2 = File.createTempFile("itwMatching", "testFile2"); ff3 = File.createTempFile("itwMatching", "testFile3"); ff4 = File.createTempFile("itwMatching", "testFile3"); - ServerAccess.saveFile("AXn 123456 .* .* jar1,jar2", ff1); - ServerAccess.saveFile("XXXXXy 123456 .* \\Qbla\\E jar1,jar2", ff2); - ServerAccess.saveFile("XXXXXY 123456 .* \\Qbla\\E jar1,jar2", ff4);//errornous + ServerAccess.saveFile("c1:A{YES};c3:n{NO}; 123456 .* .* jar1,jar2", ff1); + ServerAccess.saveFile("c6:y{YES}; 123456 .* \\Qbla\\E jar1,jar2", ff2); + ServerAccess.saveFile("c6:A{YES}; 123456 .* \\Qbla\\E jar1,jar2", ff4); ServerAccess.saveFile("" - + "XA 1 \\Qa\\E \\Qb\\E jar1\n" - + "NNA 2 \\Qc\\E \\Qd\\E\n" - + "nyXyn 3 \\Qe\\E \\Qf\\E j1,j2" + + "c2:A{YES}; 1 \\Qa\\E \\Qb\\E jar1\n" + + "c1:N{NO};c2:N{NO};c3:A{YES}; 2 \\Qc\\E \\Qd\\E\n" + + "c1:n{NO};c2:y{YES};c4:y{YES};c5:n{NO}; 3 \\Qe\\E \\Qf\\E j1,j2" + "", ff3); } @@ -107,122 +125,181 @@ //pass } - @Test(expected = RuntimeException.class) + @Test public void multipleActionsf4() { UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff4); //reed whatever - UnsignedAppletActionEntry r1 = i1.getMatchingItem("a", "b", Arrays.asList(new String[]{"jar1"}), ZERO); - //fail + UnsignedAppletActionEntry r1 = i1.getMatchingItem("a", "b", Arrays.asList(new String[]{"jar1"}), c1.class); + //nonmapped return null + Assert.assertEquals(null, r1); } @Test public void multipleActionsf3() { UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff3); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("a", "b", Arrays.asList(new String[]{"jar1"}), ONE); - UnsignedAppletActionEntry r2 = i1.getMatchingItem("c", "d", Arrays.asList(new String[]{}), ONE); - UnsignedAppletActionEntry r3 = i1.getMatchingItem("e", "f", Arrays.asList(new String[]{"j1", "j2"}), ONE); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("a", "b", Arrays.asList(new String[]{"jar1"}), c1.class); + UnsignedAppletActionEntry r2 = i1.getMatchingItem("c", "d", Arrays.asList(new String[]{}), c2.class); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("e", "f", Arrays.asList(new String[]{"j1", "j2"}), c3.class); Assert.assertNotNull("r1 should be found", r1); - checkValues(r1, ExecuteAppletAction.UNSET, ExecuteAppletAction.ALWAYS); + checkValues(r1, + new Result(c1.class), + Result.AY(c2.class), + new Result(c3.class)); Assert.assertNotNull("r2 should be found", r2); - checkValues(r2, ExecuteAppletAction.NEVER, ExecuteAppletAction.NEVER, ExecuteAppletAction.ALWAYS); + Assert.assertEquals(ExecuteAppletAction.NEVER, r2.getAppletSecurityActions().getActionEntry(c1.class).getAction()); + checkValues(r2, + Result.NN(c1.class), + Result.NN(c2.class), + Result.AY(c3.class)); Assert.assertNotNull("r3 should be found", r3); - checkValues(r3, ExecuteAppletAction.NO, ExecuteAppletAction.YES, ExecuteAppletAction.UNSET, ExecuteAppletAction.YES, ExecuteAppletAction.NO); + checkValues(r3, Result.nN(c1.class), Result.yY(c2.class), Result.NUL(c3.class), Result.yY(c4.class), Result.nN(c5.class)); } + + @Test + public void multipleActionsf2() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff2); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("whatever", "bla", Arrays.asList(new String[]{"jar1", "jar2"}), c6.class); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, Result.NUL(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.yY(c6.class)); + } + + @Test + public void multipleActionsf1() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff1); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar1", "jar2"}), c1.class); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, + Result.AY(c1.class), Result.NUL(c2.class), Result.nN(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class) + ); + + } - @Test - public void multipleActionsf2() { - UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff2); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("whatever", "bla", Arrays.asList(new String[]{"jar1", "jar2"}), ONE); - Assert.assertNotNull("r1 should be found", r1); - checkValues(r1, ExecuteAppletAction.UNSET, ExecuteAppletAction.UNSET, ExecuteAppletAction.UNSET, ExecuteAppletAction.UNSET, ExecuteAppletAction.UNSET, ExecuteAppletAction.YES); - } + @Test + public void wildcards1() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f3); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("http://www.walter-fendt.de/ph14e/inclplane.htm", "http://www.walter-fendt.de/ph14_jar/", Arrays.asList(new String[]{"Ph14English.jar", "SchiefeEbene.jar"}), c1.class); + Assert.assertNotNull("r1 should be found", r1); + ServerAccess.logOutputReprint(r1.toString()); + //stronger result +checkValues(r1, + Result.NN(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class) + ); + } + + @Test + public void allMatchingDocAndCode() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f1); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar1", "jar2"}), c1.class); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, + Result.AY(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class) + ); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("blah", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), c1.class); + checkValues(r3, + Result.AY(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class) + ); + Assert.assertNotNull("r3 should be found", r3); + UnsignedAppletActionEntry r4 = i1.getMatchingItem("blha", "blaBlam", Arrays.asList(new String[]{"jar2", "wrong_jar"}), c1.class); + Assert.assertNull("r4 should NOT be found", r4); + UnsignedAppletActionEntry r5 = i1.getMatchingItem("blaBla", "blaBlaBla", Arrays.asList(new String[]{"jar2"}), c1.class); + Assert.assertNull("r5 should NOT be found", r5); - @Test - public void multipleActionsf1() { - UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(ff1); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar1", "jar2"}), ONE); - Assert.assertNotNull("r1 should be found", r1); - checkValues(r1, ExecuteAppletAction.ALWAYS, ExecuteAppletAction.UNSET, ExecuteAppletAction.NO); + } + + @Test + public void allMatchingDocAndStrictCode() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f2); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("whatever", "bla", Arrays.asList(new String[]{"jar1", "jar2"}), c1.class); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, Result.NN(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class)); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("whatever", null, Arrays.asList(new String[]{"jar2", "jar1"}), c1.class); + Assert.assertNotNull("r3 should be found", r3); + checkValues(r3, Result.NN(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class)); + UnsignedAppletActionEntry r2 = i1.getMatchingItem("bla", "blaBlam", Arrays.asList(new String[]{"jar1", "jar2"}), c1.class); + Assert.assertNull("r2 should NOT be found", r2); + UnsignedAppletActionEntry r4 = i1.getMatchingItem(null, "blaBlam", null, c1.class); + Assert.assertNull("r4 should NOT be found", r4); + + } - } + @Test + public void allMatchingDocAndCodeWithNulls() { + UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f1); + UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", null, c1.class); + Assert.assertNotNull("r1 should be found", r1); + checkValues(r1, Result.AY(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class)); + UnsignedAppletActionEntry r3 = i1.getMatchingItem("bla", "whatever", null, c1.class); + Assert.assertNotNull("r3 should be found", r3); + checkValues(r3, Result.AY(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class)); + UnsignedAppletActionEntry r2 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), c1.class); + Assert.assertNotNull("r2 should be found", r2); + checkValues(r2, Result.AY(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class)); + UnsignedAppletActionEntry r4 = i1.getMatchingItem("bla", "blaBla", null, c1.class); + Assert.assertNotNull("r4 should be found", r4); + checkValues(r2, Result.AY(c1.class), Result.NUL(c2.class), Result.NUL(c3.class), Result.NUL(c4.class), Result.NUL(c5.class), Result.NUL(c6.class)); + UnsignedAppletActionEntry r5 = i1.getMatchingItem("", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), c1.class); + Assert.assertNotNull("r5 should be found", r5); + UnsignedAppletActionEntry r6 = i1.getMatchingItem(null, null, Arrays.asList(new String[]{"jar2", "jar1"}), c1.class); + Assert.assertNotNull("r6 should be found", r6); + UnsignedAppletActionEntry r7 = i1.getMatchingItem(null, null, Arrays.asList(new String[]{"jar2", "jar11"}), c1.class); + Assert.assertNull("r7 should NOT be found", r7); - @Test - public void wildcards1() { - UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f3); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("http://www.walter-fendt.de/ph14e/inclplane.htm", "http://www.walter-fendt.de/ph14_jar/", Arrays.asList(new String[]{"Ph14English.jar", "SchiefeEbene.jar"}), ZERO); - Assert.assertNotNull("r1 should be found", r1); - ServerAccess.logOutputReprint(r1.toString()); - checkValues(r1, ExecuteAppletAction.NEVER); + } + + + private void checkValues(UnsignedAppletActionEntry item, Result... results) { + for (Result result : results) { + if (result.nul) { + Assert.assertEquals(null, item.getAppletSecurityActions().getActionEntry(result.id)); + } else { + Assert.assertEquals(result.action, item.getAppletSecurityActions().getActionEntry(result.id).getAction()); + Assert.assertEquals(result.savedValue, item.getAppletSecurityActions().getActionEntry(result.id).getSavedValue()); + } + } } - @Test - public void allMatchingDocAndCode() { - UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f1); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar1", "jar2"}), ZERO); - Assert.assertNotNull("r1 should be found", r1); - checkValues(r1, ExecuteAppletAction.ALWAYS); - UnsignedAppletActionEntry r3 = i1.getMatchingItem("blah", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), ZERO); - checkValues(r3, ExecuteAppletAction.ALWAYS); - Assert.assertNotNull("r3 should be found", r3); - UnsignedAppletActionEntry r4 = i1.getMatchingItem("blha", "blaBlam", Arrays.asList(new String[]{"jar2", "wrong_jar"}), ZERO); - Assert.assertNull("r4 should NOT be found", r4); - UnsignedAppletActionEntry r5 = i1.getMatchingItem("blaBla", "blaBlaBla", Arrays.asList(new String[]{"jar2"}), ZERO); - Assert.assertNull("r5 should NOT be found", r5); + private static class Result { - } + public final ExecuteAppletAction action; + public final String savedValue; + public final boolean nul; + public final Class<? extends RememberableDialog> id; - @Test - public void allMatchingDocAndStrictCode() { - UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f2); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("whatever", "bla", Arrays.asList(new String[]{"jar1", "jar2"}), ZERO); - Assert.assertNotNull("r1 should be found", r1); - checkValues(r1, ExecuteAppletAction.NEVER); - UnsignedAppletActionEntry r3 = i1.getMatchingItem("whatever", null, Arrays.asList(new String[]{"jar2", "jar1"}), ZERO); - Assert.assertNotNull("r3 should be found", r3); - checkValues(r3, ExecuteAppletAction.NEVER); - UnsignedAppletActionEntry r2 = i1.getMatchingItem("bla", "blaBlam", Arrays.asList(new String[]{"jar1", "jar2"}), ZERO); - Assert.assertNull("r2 should NOT be found", r2); - UnsignedAppletActionEntry r4 = i1.getMatchingItem(null, "blaBlam", null, ZERO); - Assert.assertNull("r4 should NOT be found", r4); + public static Result AY(Class<? extends RememberableDialog> id) { + return new Result(ExecuteAppletAction.ALWAYS, "YES", id); + } - } + public static Result yY(Class<? extends RememberableDialog> id) { + return new Result(ExecuteAppletAction.YES, "YES", id); + } + + public static Result NN(Class<? extends RememberableDialog> id) { + return new Result(ExecuteAppletAction.NEVER, "NO", id); + } - @Test - public void allMatchingDocAndCodeWithNulls() { - UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f1); - UnsignedAppletActionEntry r1 = i1.getMatchingItem("bla", "blaBla", null, ZERO); - Assert.assertNotNull("r1 should be found", r1); - checkValues(r1, ExecuteAppletAction.ALWAYS); - UnsignedAppletActionEntry r3 = i1.getMatchingItem("bla", "whatever", null, ZERO); - Assert.assertNotNull("r3 should be found", r3); - checkValues(r3, ExecuteAppletAction.ALWAYS); - UnsignedAppletActionEntry r2 = i1.getMatchingItem("bla", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), ZERO); - Assert.assertNotNull("r2 should be found", r2); - checkValues(r2, ExecuteAppletAction.ALWAYS); - UnsignedAppletActionEntry r4 = i1.getMatchingItem("bla", "blaBla", null, ZERO); - Assert.assertNotNull("r4 should be found", r4); - checkValues(r2, ExecuteAppletAction.ALWAYS); - UnsignedAppletActionEntry r5 = i1.getMatchingItem("", "blaBla", Arrays.asList(new String[]{"jar2", "jar1"}), ZERO); - Assert.assertNotNull("r5 should be found", r5); - UnsignedAppletActionEntry r6 = i1.getMatchingItem(null, null, Arrays.asList(new String[]{"jar2", "jar1"}), ZERO); - Assert.assertNotNull("r6 should be found", r6); - UnsignedAppletActionEntry r7 = i1.getMatchingItem(null, null, Arrays.asList(new String[]{"jar2", "jar11"}), ZERO); - Assert.assertNull("r7 should NOT be found", r7); + public static Result nN(Class<? extends RememberableDialog> id) { + return new Result(ExecuteAppletAction.NO, "NO", id); + } + + public static Result NUL(Class<? extends RememberableDialog> id) { + return new Result(id); + } - } + public Result(ExecuteAppletAction action, String savedValue, Class<? extends RememberableDialog> id) { + this.action = action; + this.savedValue = savedValue; + this.nul = false; + this.id = id; + } - private void checkValues(UnsignedAppletActionEntry item, ExecuteAppletAction... items) { - AppletSecurityActions as = item.getAppletSecurityActions(); - for (int i = 0; i < items.length; i++) { - Assert.assertEquals(items[i], as.getAction(i)); - - } - for (int i = items.length; i < 1000; i++) { - Assert.assertEquals(ExecuteAppletAction.UNSET, as.getAction(i)); - + public Result(Class<? extends RememberableDialog> id) { + this.action = null; + this.savedValue = null; + this.nul = true; + this.id = id; } }
--- a/tests/netx/unit/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActionsTest.java Thu Jun 11 13:24:54 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActionsTest.java Fri Jun 12 16:49:07 2015 +0200 @@ -35,86 +35,129 @@ */ package net.sourceforge.jnlp.security.dialogs.remember; -import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; -import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.MatchingALACAttributePanel; +import net.sourceforge.jnlp.security.dialogs.apptrustwarningpanel.UnsignedAppletTrustWarningPanel; +import org.junit.Assert; import static org.junit.Assert.assertEquals; import org.junit.Test; public class AppletSecurityActionsTest { + //before 1.7 only those two were remebered. Using in legacy parsing tests + public static final Class UATWA = UnsignedAppletTrustWarningPanel.class; + public static final Class MACA = MatchingALACAttributePanel.class; + + @Test + public void parseMultipleItemsCorrectLegacy() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); + assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(UATWA)); + assertEquals(ExecuteAppletAction.NEVER, a1.getAction(MACA)); + assertEquals(2, a1.getActions().size()); + } + @Test public void parseMultipleItemsCorrect() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); - assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(0)); - assertEquals(ExecuteAppletAction.NEVER, a1.getAction(1)); - assertEquals(ExecuteAppletAction.YES, a1.getAction(2)); - assertEquals(ExecuteAppletAction.NO, a1.getAction(3)); - assertEquals(ExecuteAppletAction.SANDBOX, a1.getAction(4)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(5)); - assertEquals(ExecuteAppletAction.SANDBOX, a1.getAction(6)); - assertEquals(ExecuteAppletAction.NO, a1.getAction(7)); - assertEquals(ExecuteAppletAction.YES, a1.getAction(8)); - assertEquals(ExecuteAppletAction.NEVER, a1.getAction(9)); - assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(10)); - assertEquals(11, a1.getActions().size()); + AppletSecurityActions a1 = AppletSecurityActions.fromString("c1:A{};c2:N{};c3:y{};c4:n{};c8:n{};c9:y{};c10:N{};c11:A{};"); + assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction("c1")); + assertEquals(ExecuteAppletAction.NEVER, a1.getAction("c2")); + assertEquals(ExecuteAppletAction.YES, a1.getAction("c3")); + assertEquals(ExecuteAppletAction.NO, a1.getAction("c4")); + assertEquals(ExecuteAppletAction.NO, a1.getAction("c8")); + assertEquals(ExecuteAppletAction.YES, a1.getAction("c9")); + assertEquals(ExecuteAppletAction.NEVER, a1.getAction("c10")); + assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction("c11")); + assertEquals(8, a1.getActions().size()); + } + + @Test + public void checkToString() throws Exception { + AppletSecurityActions as = new AppletSecurityActions(); + as.setAction("c1", new SavedRememberAction(ExecuteAppletAction.ALWAYS, "")); + as.setAction("c2", new SavedRememberAction(ExecuteAppletAction.ALWAYS, null)); + as.setAction("c3", new SavedRememberAction(ExecuteAppletAction.ALWAYS, "item")); + String saveString = as.toShortString(); + //order is not guaranted + Assert.assertTrue(saveString.contains("c3:A{item};")); + Assert.assertTrue(saveString.contains("c1:A{};")); + Assert.assertTrue(saveString.contains("c2:A{};")); + } + + @Test + public void checkToStringIsParsableBack() throws Exception { + AppletSecurityActions as = new AppletSecurityActions(); + as.setAction("c1", new SavedRememberAction(ExecuteAppletAction.ALWAYS, "")); + as.setAction("c2", new SavedRememberAction(ExecuteAppletAction.NEVER, null)); + as.setAction("c3", new SavedRememberAction(ExecuteAppletAction.YES, "item")); + as.setAction("c2", new SavedRememberAction(ExecuteAppletAction.NO, "item2")); + as.setAction("c3", new SavedRememberAction(ExecuteAppletAction.NO, null)); + Assert.assertTrue(as.getRealCount() == 3); + String saveString = as.toShortString(); + AppletSecurityActions a2 = AppletSecurityActions.fromString(saveString); + Assert.assertTrue(as.getRealCount() == a2.getRealCount()); + SavedRememberAction c1 = a2.getActionEntry("c1"); + Assert.assertTrue(c1.getSavedValue() == null || c1.getSavedValue().equals("")); + Assert.assertTrue(c1.getAction().equals(ExecuteAppletAction.ALWAYS)); + SavedRememberAction c2 = a2.getActionEntry("c2"); + Assert.assertTrue(c2.getSavedValue().equals("item2")); + Assert.assertTrue(c2.getAction().equals(ExecuteAppletAction.NO)); + SavedRememberAction c3 = a2.getActionEntry("c3"); + Assert.assertTrue(c3.getSavedValue() == null || c3.getSavedValue().equals("")); //not yet decided + Assert.assertTrue(c3.getAction().equals(ExecuteAppletAction.NO)); } @Test public void parseEmpty() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString(""); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(0)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(10)); + assertEquals(null, a1.getAction(UATWA)); + assertEquals(null, a1.getAction(MACA)); assertEquals(0, a1.getActions().size()); } @Test public void parseOkSetAndGetZero() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString(""); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(0)); + assertEquals(null, a1.getAction(MACA)); assertEquals(0, a1.getActions().size()); - a1.setAction(0, ExecuteAppletAction.YES); - assertEquals(ExecuteAppletAction.YES, a1.getAction(0)); + a1.setAction(MACA, new SavedRememberAction(ExecuteAppletAction.YES, "aa")); + assertEquals(ExecuteAppletAction.YES, a1.getAction(MACA)); + assertEquals("aa", a1.getActionEntry(MACA).getSavedValue()); assertEquals(1, a1.getActions().size()); } @Test public void parseOkSetAndGet() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("s"); - assertEquals(ExecuteAppletAction.SANDBOX, a1.getAction(0)); + AppletSecurityActions a1 = AppletSecurityActions.fromString("A"); + assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(UATWA)); assertEquals(1, a1.getActions().size()); - a1.setAction(0, ExecuteAppletAction.NO); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); + a1.setAction(UATWA, new SavedRememberAction(ExecuteAppletAction.NO, "U1")); + assertEquals(ExecuteAppletAction.NO, a1.getAction(UATWA)); assertEquals(1, a1.getActions().size()); - a1.setAction(1, ExecuteAppletAction.YES); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); - assertEquals(ExecuteAppletAction.YES, a1.getAction(1)); + a1.setAction(MACA, new SavedRememberAction(ExecuteAppletAction.YES,"M1")); + assertEquals(ExecuteAppletAction.NO, a1.getAction(UATWA)); + assertEquals(ExecuteAppletAction.YES, a1.getAction(MACA)); assertEquals(2, a1.getActions().size()); - a1.setAction(0, ExecuteAppletAction.NO); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); + a1.setAction(UATWA, new SavedRememberAction(ExecuteAppletAction.NO, "U2")); + assertEquals(ExecuteAppletAction.NO, a1.getAction(UATWA)); assertEquals(2, a1.getActions().size()); - a1.setAction(4, ExecuteAppletAction.NEVER); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); - assertEquals(ExecuteAppletAction.YES, a1.getAction(1)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(2)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(3)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(3)); - assertEquals(ExecuteAppletAction.NEVER, a1.getAction(4)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(5));//default again - assertEquals(5, a1.getActions().size()); + a1.setAction("Another", new SavedRememberAction(ExecuteAppletAction.NEVER,"A1")); + assertEquals(ExecuteAppletAction.NO, a1.getAction(UATWA)); + assertEquals(ExecuteAppletAction.YES, a1.getAction(MACA)); + assertEquals(ExecuteAppletAction.NEVER, a1.getAction("Another")); + assertEquals(3, a1.getActions().size()); } - @Test(expected = IndexOutOfBoundsException.class) + @Test(expected = NullPointerException.class) public void parseNotOkGet() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); - a1.getAction(-1); + a1.getAction((Class)null); } - @Test(expected = IndexOutOfBoundsException.class) + @Test(expected = NullPointerException.class) public void parseNotOkSet() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); - a1.setAction(-1, ExecuteAppletAction.NO); + a1.setAction((Class)null, new SavedRememberAction(ExecuteAppletAction.NO, "")); } @Test(expected = RuntimeException.class) @@ -125,10 +168,10 @@ @Test public void parseMultipleItemsFillMissing() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString("AN"); - assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(0)); - assertEquals(ExecuteAppletAction.NEVER, a1.getAction(1)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(2)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(3)); + assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(UATWA)); + assertEquals(ExecuteAppletAction.NEVER, a1.getAction(MACA)); + assertEquals(null, a1.getAction("unset")); + assertEquals(null, a1.getAction("unset")); //note, getters do not increase length assertEquals(2, a1.getActions().size()); } @@ -136,22 +179,22 @@ @Test public void parseMultipleItemsSpaceEnd() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString("ANXs AAA"); - assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(0)); - assertEquals(ExecuteAppletAction.NEVER, a1.getAction(1)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(2)); - assertEquals(ExecuteAppletAction.SANDBOX, a1.getAction(3)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(4)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(5)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(10)); - assertEquals(4, a1.getActions().size()); + assertEquals(ExecuteAppletAction.ALWAYS, a1.getAction(UATWA)); + assertEquals(ExecuteAppletAction.NEVER, a1.getAction(MACA)); + assertEquals(null, a1.getAction("no1")); + assertEquals(null, a1.getAction("no2")); + assertEquals(null, a1.getAction("no3")); + assertEquals(null, a1.getAction("no4")); + assertEquals(null, a1.getAction("no5")); + assertEquals(2, a1.getActions().size()); } - + @Test public void testIterator() throws Exception { AppletSecurityActions a1 = AppletSecurityActions.fromString("ANXs AAA"); int i = 0; - for (ExecuteAppletAction eaa : a1) { - assertEquals(a1.getAction(i), eaa); + for (SavedRememberAction eaa : a1) { + Assert.assertTrue(a1.getActions().contains(eaa.getAction())); i++; } assertEquals(a1.getRealCount(), i);