Mercurial > hg > release > icedtea-web-1.7
changeset 1240:21aca3386c4f
AppletSecurityActions, ExecuteAppletAction, AppletSecurityActionsTest moved to remember package
line wrap: on
line diff
--- a/ChangeLog Thu Jun 11 12:51:00 2015 +0200 +++ b/ChangeLog Thu Jun 11 13:24:54 2015 +0200 @@ -1,3 +1,48 @@ +2015-06-11 Jiri Vanek <jvanek@redhat.com> + + AppletSecurityActions, ExecuteAppletAction, AppletSecurityActionsTest moved to remember package + * netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletActionTableModel.java: + adapted imports + * netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletsTrustingListPanel.java: + same + * netx/net/sourceforge/jnlp/security/SecurityDialogs.java: + same + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java: + same + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java: + same + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImpl.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanel.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/MatchingALACAttributePanel.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/UnsignedAppletTrustWarningPanel.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/remember/AppSigningWarningAction.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java + same + * tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java + same + * netx/net/sourceforge/jnlp/security/SecurityDialog.java: (getPanel) extracted + from (installPanel). It now throws exception if panel is about to be null. + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionEntry.java: + used diamond + * net/sourceforge/jnlp/security/appletextendedsecurity/AppletSecurityActions.java: + moved to + * netx/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActions.java: + here + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/ExecuteAppletAction.java: + moved to + * netx/net/sourceforge/jnlp/security/dialogs/remember/ExecuteAppletAction.java: + here + * tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/AppletSecurityActionsTest.java: + moved to + * tests/netx/unit/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActionsTest.java: + here 2015-06-11 Jiri Vanek <jvanek@redhat.com> make jnlpfile nearly mandatory argument of message and adapt various re-declarations accordingly
--- a/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletActionTableModel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletActionTableModel.java Thu Jun 11 13:24:54 2015 +0200 @@ -39,8 +39,8 @@ import javax.swing.event.TableModelEvent; import javax.swing.table.AbstractTableModel; import net.sourceforge.jnlp.runtime.Translator; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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;
--- a/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletsTrustingListPanel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletsTrustingListPanel.java Thu Jun 11 13:24:54 2015 +0200 @@ -87,9 +87,9 @@ import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.config.PathsAndFiles; import net.sourceforge.jnlp.runtime.Translator; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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;
--- a/netx/net/sourceforge/jnlp/security/SecurityDialog.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialog.java Thu Jun 11 13:24:54 2015 +0200 @@ -293,36 +293,53 @@ return cert; } - /** + /* + * find appropriate JPanel to this Dialog, based on {@link DialogType}. + */ + private SecurityDialogPanel getPanel() { + return getPanel(this); + } + + /* + * find appropriate JPanel to given Dialog, based on {@link DialogType}. + */ + private static SecurityDialogPanel getPanel(SecurityDialog sd) { + SecurityDialogPanel lpanel = null; + if (sd.dialogType == DialogType.CERT_WARNING) { + lpanel = new CertWarningPane(sd, sd.certVerifier, (SecurityDelegate) sd.extras[0]); + } else if (sd.dialogType == DialogType.MORE_INFO) { + lpanel = new MoreInfoPane(sd, sd.certVerifier); + } else if (sd.dialogType == DialogType.CERT_INFO) { + lpanel = new CertsInfoPane(sd, sd.certVerifier); + } else if (sd.dialogType == DialogType.SINGLE_CERT_INFO) { + lpanel = new SingleCertInfoPane(sd, sd.certVerifier); + } else if (sd.dialogType == DialogType.ACCESS_WARNING) { + lpanel = new AccessWarningPane(sd, sd.extras, sd.certVerifier); + } else if (sd.dialogType == DialogType.APPLET_WARNING) { + lpanel = new AppletWarningPane(sd, sd.certVerifier); + } else if (sd.dialogType == DialogType.PARTIALLYSIGNED_WARNING) { + lpanel = AppTrustWarningDialog.partiallySigned(sd, sd.file, (SecurityDelegate) sd.extras[0]); + } else if (sd.dialogType == DialogType.UNSIGNED_WARNING) { + lpanel = AppTrustWarningDialog.unsigned(sd, sd.file); // Only necessary for applets on 'high security' or above + } else if (sd.dialogType == DialogType.AUTHENTICATION) { + lpanel = new PasswordAuthenticationPane(sd, sd.extras); + } else if (sd.dialogType == DialogType.UNSIGNED_EAS_NO_PERMISSIONS_WARNING) { + lpanel = new MissingPermissionsAttributePanel(sd, sd.file.getTitle(), sd.file.getCodeBase().toExternalForm()); + } else if (sd.dialogType == DialogType.MISSING_ALACA) { + lpanel = new MissingALACAttributePanel(sd, sd.file.getTitle(), (String) sd.extras[0], (String) sd.extras[1]); + } else if (sd.dialogType == DialogType.MATCHING_ALACA) { + lpanel = AppTrustWarningDialog.matchingAlaca(sd, sd.file, (String) sd.extras[0], (String) sd.extras[1]); + } else { + throw new RuntimeException("Unknown value of " + sd.dialogType + ". Panel will be null. Tahts not allowed."); + } + return lpanel; + } + + /* * Adds the appropriate JPanel to this Dialog, based on {@link DialogType}. */ private void installPanel() { - - if (dialogType == DialogType.CERT_WARNING) - panel = new CertWarningPane(this, this.certVerifier, (SecurityDelegate) extras[0]); - else if (dialogType == DialogType.MORE_INFO) - panel = new MoreInfoPane(this, this.certVerifier); - else if (dialogType == DialogType.CERT_INFO) - panel = new CertsInfoPane(this, this.certVerifier); - else if (dialogType == DialogType.SINGLE_CERT_INFO) - panel = new SingleCertInfoPane(this, this.certVerifier); - else if (dialogType == DialogType.ACCESS_WARNING) - panel = new AccessWarningPane(this, extras, this.certVerifier); - else if (dialogType == DialogType.APPLET_WARNING) - panel = new AppletWarningPane(this, this.certVerifier); - else if (dialogType == DialogType.PARTIALLYSIGNED_WARNING) - panel = AppTrustWarningDialog.partiallySigned(this, file, (SecurityDelegate) extras[0]); - else if (dialogType == DialogType.UNSIGNED_WARNING) // Only necessary for applets on 'high security' or above - panel = AppTrustWarningDialog.unsigned(this, file); - else if (dialogType == DialogType.AUTHENTICATION) - panel = new PasswordAuthenticationPane(this, extras); - else if (dialogType == DialogType.UNSIGNED_EAS_NO_PERMISSIONS_WARNING) - panel = new MissingPermissionsAttributePanel(this, file.getTitle(), file.getCodeBase().toExternalForm()); - else if (dialogType == DialogType.MISSING_ALACA) - panel = new MissingALACAttributePanel(this, file.getTitle(), (String) extras[0], (String) extras[1]); - else if (dialogType == DialogType.MATCHING_ALACA) - panel = AppTrustWarningDialog.matchingAlaca(this, file, (String) extras[0], (String) extras[1]); - + panel = getPanel(); add(panel, BorderLayout.CENTER); }
--- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Thu Jun 11 13:24:54 2015 +0200 @@ -54,8 +54,6 @@ 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.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; import static net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation.getStoredAction; import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; @@ -63,6 +61,8 @@ import net.sourceforge.jnlp.security.dialogresults.NamePassword; 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.util.UrlUtils; import net.sourceforge.jnlp.util.logging.OutputController;
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/AppletSecurityActions.java Thu Jun 11 12:51:00 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -/* Copyright (C) 2014 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; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -public class AppletSecurityActions implements Iterable<ExecuteAppletAction>{ - - 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; - - - 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; - } - AppletSecurityActions asas = new AppletSecurityActions(); - asas.setAction(id, s); - return asas; - } - - - static AppletSecurityActions fromString(String s) { - if (s == null) { - s = ""; - } - s = s.trim(); //to not return on leading space, may be dangerous, - //but the s shouldbe already trimmed before bubbling here. - //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)){ - break; - } - asas.actions.add(ExecuteAppletAction.fromChar(x)); - } - return asas; - } - - public ExecuteAppletAction getAction(int i) { - if (i>= actions.size()){ - return ExecuteAppletAction.UNSET; - } - return actions.get(i); - } - - public void setAction(int i, ExecuteAppletAction a) { - while (actions.size() <= i){ - actions.add(ExecuteAppletAction.UNSET); - } - actions.set(i,a); - } - - - public ExecuteAppletAction getUnsignedAppletAction() { - return getAction(UNSIGNED_APPLET_ACTION); - } - - public void setUnsignedAppletAction(ExecuteAppletAction a) { - setAction(UNSIGNED_APPLET_ACTION,a); - } - - - public ExecuteAppletAction getMatchingAlacaAction() { - return getAction(MATCHING_ALACA_ACTION); - } - - public void setMatchingAlacaAction(ExecuteAppletAction a) { - setAction(MATCHING_ALACA_ACTION, a); - } - - @Override - public String toString() { - return toShortString(); - } - - public String toLongString() { - StringBuilder sb = new StringBuilder(); - for (ExecuteAppletAction executeAppletAction : actions) { - sb.append(executeAppletAction.toString()).append("; "); - } - return sb.toString(); - } - - - public String toShortString() { - StringBuilder sb = new StringBuilder(); - for (ExecuteAppletAction executeAppletAction : actions) { - sb.append(executeAppletAction.toChar()); - } - return sb.toString(); - } - - public int getRealCount() { - return actions.size(); - } - - - /** - * stub for testing - * @return - */ - List<ExecuteAppletAction> getActions() { - return actions; - } - - @Override - public Iterator<ExecuteAppletAction> iterator() { - return actions.iterator(); - } - -}
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/ExecuteAppletAction.java Thu Jun 11 12:51:00 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* 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; - -import net.sourceforge.jnlp.runtime.Translator; - -public enum ExecuteAppletAction { - - ALWAYS, NEVER, YES, SANDBOX, NO, UNSET; - - public String toChar() { - switch (this) { - case ALWAYS: - return "A"; - case NEVER: - return "N"; - case YES: - return "y"; - case SANDBOX: - return "s"; - case NO: - return "n"; - case UNSET: - return "X"; - } - throw new RuntimeException("Unknown ExecuteUnsignedApplet"); - } - - public String toExplanation() { - switch (this) { - case ALWAYS: - return Translator.R("APPEXTSECunsignedAppletActionAlways"); - case NEVER: - return Translator.R("APPEXTSECunsignedAppletActionNever"); - case YES: - return Translator.R("APPEXTSECunsignedAppletActionYes"); - case SANDBOX: - return Translator.R("APPEXTSECunsignedAppletActionSandbox"); - 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"); - } - return fromChar(s.charAt(0)); - - } - - public static ExecuteAppletAction fromChar(char s) { - switch (s) { - case 'A': - return ExecuteAppletAction.ALWAYS; - case 'N': - 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); - } - - @Override - public String toString() { - return toChar() + " - " + toExplanation(); - } -}
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionEntry.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletActionEntry.java Thu Jun 11 13:24:54 2015 +0200 @@ -35,6 +35,7 @@ */ 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; @@ -172,14 +173,12 @@ return null; } String[] items = commedArchives.trim().split(","); - List<String> r = new ArrayList<String>(items.length); - for (int i = 0; i < items.length; i++) { - String string = items[i]; + List<String> r = new ArrayList<>(items.length); + for (String string : items) { if (string.trim().isEmpty()) { continue; } r.add(string); - } return r;
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmation.java Thu Jun 11 13:24:54 2015 +0200 @@ -36,6 +36,8 @@ 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;
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java Thu Jun 11 13:24:54 2015 +0200 @@ -38,8 +38,8 @@ import java.io.File; import java.io.IOException; import java.util.Date; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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;
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImpl.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImpl.java Thu Jun 11 13:24:54 2015 +0200 @@ -41,7 +41,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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.util.lockingfile.LockingReaderWriter;
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/AppTrustWarningPanel.java Thu Jun 11 13:24:54 2015 +0200 @@ -65,7 +65,7 @@ import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.PluginBridge; import static net.sourceforge.jnlp.runtime.Translator.R; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.ExtendedAppletSecurityHelp; import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; import net.sourceforge.jnlp.util.ScreenFinder;
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/MatchingALACAttributePanel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/MatchingALACAttributePanel.java Thu Jun 11 13:24:54 2015 +0200 @@ -50,8 +50,8 @@ 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.appletextendedsecurity.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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.RememberPanel;
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java Thu Jun 11 13:24:54 2015 +0200 @@ -50,11 +50,11 @@ import net.sourceforge.jnlp.runtime.JNLPClassLoader.SecurityDelegate; import net.sourceforge.jnlp.security.SecurityDialog; import net.sourceforge.jnlp.security.SecurityUtil; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry; import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation; 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; import net.sourceforge.jnlp.tools.JarCertVerifier;
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/UnsignedAppletTrustWarningPanel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/UnsignedAppletTrustWarningPanel.java Thu Jun 11 13:24:54 2015 +0200 @@ -45,8 +45,8 @@ import javax.swing.JFrame; import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.security.SecurityDialog; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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.RememberPanel;
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/AppSigningWarningAction.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/AppSigningWarningAction.java Thu Jun 11 13:24:54 2015 +0200 @@ -36,8 +36,6 @@ */ package net.sourceforge.jnlp.security.dialogs.remember; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; - /* * Details of decided action. */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActions.java Thu Jun 11 13:24:54 2015 +0200 @@ -0,0 +1,166 @@ +/* Copyright (C) 2014 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.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +public class AppletSecurityActions implements Iterable<ExecuteAppletAction>{ + + 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; + + + 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; + } + AppletSecurityActions asas = new AppletSecurityActions(); + asas.setAction(id, s); + return asas; + } + + + public static AppletSecurityActions fromString(String s) { + if (s == null) { + s = ""; + } + s = s.trim(); //to not return on leading space, may be dangerous, + //but the s shouldbe already trimmed before bubbling here. + //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)){ + break; + } + asas.actions.add(ExecuteAppletAction.fromChar(x)); + } + return asas; + } + + public ExecuteAppletAction getAction(int i) { + if (i>= actions.size()){ + return ExecuteAppletAction.UNSET; + } + return actions.get(i); + } + + public void setAction(int i, ExecuteAppletAction a) { + while (actions.size() <= i){ + actions.add(ExecuteAppletAction.UNSET); + } + actions.set(i,a); + } + + + public ExecuteAppletAction getUnsignedAppletAction() { + return getAction(UNSIGNED_APPLET_ACTION); + } + + public void setUnsignedAppletAction(ExecuteAppletAction a) { + setAction(UNSIGNED_APPLET_ACTION,a); + } + + + public ExecuteAppletAction getMatchingAlacaAction() { + return getAction(MATCHING_ALACA_ACTION); + } + + public void setMatchingAlacaAction(ExecuteAppletAction a) { + setAction(MATCHING_ALACA_ACTION, a); + } + + @Override + public String toString() { + return toShortString(); + } + + public String toLongString() { + StringBuilder sb = new StringBuilder(); + for (ExecuteAppletAction executeAppletAction : actions) { + sb.append(executeAppletAction.toString()).append("; "); + } + return sb.toString(); + } + + + public String toShortString() { + StringBuilder sb = new StringBuilder(); + for (ExecuteAppletAction executeAppletAction : actions) { + sb.append(executeAppletAction.toChar()); + } + return sb.toString(); + } + + public int getRealCount() { + return actions.size(); + } + + + /** + * stub for testing + * @return + */ + List<ExecuteAppletAction> getActions() { + return actions; + } + + @Override + public Iterator<ExecuteAppletAction> iterator() { + return actions.iterator(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/ExecuteAppletAction.java Thu Jun 11 13:24:54 2015 +0200 @@ -0,0 +1,110 @@ +/* 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.dialogs.remember; + +import net.sourceforge.jnlp.runtime.Translator; + +public enum ExecuteAppletAction { + + ALWAYS, NEVER, YES, SANDBOX, NO, UNSET; + + public String toChar() { + switch (this) { + case ALWAYS: + return "A"; + case NEVER: + return "N"; + case YES: + return "y"; + case SANDBOX: + return "s"; + case NO: + return "n"; + case UNSET: + return "X"; + } + throw new RuntimeException("Unknown ExecuteUnsignedApplet"); + } + + public String toExplanation() { + switch (this) { + case ALWAYS: + return Translator.R("APPEXTSECunsignedAppletActionAlways"); + case NEVER: + return Translator.R("APPEXTSECunsignedAppletActionNever"); + case YES: + return Translator.R("APPEXTSECunsignedAppletActionYes"); + case SANDBOX: + return Translator.R("APPEXTSECunsignedAppletActionSandbox"); + 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"); + } + return fromChar(s.charAt(0)); + + } + + public static ExecuteAppletAction fromChar(char s) { + switch (s) { + case 'A': + return ExecuteAppletAction.ALWAYS; + case 'N': + 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); + } + + @Override + public String toString() { + return toChar() + " - " + toExplanation(); + } +}
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java Thu Jun 11 12:51:00 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java Thu Jun 11 13:24:54 2015 +0200 @@ -50,7 +50,6 @@ import javax.swing.JRadioButton; import static net.sourceforge.jnlp.runtime.Translator.R; import net.sourceforge.jnlp.security.SecurityDialog; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; import net.sourceforge.jnlp.security.dialogresults.DialogResult; public class RememberPanel extends JPanel {
--- a/tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java Thu Jun 11 12:51:00 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java Thu Jun 11 13:24:54 2015 +0200 @@ -49,8 +49,7 @@ import net.sourceforge.jnlp.mock.DummyJNLPFileWithJar; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletStartupSecuritySettings; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +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;
--- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/AppletSecurityActionsTest.java Thu Jun 11 12:51:00 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -/* Copyright (C) 2014 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; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class AppletSecurityActionsTest { - - @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()); - } - - @Test - public void parseEmpty() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString(""); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(0)); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(10)); - assertEquals(0, a1.getActions().size()); - } - - @Test - public void parseOkSetAndGetZero() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString(""); - assertEquals(ExecuteAppletAction.UNSET, a1.getAction(0)); - assertEquals(0, a1.getActions().size()); - a1.setAction(0, ExecuteAppletAction.YES); - assertEquals(ExecuteAppletAction.YES, a1.getAction(0)); - assertEquals(1, a1.getActions().size()); - } - - @Test - public void parseOkSetAndGet() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("s"); - assertEquals(ExecuteAppletAction.SANDBOX, a1.getAction(0)); - assertEquals(1, a1.getActions().size()); - a1.setAction(0, ExecuteAppletAction.NO); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); - assertEquals(1, a1.getActions().size()); - a1.setAction(1, ExecuteAppletAction.YES); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); - assertEquals(ExecuteAppletAction.YES, a1.getAction(1)); - assertEquals(2, a1.getActions().size()); - a1.setAction(0, ExecuteAppletAction.NO); - assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); - 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()); - - } - - @Test(expected = IndexOutOfBoundsException.class) - public void parseNotOkGet() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); - a1.getAction(-1); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void parseNotOkSet() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); - a1.setAction(-1, ExecuteAppletAction.NO); - } - - @Test(expected = RuntimeException.class) - public void parseMultipleItemsToSomeWrong() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("AQA"); - } - - @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)); - //note, getters do not increase length - assertEquals(2, a1.getActions().size()); - } - - @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()); - } - - @Test - public void testIterator() throws Exception { - AppletSecurityActions a1 = AppletSecurityActions.fromString("ANXs AAA"); - int i = 0; - for (ExecuteAppletAction eaa : a1) { - assertEquals(a1.getAction(i), eaa); - i++; - } - assertEquals(a1.getRealCount(), i); - } - -}
--- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java Thu Jun 11 12:51:00 2015 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java Thu Jun 11 13:24:54 2015 +0200 @@ -40,8 +40,8 @@ import java.io.IOException; import java.util.Arrays; import net.sourceforge.jnlp.ServerAccess; -import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityActions; -import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogs/remember/AppletSecurityActionsTest.java Thu Jun 11 13:24:54 2015 +0200 @@ -0,0 +1,160 @@ +/* Copyright (C) 2014 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.security.dialogs.remember.ExecuteAppletAction; +import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class AppletSecurityActionsTest { + + @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()); + } + + @Test + public void parseEmpty() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString(""); + assertEquals(ExecuteAppletAction.UNSET, a1.getAction(0)); + assertEquals(ExecuteAppletAction.UNSET, a1.getAction(10)); + assertEquals(0, a1.getActions().size()); + } + + @Test + public void parseOkSetAndGetZero() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString(""); + assertEquals(ExecuteAppletAction.UNSET, a1.getAction(0)); + assertEquals(0, a1.getActions().size()); + a1.setAction(0, ExecuteAppletAction.YES); + assertEquals(ExecuteAppletAction.YES, a1.getAction(0)); + assertEquals(1, a1.getActions().size()); + } + + @Test + public void parseOkSetAndGet() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString("s"); + assertEquals(ExecuteAppletAction.SANDBOX, a1.getAction(0)); + assertEquals(1, a1.getActions().size()); + a1.setAction(0, ExecuteAppletAction.NO); + assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); + assertEquals(1, a1.getActions().size()); + a1.setAction(1, ExecuteAppletAction.YES); + assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); + assertEquals(ExecuteAppletAction.YES, a1.getAction(1)); + assertEquals(2, a1.getActions().size()); + a1.setAction(0, ExecuteAppletAction.NO); + assertEquals(ExecuteAppletAction.NO, a1.getAction(0)); + 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()); + + } + + @Test(expected = IndexOutOfBoundsException.class) + public void parseNotOkGet() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); + a1.getAction(-1); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void parseNotOkSet() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString("ANynsXsnyNA"); + a1.setAction(-1, ExecuteAppletAction.NO); + } + + @Test(expected = RuntimeException.class) + public void parseMultipleItemsToSomeWrong() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString("AQA"); + } + + @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)); + //note, getters do not increase length + assertEquals(2, a1.getActions().size()); + } + + @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()); + } + + @Test + public void testIterator() throws Exception { + AppletSecurityActions a1 = AppletSecurityActions.fromString("ANXs AAA"); + int i = 0; + for (ExecuteAppletAction eaa : a1) { + assertEquals(a1.getAction(i), eaa); + i++; + } + assertEquals(a1.getRealCount(), i); + } + +}