Mercurial > hg > release > icedtea-web-1.8
changeset 1234:9b3cfdc71c60
SecurityDialog return type changed from Object (mostly int) to regular type
line wrap: on
line diff
--- a/ChangeLog Mon Jun 01 14:43:43 2015 +0200 +++ b/ChangeLog Tue Jun 09 13:02:00 2015 +0200 @@ -1,3 +1,83 @@ +2015-06-01 Jiri Vanek <jvanek@redhat.com> + + SecurityDialog return type changed from Object (mostly int) to regular type + * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java: removed handling + of integer results/inputs + * netx/net/sourceforge/jnlp/security/JNLPAppVerifier.java: AppletAction usage + replaced by YesNoSandbox + * netx/net/sourceforge/jnlp/security/PluginAppVerifier.java: same + * netx/net/sourceforge/jnlp/security/JNLPAuthenticator.java: usages of Object[] + replaced by regular type + * netx/net/sourceforge/jnlp/security/SecurityDialog.java: value changed from + Object to DialogResult + * netx/net/sourceforge/jnlp/security/SecurityDialogMessage.java: same for + userResponse, class made public + * netx/net/sourceforge/jnlp/security/SecurityDialogs.java: removed redundant + AppletAction and all to/from int/boolean conversion methods. All Object returns + repalced by proper class/interface. Removed redundant showAppletWarning + * netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java: adapted + to removed AppletAction and new BasicDialogValue + * netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java: + added override annotations. + * netx/net/sourceforge/jnlp/security/dialogresults/AccessWarningPaneComplexReturn.java: + class extracted from netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPaneComplexReturn.java + Made to implement DialogResult + * netx/net/sourceforge/jnlp/security/dialogresults/BasicDialogValue.java: + New class, which keeps together main utility methods and base classes of + dialog return. + * netx/net/sourceforge/jnlp/security/dialogresults/DialogResult.java: + new class, main interface of SecurityDialog return. + * netx/net/sourceforge/jnlp/security/dialogresults/NamePassword.java: + Implementation of SecurityDialog for dialog asking for username and password. + * netx/net/sourceforge/jnlp/security/dialogresults/SetValueHandler.java: + extracted from SecurityDialogPanel. Have DialogResult instead of Object. + It is base implementation of any click to button. + * netx/net/sourceforge/jnlp/security/dialogresults/Yes.java: + Wrapper for return from dialog, which can return only and only yes. + * netx/net/sourceforge/jnlp/security/dialogresults/YesCancel.java: + Wrapper for return from dialog, which can return only and only yes or cancel + * netx/net/sourceforge/jnlp/security/dialogresults/YesNo.java: + Wrapper for return from dialog, which can return only and only yes or no + * netx/net/sourceforge/jnlp/security/dialogresults/YesNoCancel.java: + Wrapper for return from dialog, which can return only and only yes, no or cancel + * netx/net/sourceforge/jnlp/security/dialogresults/YesNoSandbox.java: + Wrapper for return from dialog, which can return only and only yes, no or sandbox + * netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPane.java: get rid of + int buttons, replaced by YesNo. + * netx/net/sourceforge/jnlp/security/dialogs/AppletWarningPane.java: get rid of + int buttons, replaced by YesNoCancel. + * netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java: get rid of + int buttons, replaced by YesNoSadnbox + * netx/net/sourceforge/jnlp/security/dialogs/CertsInfoPane.java: get rid of + int buttons, replaced by Yes. + * netx/net/sourceforge/jnlp/security/dialogs/MoreInfoPane.java: same + * netx/net/sourceforge/jnlp/security/dialogs/MissingALACAttributePanel.java: + get rid of int buttons, replaced by YesNo. + * netx/net/sourceforge/jnlp/security/dialogs/MissingPermissionsAttributePanel.java: + same + * netx/net/sourceforge/jnlp/security/dialogs/PasswordAuthenticationPane.java: + get rid of Object[] return, replaced by NamePassword. + * netx/net/sourceforge/jnlp/security/dialogs/SecurityDialogPanel.java: get rid + of inner SetValueHandler + * netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java: included + wrappers, which allows compilation and pass tests. Must be fixed in next changesets. + * netx/net/sourceforge/jnlp/services/ServiceUtil.java: adapted to DialogResult + * netx/net/sourceforge/jnlp/util/XDesktopEntry.java: changed import + * tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java: + removed. Tests were checking int conversions from legacy model. + * tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/AccessWarningPaneComplexReturnTest.java: + new tests for new class + * tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesCancelTest.java: + same + * tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesNoCancelTest.java: + same + * tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesNoSandboxTest.java: + same + * tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesNoTestTest.java: + same + * tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesTest.java: + same + 2015-06-01 Jiri Vanek <jvanek@redhat.com> Remember panel extracted so it can be reused
--- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java Tue Jun 09 13:02:00 2015 +0200 @@ -38,7 +38,7 @@ import net.sourceforge.jnlp.event.ApplicationListener; import net.sourceforge.jnlp.security.SecurityDialogs; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; -import net.sourceforge.jnlp.security.dialogs.AccessWarningPaneComplexReturn; +import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; import net.sourceforge.jnlp.util.logging.OutputController; import net.sourceforge.jnlp.util.WeakList; import net.sourceforge.jnlp.util.XDesktopEntry; @@ -185,7 +185,7 @@ return; } AccessWarningPaneComplexReturn ics = getComplexReturn(sd); - if (ics.getRegularReturnAsBoolean()) { + if (ics.toBoolean()) { entry.createDesktopShortcuts(ics.getMenu(), ics.getDekstop(), isSigned()); } @@ -201,7 +201,7 @@ private AccessWarningPaneComplexReturn getComplexReturn(ShortcutDesc sd) { if (JNLPRuntime.isTrustAll()) { boolean mainResult = (sd != null && (sd.onDesktop() || sd.getMenu() != null)); - AccessWarningPaneComplexReturn r = new AccessWarningPaneComplexReturn(mainResult?0:1); + AccessWarningPaneComplexReturn r = new AccessWarningPaneComplexReturn(mainResult); if (mainResult){ if (sd.onDesktop()){ r.setDekstop(new AccessWarningPaneComplexReturn.ShortcutResult(true)); @@ -225,22 +225,22 @@ */ switch (currentSetting) { case ShortcutDesc.CREATE_NEVER: - return new AccessWarningPaneComplexReturn(1); + return new AccessWarningPaneComplexReturn(false); case ShortcutDesc.CREATE_ALWAYS: - return new AccessWarningPaneComplexReturn(0); + return new AccessWarningPaneComplexReturn(true); case ShortcutDesc.CREATE_ASK_USER: - return SecurityDialogs.showAccessWarningDialogComplexReturn(AccessType.CREATE_DESTKOP_SHORTCUT, file); + return SecurityDialogs.showAccessWarningDialog(AccessType.CREATE_DESTKOP_SHORTCUT, file, null); case ShortcutDesc.CREATE_ASK_USER_IF_HINTED: if (sd != null && (sd.onDesktop() || sd.toMenu())) { - return SecurityDialogs.showAccessWarningDialogComplexReturn(AccessType.CREATE_DESTKOP_SHORTCUT, file); + return SecurityDialogs.showAccessWarningDialog(AccessType.CREATE_DESTKOP_SHORTCUT, file, null); } case ShortcutDesc.CREATE_ALWAYS_IF_HINTED: if (sd != null && (sd.onDesktop() || sd.toMenu())) { - return new AccessWarningPaneComplexReturn(0); + return new AccessWarningPaneComplexReturn(true); } } - return new AccessWarningPaneComplexReturn(1); + return new AccessWarningPaneComplexReturn(false); } /**
--- a/netx/net/sourceforge/jnlp/security/JNLPAppVerifier.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/JNLPAppVerifier.java Tue Jun 09 13:02:00 2015 +0200 @@ -46,7 +46,8 @@ import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.runtime.JNLPClassLoader.SecurityDelegate; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; -import net.sourceforge.jnlp.security.SecurityDialogs.AppletAction; +import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; import net.sourceforge.jnlp.tools.CertInformation; import net.sourceforge.jnlp.tools.JarCertVerifier; @@ -120,10 +121,10 @@ dialogType = AccessType.UNVERIFIED; } - AppletAction action = SecurityDialogs.showCertWarningDialog( + YesNoSandbox action = SecurityDialogs.showCertWarningDialog( dialogType, file, jcv, securityDelegate); - if (action != AppletAction.CANCEL) { - if (action == AppletAction.SANDBOX) { + if (action != null && action.toBoolean()) { + if (action.compareValue(BasicDialogValue.Primitive.SANDBOX)) { securityDelegate.setRunInSandbox(); } return;
--- a/netx/net/sourceforge/jnlp/security/JNLPAuthenticator.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/JNLPAuthenticator.java Tue Jun 09 13:02:00 2015 +0200 @@ -39,6 +39,7 @@ import java.net.Authenticator; import java.net.PasswordAuthentication; +import net.sourceforge.jnlp.security.dialogresults.NamePassword; public class JNLPAuthenticator extends Authenticator { @@ -55,11 +56,11 @@ int port = getRequestingPort(); String prompt = getRequestingPrompt(); - Object[] response = SecurityDialogs.showAuthenicationPrompt(host, port, prompt, type); + NamePassword response = SecurityDialogs.showAuthenicationPrompt(host, port, prompt, type); if (response == null) { return null; } else { - return new PasswordAuthentication((String) response[0], (char[]) response[1]); + return new PasswordAuthentication(response.getName(), response.getPassword()); } }
--- a/netx/net/sourceforge/jnlp/security/PluginAppVerifier.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/PluginAppVerifier.java Tue Jun 09 13:02:00 2015 +0200 @@ -48,7 +48,8 @@ import net.sourceforge.jnlp.LaunchException; import net.sourceforge.jnlp.runtime.JNLPClassLoader.SecurityDelegate; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; -import net.sourceforge.jnlp.security.SecurityDialogs.AppletAction; +import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; import net.sourceforge.jnlp.tools.CertInformation; import net.sourceforge.jnlp.tools.JarCertVerifier; @@ -167,10 +168,10 @@ dialogType = AccessType.UNVERIFIED; } - AppletAction action = SecurityDialogs.showCertWarningDialog( + YesNoSandbox action = SecurityDialogs.showCertWarningDialog( dialogType, file, jcv, securityDelegate); - if (action != AppletAction.CANCEL) { - if (action == AppletAction.SANDBOX) { + if (action != null && action.toBoolean()) { + if (action.compareValue(BasicDialogValue.Primitive.SANDBOX)) { securityDelegate.setRunInSandbox(); } alreadyApprovedByUser.add(cPath);
--- a/netx/net/sourceforge/jnlp/security/SecurityDialog.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialog.java Tue Jun 09 13:02:00 2015 +0200 @@ -51,6 +51,7 @@ import net.sourceforge.jnlp.runtime.JNLPClassLoader.SecurityDelegate; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; import net.sourceforge.jnlp.security.SecurityDialogs.DialogType; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; import net.sourceforge.jnlp.security.dialogs.AccessWarningPane; import net.sourceforge.jnlp.security.dialogs.AppletWarningPane; import net.sourceforge.jnlp.security.dialogs.CertWarningPane; @@ -100,11 +101,7 @@ /** Whether or not this object has been fully initialized */ private boolean initialized = false; - /** - * the return value of this dialog. result: 0 = Yes, 1 = No, 2 = Cancel, - * null = Window closed. - */ - private Object value; + private DialogResult value; /** Should show signed JNLP file warning */ private boolean requiresSignedJNLPWarning; @@ -340,12 +337,12 @@ panel.requestFocusOnDefaultButton(); } - public void setValue(Object value) { + public void setValue(DialogResult value) { OutputController.getLogger().log("Setting value:" + value); this.value = value; } - public Object getValue() { + public DialogResult getValue() { OutputController.getLogger().log("Returning value:" + value); return value; } @@ -366,7 +363,7 @@ * Notify all the listeners that the user has made a decision using this * security dialog. */ - public void notifySelectionMade() { + private void notifySelectionMade() { for (ActionListener listener : listeners) { listener.actionPerformed(null); } @@ -386,5 +383,4 @@ { return requiresSignedJNLPWarning; } - }
--- a/netx/net/sourceforge/jnlp/security/SecurityDialogMessage.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogMessage.java Tue Jun 09 13:02:00 2015 +0200 @@ -45,12 +45,13 @@ import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; import net.sourceforge.jnlp.security.SecurityDialogs.DialogType; +import net.sourceforge.jnlp.security.dialogresults.DialogResult; /** * Represents a message to the security framework to show a specific security * dialog */ -final class SecurityDialogMessage { +public final class SecurityDialogMessage { /* * These fields contain information need to display the correct dialog type @@ -67,7 +68,7 @@ * Volatile because this is shared between threads and we dont want threads * to use a cached value of this. */ - public volatile Object userResponse; + public volatile DialogResult userResponse; /* * These two fields are used to block/unblock the application or the applet.
--- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java Tue Jun 09 13:02:00 2015 +0200 @@ -58,8 +58,12 @@ 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.dialogs.AccessWarningPaneComplexReturn; +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.YesNoSandbox; import net.sourceforge.jnlp.security.dialogs.remember.AppSigningWarningAction; +import net.sourceforge.jnlp.security.dialogs.remember.RememberPanel; import net.sourceforge.jnlp.util.UrlUtils; import net.sourceforge.jnlp.util.logging.OutputController; @@ -109,24 +113,6 @@ SIGNING_ERROR } - public static enum AppletAction { - RUN, - SANDBOX, - CANCEL; - public static AppletAction fromInteger(int i) { - switch (i) { - case 0: - return RUN; - case 1: - return SANDBOX; - case 2: - return CANCEL; - default: - return CANCEL; - } - } - } - /** * Shows a warning dialog for different types of system access (i.e. file * open/save, clipboard read/write, printing, etc). @@ -135,81 +121,11 @@ * @param file the jnlp file associated with the requesting application. * @return true if permission was granted by the user, false otherwise. */ - public static boolean showAccessWarningDialogB(AccessType accessType, JNLPFile file) { - return showAccessWarningDialogB(accessType, file, null); - } - - public static boolean showAccessWarningDialogB(AccessType accessType, JNLPFile file, final Object[] extras) { - Object o = showAccessWarningDialog(accessType, file, extras); - if (o instanceof Boolean){ - return (Boolean) o; - } - if (o instanceof Integer){ - return getIntegerResponseAsBoolean((Boolean)o); - } - if (o instanceof AccessWarningPaneComplexReturn){ - return getIntegerResponseAsBoolean(((AccessWarningPaneComplexReturn)o).getRegularReturn()); - } - return false; - } - - /** - * unlike showAccessWarningDialogB this is returning raw int code - * @param accessType type of dialogue - * @param file file for which thsi dialogue is built for - * @return return from dialogue - */ - public static int showAccessWarningDialogI(AccessType accessType, JNLPFile file) { - Object o = showAccessWarningDialog(accessType, file, null); - if (o instanceof Boolean){ - boolean b =(Boolean) o; - if (b){ - return 0; - } else { - return 1; - } - } - if (o instanceof Integer){ - return (Integer)o; - } - if (o instanceof AccessWarningPaneComplexReturn){ - return ((AccessWarningPaneComplexReturn)o).getRegularReturn(); - } - return 1; - } - - public static AccessWarningPaneComplexReturn showAccessWarningDialogComplexReturn(AccessType accessType, JNLPFile file) { - Object o = showAccessWarningDialog(accessType, file, null); - if (o instanceof AccessWarningPaneComplexReturn){ - return (AccessWarningPaneComplexReturn)o; - } - if (o instanceof Boolean) { - boolean b = (Boolean) o; - if (b) { - return new AccessWarningPaneComplexReturn(0); - } else { - return new AccessWarningPaneComplexReturn(1); - } - } - if (o instanceof Integer) { - return new AccessWarningPaneComplexReturn((int) o); - } - return new AccessWarningPaneComplexReturn(1); - } - - - /** - * unlike showAccessWarningDialogB this is returning raw int code - * @param accessType type of dialogue - * @param file file for which thsi dialogue is built for - * @param extras aditional parameters to dialogue - * @return return from dialogue - */ - public static Object showAccessWarningDialog(final AccessType accessType, + public static AccessWarningPaneComplexReturn showAccessWarningDialog(final AccessType accessType, final JNLPFile file, final Object[] extras) { if (!shouldPromptUser()) { - return 1; + return new AccessWarningPaneComplexReturn(false); } final SecurityDialogMessage message = new SecurityDialogMessage(); @@ -219,7 +135,7 @@ message.file = file; message.extras = extras; - return getUserResponse(message); + return (AccessWarningPaneComplexReturn) getUserResponse(message); } @@ -246,7 +162,7 @@ message.accessType = AccessType.UNSIGNED; message.file = file; - return (AppSigningWarningAction) getUserResponse(message); + return ((RememberPanel.Garbage) getUserResponse(message)).getAction(); } /** @@ -264,11 +180,11 @@ * wants the applet to run with only sandbox permissions, or CANCEL if the * user did not accept running the applet */ - public static AppletAction showCertWarningDialog(AccessType accessType, + public static YesNoSandbox showCertWarningDialog(AccessType accessType, JNLPFile file, CertVerifier certVerifier, SecurityDelegate securityDelegate) { if (!shouldPromptUser()) { - return AppletAction.CANCEL; + return YesNoSandbox.no(); } final SecurityDialogMessage message = new SecurityDialogMessage(); @@ -278,9 +194,9 @@ message.certVerifier = certVerifier; message.extras = new Object[] { securityDelegate }; - Object selectedValue = getUserResponse(message); + DialogResult selectedValue = getUserResponse(message); - return getIntegerResponseAsAppletAction(selectedValue); + return (YesNoSandbox) selectedValue; } /** @@ -305,7 +221,7 @@ message.certVerifier = certVerifier; message.extras = new Object[] { securityDelegate }; - return (AppSigningWarningAction) getUserResponse(message); + return ((RememberPanel.Garbage) getUserResponse(message)).getAction(); } /** @@ -320,7 +236,7 @@ * @return an array of objects representing user's authentication tokens * @throws SecurityException if the caller does not have the appropriate permissions. */ - public static Object[] showAuthenicationPrompt(String host, int port, String prompt, String type) { + public static NamePassword showAuthenicationPrompt(String host, int port, String prompt, String type) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -334,8 +250,8 @@ message.dialogType = DialogType.AUTHENTICATION; message.extras = new Object[] { host, port, prompt, type }; - Object response = getUserResponse(message); - return (Object[]) response; + DialogResult response = getUserResponse(message); + return (NamePassword) response; } public static boolean showMissingALACAttributePanel(String title, URL codeBase, Set<URL> remoteUrls) { @@ -353,8 +269,8 @@ OutputController.getLogger().log("Warning, null codebase wants to show in ALACA!"); } message.extras = new Object[]{title, urlToShow, UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; - Object selectedValue = getUserResponse(message); - return getIntegerResponseAsBoolean(selectedValue); + DialogResult selectedValue = getUserResponse(message); + return selectedValue.toBoolean(); } public static boolean showMatchingALACAttributePanel(JNLPFile file, URL codeBase, Set<URL> remoteUrls) { @@ -379,7 +295,7 @@ SecurityDialogMessage message = new SecurityDialogMessage(); message.dialogType = DialogType.MATCHING_ALACA; message.extras = new Object[]{file, codeBase.toString(), UrlUtils.setOfUrlsToHtmlList(remoteUrls)}; - AppSigningWarningAction selectedValue = (AppSigningWarningAction) getUserResponse(message); + AppSigningWarningAction selectedValue = ((RememberPanel.Garbage) getUserResponse(message)).getAction(); if (selectedValue != null) { OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Decided action for matching alaca at " + file.getCodeBase() + " was " + selectedValue.getAction()); @@ -392,31 +308,6 @@ } - /** - * FIXME This is unused. Remove it? - * @return (0, 1, 2) => (Yes, No, Cancel) - */ - public static int showAppletWarning() { - - if (!shouldPromptUser()) { - return 2; - } - - SecurityDialogMessage message = new SecurityDialogMessage(); - message.dialogType = DialogType.APPLET_WARNING; - - Object selectedValue = getUserResponse(message); - - // result 0 = Yes, 1 = No, 2 = Cancel - if (selectedValue instanceof Integer) { - // If the selected value can be cast to Integer, use that value - return ((Integer) selectedValue); - } else { - // Otherwise default to "cancel" - return 2; - } - } - public static boolean showMissingPermissionsAttributeDialogue(String title, URL codeBase) { if (!shouldPromptUser()) { @@ -426,8 +317,8 @@ SecurityDialogMessage message = new SecurityDialogMessage(); message.dialogType = DialogType.UNSIGNED_EAS_NO_PERMISSIONS_WARNING; message.extras = new Object[]{title, codeBase.toExternalForm()}; - Object selectedValue = getUserResponse(message); - return SecurityDialogs.getIntegerResponseAsBoolean(selectedValue); + DialogResult selectedValue = getUserResponse(message); + return selectedValue.toBoolean(); } /** * Posts the message to the SecurityThread and gets the response. Blocks @@ -440,7 +331,7 @@ * type of message, but generally an Integer corresponding to the value 0 * indicates success/proceed, and everything else indicates failure */ - private static Object getUserResponse(final SecurityDialogMessage message) { + private static DialogResult getUserResponse(final SecurityDialogMessage message) { /* * Want to show a security warning, while blocking the client * application. This would be easy except there is a bug in showing @@ -505,33 +396,10 @@ } } - return message.userResponse; } /** - * Returns true iff the given Object reference can be cast to Integer and that Integer's - * intValue is 0. - * @param ref the Integer (hopefully) reference - * @return whether the given reference is both an Integer type and has intValue of 0 - */ - public static boolean getIntegerResponseAsBoolean(Object ref) { - boolean isInteger = ref instanceof Integer; - if (isInteger) { - Integer i = (Integer) ref; - return i == 0; - } - return false; - } - - public static AppletAction getIntegerResponseAsAppletAction(Object ref) { - if (ref instanceof Integer) { - return AppletAction.fromInteger((Integer) ref); - } - return AppletAction.CANCEL; - } - - /** * Returns whether the current runtime configuration allows prompting user * for security warnings. *
--- a/netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java Tue Jun 09 13:02:00 2015 +0200 @@ -58,7 +58,7 @@ import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; -import net.sourceforge.jnlp.security.SecurityDialogs.AppletAction; +import net.sourceforge.jnlp.security.dialogresults.BasicDialogValue; import net.sourceforge.jnlp.util.logging.OutputController; import sun.security.util.HostnameChecker; import sun.security.validator.ValidatorException; @@ -418,7 +418,7 @@ AccessType.UNVERIFIED, null, new HttpsCertVerifier(chain, authType, isTrusted, hostMatched, - hostName), null) == AppletAction.RUN; + hostName), null).compareValue(BasicDialogValue.Primitive.YES); } }); }
--- a/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java Tue Jun 09 13:02:00 2015 +0200 @@ -68,6 +68,7 @@ public void clear() { doLocked(new Runnable() { + @Override public void run() { try { items.clear(); @@ -81,6 +82,7 @@ public void removeByBehaviour(final ExecuteAppletAction unsignedAppletAction) { doLocked(new Runnable() { + @Override public void run() { try { readContents();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/AccessWarningPaneComplexReturn.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,232 @@ +package net.sourceforge.jnlp.security.dialogresults; + +import java.util.Objects; + +/* + Copyright (C) 2008 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. + */ +public class AccessWarningPaneComplexReturn implements DialogResult { + + public static AccessWarningPaneComplexReturn readValue(String s) { + String[] sq = s.split(","); + 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]); + AccessWarningPaneComplexReturn a = new AccessWarningPaneComplexReturn(regularReturn); + a.dekstop = d; + a.menu = m; + return a; + } + + @Override + public String writeValue() { + StringBuilder sb = new StringBuilder(); + sb.append(regularReturn.writeValue()).append(",D("); + if (dekstop != null) { + sb.append(dekstop.writeValue()); + } + sb.append(")M("); + if (menu != null) { + sb.append(menu.writeValue()); + } + sb.append(")"); + return sb.toString(); + } + + public static class ShortcutResult { + + public static ShortcutResult readValue(String s) { + if (s.trim().isEmpty()){ + return null; + } + String[] sq = s.split(","); + ShortcutResult sr = new ShortcutResult(Boolean.valueOf(sq[3])); + sr.browser = sq[0]; + sr.fixHref = Boolean.parseBoolean(sq[1]); + if (!sq[2].equalsIgnoreCase("null")) { + sr.shortcutType = Shortcut.valueOf(sq[2]); + } + return sr; + } + + public String writeValue() { + StringBuilder sb = new StringBuilder(); + sb.append(browser).append(",") + .append(fixHref).append(",") + .append(shortcutType).append(",") + .append(create).append(","); + return sb.toString(); + } + + public static enum Shortcut { + + BROWSER, GENERATED_JNLP, JNLP_HREF, JAVAWS_HTML; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ShortcutResult)){ + return false; + } + ShortcutResult sr = (ShortcutResult) obj; + return this.create == sr.create && this.fixHref == sr.fixHref + && this.browser.equals(sr.browser) && this.shortcutType == sr.shortcutType; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 89 * hash + Objects.hashCode(this.browser); + hash = 89 * hash + (this.fixHref ? 1 : 0); + hash = 89 * hash + Objects.hashCode(this.shortcutType); + 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){ + this.browser = browser; + this.fixHref = fixHref; + this.shortcutType = shortcutType; + this.create = create; + } + + public ShortcutResult(boolean create) { + this.create = create; + } + + public boolean isCreate() { + return create; + } + + public String getBrowser() { + return browser; + } + + public Shortcut getShortcutType() { + return shortcutType; + } + + public boolean isFixHref() { + return fixHref; + } + + public void setBrowser(String browser) { + this.browser = browser; + } + + public void setFixHref(boolean fixHref) { + this.fixHref = fixHref; + } + + public void setShortcutType(Shortcut shortcutType) { + this.shortcutType = shortcutType; + } + + } + + private final YesNo regularReturn; + private ShortcutResult dekstop; + private ShortcutResult menu; + + public AccessWarningPaneComplexReturn(boolean b) { + if (b) { + this.regularReturn = YesNo.yes(); + } else { + this.regularReturn = YesNo.no(); + } + } + + public AccessWarningPaneComplexReturn(BasicDialogValue.Primitive regularReturn) { + this.regularReturn = new YesNo(regularReturn); + } + + public void setDekstop(ShortcutResult dekstop) { + this.dekstop = dekstop; + } + + public ShortcutResult getDekstop() { + return dekstop; + } + + public void setMenu(ShortcutResult menu) { + this.menu = menu; + } + + public ShortcutResult getMenu() { + return menu; + } + + @Override + public boolean toBoolean() { + if (regularReturn == null) { + return false; + } + return regularReturn.toBoolean(); + } + + public YesNo getRegularReturn() { + return regularReturn; + } + + @Override + public int getButtonIndex() { + if (regularReturn == null) { + return BasicDialogValue.Primitive.NO.getLegacyButton(); + } else { + return regularReturn.getButtonIndex(); + } + } + + 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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/BasicDialogValue.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,129 @@ +/* + 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; + +public abstract class BasicDialogValue { + + public static enum Primitive { + + YES(0), NO(1), CANCEL(2), SANDBOX(2); + + private final int legacyButton; + + private Primitive(int legacyButton) { + this.legacyButton = legacyButton; + } + + public int getLegacyButton() { + return legacyButton; + } + + } + + static abstract class PrimitivesSubset implements DialogResult { + + protected final BasicDialogValue.Primitive value; + + abstract EnumSet<Primitive> getAllowedValues(); + + protected PrimitivesSubset(BasicDialogValue.Primitive value) { + this.value = value; + checkValue(value); + } + + final void checkValue(Primitive p) { + if (!getAllowedValues().contains(p)) { + throw new RuntimeException("Unsupported primitive " + p + ". Allowed are " + getAllowedValues().toString()); + } + } + + @Override + public String writeValue() { + if (value == null) { + return writeNUll(); + } + return value.name(); + } + + @Override + public boolean toBoolean() { + if (value == null || value == BasicDialogValue.Primitive.NO || value == BasicDialogValue.Primitive.CANCEL) { + return false; + } else { + return true; + } + } + + public BasicDialogValue.Primitive getValue() { + return value; + } + + public boolean compareValue(Primitive with) { + if (getValue() == null && with ==null){ + return true; + } + checkValue(with); + return getValue() == with; + } + + @Override + public int getButtonIndex() { + return BasicDialogValue.Primitive.NO.getLegacyButton(); + } + + } + + public static final EnumSet<Primitive> Yes = EnumSet.of(Primitive.YES); + public static final EnumSet<Primitive> YesNo = EnumSet.of(Primitive.YES, Primitive.NO); + public static final EnumSet<Primitive> YesCancel = EnumSet.of(Primitive.YES, Primitive.CANCEL); + public static final EnumSet<Primitive> YesNoCancel = EnumSet.of(Primitive.YES, Primitive.NO, Primitive.CANCEL); + public static final EnumSet<Primitive> YesNoSandbox = EnumSet.of(Primitive.YES, Primitive.NO, Primitive.SANDBOX); + + /** + * Current convention for null is empty string. + * + * @return "" + */ + public static String writeNUll() { + return ""; + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/DialogResult.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,62 @@ +/* + 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; + +/** + * Note - this interface do not force return type, otherwise we will end with Object again. + * It is just pointing out, that what is returned, is DialogResult, so it can be traced via code. + * Also it gathers some most used methods on various implementations. Feel free to enlarge the list! + * + */ +public interface DialogResult { + + /** + * the index of the button. By convention 0 = Yes. 1 = No, 2 = Cancel/sandbox + * + * @return button to be preselected in dialogue + */ + abstract public int getButtonIndex(); + + /** + * Simplified decision model whether dialog was approved or not. + * @return true only and only if dialog was approved + */ + abstract public boolean toBoolean(); + + abstract public String writeValue(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/NamePassword.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,80 @@ +/* + 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; + +public class NamePassword implements DialogResult { + + String name; + char[] password; + + public NamePassword(String name, char[] password) { + this.name = name; + this.password = password; + } + + @Override + public int getButtonIndex() { + return BasicDialogValue.Primitive.NO.getLegacyButton(); + + } + + public String getName() { + return name; + } + + public char[] getPassword() { + return password; + } + + //following three methods are not used by this class + @Override + public boolean toBoolean() { + throw new UnsupportedOperationException("Not supported yet."); + } + + + + public static NamePassword readValue(String s) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String writeValue() { + throw new UnsupportedOperationException("Not supported yet."); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/SetValueHandler.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,78 @@ +/* + Copyright (C) 2008 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.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import net.sourceforge.jnlp.security.SecurityDialog; + +/** + * Creates a handler that sets a dialog's value and then disposes it when + * activated + * + */ +public class SetValueHandler implements ActionListener { + + /** + * Create an ActionListener suitable for use with buttons. When this + * {@link ActionListener} is invoked, it will set the value of the + * {@link SecurityDialog} and then dispossed. + * + * @param dialog dialog ressonsible for actual operation + * @param returnValue may contain also information about default, preselected button + * @return the ActionListener instance. + */ + public static ActionListener createSetValueListener(SecurityDialog dialog, DialogResult returnValue) { + return new SetValueHandler(dialog, returnValue); + } + + private final DialogResult returnValue; + private final SecurityDialog dialog; + + private SetValueHandler(SecurityDialog dialog, DialogResult returnValue) { + this.dialog = dialog; + this.returnValue = returnValue; + } + + + @Override + public void actionPerformed(ActionEvent e) { + dialog.setValue(returnValue); + dialog.dispose(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/Yes.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,67 @@ +/* + 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; + +public class Yes extends BasicDialogValue.PrimitivesSubset { + + public static Yes readValue(String s) { + BasicDialogValue.Primitive x = BasicDialogValue.Primitive.valueOf(s); + if (x == BasicDialogValue.Primitive.YES) { + return new Yes(); + } + throw new RuntimeException("Expected YES and only YES. Got" + x); + + } + + + public Yes() { + super(BasicDialogValue.Primitive.YES); + } + + @Override + public int getButtonIndex() { + return BasicDialogValue.Primitive.YES.getLegacyButton(); + } + + @Override + public EnumSet<BasicDialogValue.Primitive> getAllowedValues() { + return BasicDialogValue.Yes; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesCancel.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,70 @@ +/* + 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; + +public class YesCancel extends BasicDialogValue.PrimitivesSubset { + + public static YesCancel yes() { + return new YesCancel(BasicDialogValue.Primitive.YES); + } + + public static YesCancel cancel() { + return new YesCancel(BasicDialogValue.Primitive.CANCEL); + } + + public static YesCancel readValue(String s) { + return new YesCancel(BasicDialogValue.Primitive.valueOf(s)); + } + + private YesCancel(BasicDialogValue.Primitive valueOf) { + super(valueOf); + } + + @Override + public int getButtonIndex() { + //use rather NO, however nonsense it seems? + return BasicDialogValue.Primitive.CANCEL.getLegacyButton(); + } + + @Override + public EnumSet<BasicDialogValue.Primitive> getAllowedValues() { + return BasicDialogValue.YesCancel; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNo.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,64 @@ +/* + 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; + +public class YesNo extends BasicDialogValue.PrimitivesSubset { + + public static YesNo yes() { + return new YesNo(BasicDialogValue.Primitive.YES); + } + + public static YesNo no() { + return new YesNo(BasicDialogValue.Primitive.NO); + } + + public static YesNo readValue(String s) { + return new YesNo(BasicDialogValue.Primitive.valueOf(s)); + } + + YesNo(BasicDialogValue.Primitive valueOf) { + super(valueOf); + } + + @Override + public EnumSet<BasicDialogValue.Primitive> getAllowedValues() { + return BasicDialogValue.YesNo; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNoCancel.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,68 @@ +/* + 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; + +public class YesNoCancel extends BasicDialogValue.PrimitivesSubset { + + public static YesNoCancel yes() { + return new YesNoCancel(BasicDialogValue.Primitive.YES); + } + + public static YesNoCancel no() { + return new YesNoCancel(BasicDialogValue.Primitive.NO); + } + + public static YesNoCancel cancel() { + return new YesNoCancel(BasicDialogValue.Primitive.CANCEL); + } + + public static YesNoCancel readValue(String s) { + return new YesNoCancel(BasicDialogValue.Primitive.valueOf(s)); + } + + private YesNoCancel(BasicDialogValue.Primitive valueOf) { + super(valueOf); + } + + @Override + public EnumSet<BasicDialogValue.Primitive> getAllowedValues() { + return BasicDialogValue.YesNoCancel; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/security/dialogresults/YesNoSandbox.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,68 @@ +/* + 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; + +public class YesNoSandbox extends BasicDialogValue.PrimitivesSubset { + + public static YesNoSandbox yes() { + return new YesNoSandbox(BasicDialogValue.Primitive.YES); + } + + public static YesNoSandbox no() { + return new YesNoSandbox(BasicDialogValue.Primitive.NO); + } + + public static YesNoSandbox sandbox() { + return new YesNoSandbox(BasicDialogValue.Primitive.SANDBOX); + } + + public static YesNoSandbox readValue(String s) { + return new YesNoSandbox(BasicDialogValue.Primitive.valueOf(s)); + } + + private YesNoSandbox(BasicDialogValue.Primitive valueOf) { + super(valueOf); + } + + @Override + public EnumSet<BasicDialogValue.Primitive> getAllowedValues() { + return BasicDialogValue.YesNoSandbox; + } + +}
--- a/netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPane.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPane.java Tue Jun 09 13:02:00 2015 +0200 @@ -1,4 +1,4 @@ -/* AccessWarningPane.java +/* Copyright (C) 2008 Red Hat, Inc. This file is part of IcedTea. @@ -71,6 +71,8 @@ import net.sourceforge.jnlp.security.CertVerifier; import net.sourceforge.jnlp.security.SecurityDialog; 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.util.FileUtils; import net.sourceforge.jnlp.util.XDesktopEntry; @@ -90,6 +92,7 @@ HtmlShortcutPanel htmlPanelDesktop; HtmlShortcutPanel htmlPanelMenu; RememberPanel rememberPanel; + public AccessWarningPane(SecurityDialog x, CertVerifier certVerifier) { super(x, certVerifier); addComponents(); @@ -297,7 +300,7 @@ @Override public void actionPerformed(ActionEvent e) { - parent.setValue(getModifier(0)); //according to createSetValueListener 0 is ok and 1 cancel + parent.setValue(getModifier(BasicDialogValue.Primitive.YES)); parent.dispose(); } }); @@ -305,7 +308,7 @@ @Override public void actionPerformed(ActionEvent e) { - parent.setValue(getModifier(1)); //according to createSetValueListener 0 is ok and 1 cancel + parent.setValue(getModifier(BasicDialogValue.Primitive.NO)); parent.dispose(); } }); @@ -326,7 +329,7 @@ } - private AccessWarningPaneComplexReturn getModifier(int button) { + private AccessWarningPaneComplexReturn getModifier(BasicDialogValue.Primitive button) { AccessWarningPaneComplexReturn ar = new AccessWarningPaneComplexReturn(button); if (desktopCheck != null) { if (htmlPanelDesktop != null) {
--- a/netx/net/sourceforge/jnlp/security/dialogs/AccessWarningPaneComplexReturn.java Mon Jun 01 14:43:43 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -package net.sourceforge.jnlp.security.dialogs; - -/* - Copyright (C) 2008 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. -*/ - -public class AccessWarningPaneComplexReturn { - - - public static class ShortcutResult { - - public static enum Shortcut { - - BROWSER, GENERATED_JNLP, JNLP_HREF, JAVAWS_HTML; - } - - private String browser = "not_found_browser"; - private boolean fixHref = false; - private Shortcut shortcutType = null; - private final boolean create; - - public ShortcutResult(boolean create) { - this.create = create; - } - - public boolean isCreate() { - return create; - } - - public String getBrowser() { - return browser; - } - - public Shortcut getShortcutType() { - return shortcutType; - } - - public boolean isFixHref() { - return fixHref; - } - - public void setBrowser(String browser) { - this.browser = browser; - } - - public void setFixHref(boolean fixHref) { - this.fixHref = fixHref; - } - - public void setShortcutType(Shortcut shortcutType) { - this.shortcutType = shortcutType; - } - - } - - - public static enum RemeberType { - - REMEMBER_BY_APP, REMEMBER_BY_DOMAIN, REMEMBER_DONT; - } - - - private final int regularReturn; - private ShortcutResult dekstop; - private ShortcutResult menu; - private RemeberType rember; - - - //0 = true; legacy...:-/ - public AccessWarningPaneComplexReturn(int regularReturn) { - this.regularReturn = regularReturn; - } - - public void setDekstop(ShortcutResult dekstop) { - this.dekstop = dekstop; - } - - public ShortcutResult getDekstop() { - return dekstop; - } - - public void setMenu(ShortcutResult menu) { - this.menu = menu; - } - - public ShortcutResult getMenu() { - return menu; - } - - public void setRember(RemeberType rember) { - this.rember = rember; - } - - public RemeberType getRember() { - return rember; - } - - - - public int getRegularReturn() { - return regularReturn; - } - - public boolean getRegularReturnAsBoolean() { - return regularReturn == 0 ? true : false; - } - -}
--- a/netx/net/sourceforge/jnlp/security/dialogs/AppletWarningPane.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/AppletWarningPane.java Tue Jun 09 13:02:00 2015 +0200 @@ -50,6 +50,8 @@ import javax.swing.JPanel; import net.sourceforge.jnlp.security.CertVerifier; import net.sourceforge.jnlp.security.SecurityDialog; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.YesNoCancel; public class AppletWarningPane extends SecurityDialogPanel { @@ -96,9 +98,9 @@ yes.setPreferredSize(d); no.setPreferredSize(d); cancel.setPreferredSize(d); - yes.addActionListener(createSetValueListener(parent, 0)); - no.addActionListener(createSetValueListener(parent, 1)); - cancel.addActionListener(createSetValueListener(parent, 2)); + yes.addActionListener(SetValueHandler.createSetValueListener(parent, YesNoCancel.yes())); + no.addActionListener(SetValueHandler.createSetValueListener(parent, YesNoCancel.no())); + cancel.addActionListener(SetValueHandler.createSetValueListener(parent, YesNoCancel.cancel())); initialFocusComponent = cancel; buttonPanel.add(yes); buttonPanel.add(no);
--- a/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java Tue Jun 09 13:02:00 2015 +0200 @@ -73,6 +73,8 @@ import net.sourceforge.jnlp.security.SecurityDialog; import net.sourceforge.jnlp.security.SecurityDialogs.AccessType; import net.sourceforge.jnlp.security.SecurityUtil; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.YesNoSandbox; import net.sourceforge.jnlp.util.FileUtils; import net.sourceforge.jnlp.util.logging.OutputController; @@ -271,12 +273,12 @@ sandbox.setEnabled(!alwaysTrust.isSelected()); - run.addActionListener(createSetValueListener(parent, 0)); + run.addActionListener(SetValueHandler.createSetValueListener(parent, YesNoSandbox.yes())); run.addActionListener(new CheckBoxListener()); - sandbox.addActionListener(createSetValueListener(parent, 1)); + sandbox.addActionListener(SetValueHandler.createSetValueListener(parent, YesNoSandbox.sandbox())); - cancel.addActionListener(createSetValueListener(parent, 2)); + cancel.addActionListener(SetValueHandler.createSetValueListener(parent, YesNoSandbox.no())); initialFocusComponent = cancel; buttonPanel.add(run);
--- a/netx/net/sourceforge/jnlp/security/dialogs/CertsInfoPane.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/CertsInfoPane.java Tue Jun 09 13:02:00 2015 +0200 @@ -58,6 +58,8 @@ import net.sourceforge.jnlp.security.CertVerifier; import net.sourceforge.jnlp.security.SecurityDialog; import net.sourceforge.jnlp.security.SecurityUtil; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.Yes; /** * Provides the panel for the Certificate Info dialog. This dialog displays data from @@ -223,7 +225,7 @@ JPanel buttonPane = new JPanel(new BorderLayout()); JButton close = new JButton(R("ButClose")); JButton copyToClipboard = new JButton(R("ButCopy")); - close.addActionListener(createSetValueListener(parent, 0)); + close.addActionListener(SetValueHandler.createSetValueListener(parent, new Yes())); copyToClipboard.addActionListener(new CopyToClipboardHandler()); buttonPane.add(close, BorderLayout.EAST); buttonPane.add(copyToClipboard, BorderLayout.WEST);
--- a/netx/net/sourceforge/jnlp/security/dialogs/MissingALACAttributePanel.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/MissingALACAttributePanel.java Tue Jun 09 13:02:00 2015 +0200 @@ -64,6 +64,8 @@ import javax.swing.event.HyperlinkListener; import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.security.SecurityDialog; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.YesNo; import net.sourceforge.jnlp.util.UrlUtils; import net.sourceforge.jnlp.util.logging.OutputController; @@ -111,9 +113,7 @@ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { Desktop.getDesktop().browse(e.getURL().toURI()); } - } catch (IOException ex) { - OutputController.getLogger().log(ex); - } catch (URISyntaxException ex) { + } catch (IOException | URISyntaxException ex) { OutputController.getLogger().log(ex); } } @@ -134,8 +134,8 @@ Dimension d = new Dimension(buttonWidth, buttonHeight); yes.setPreferredSize(d); no.setPreferredSize(d); - yes.addActionListener(createSetValueListener(parent, 0)); - no.addActionListener(createSetValueListener(parent, 1)); + yes.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.yes())); + no.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.no())); initialFocusComponent = no; buttonPanel.add(yes); buttonPanel.add(no); @@ -149,7 +149,7 @@ } public static void main(String[] args) throws MalformedURLException { - Set<URL> s = new HashSet<URL>(); + Set<URL> s = new HashSet<>(); s.add(new URL("http:/blah.com/blah")); s.add(new URL("http:/blah.com/blah/blah")); MissingALACAttributePanel w = new MissingALACAttributePanel(null, "HelloWorld", "http://nbblah.url", UrlUtils.setOfUrlsToHtmlList(s));
--- a/netx/net/sourceforge/jnlp/security/dialogs/MissingPermissionsAttributePanel.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/MissingPermissionsAttributePanel.java Tue Jun 09 13:02:00 2015 +0200 @@ -61,6 +61,9 @@ import javax.swing.event.HyperlinkListener; 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.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.YesNo; import net.sourceforge.jnlp.util.logging.OutputController; public class MissingPermissionsAttributePanel extends SecurityDialogPanel { @@ -127,8 +130,8 @@ Dimension d = new Dimension(buttonWidth, buttonHeight); yes.setPreferredSize(d); no.setPreferredSize(d); - yes.addActionListener(createSetValueListener(parent, 0)); - no.addActionListener(createSetValueListener(parent, 1)); + yes.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.yes())); + no.addActionListener(SetValueHandler.createSetValueListener(parent, YesNo.no())); initialFocusComponent = no; buttonPanel.add(yes); buttonPanel.add(no);
--- a/netx/net/sourceforge/jnlp/security/dialogs/MoreInfoPane.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/MoreInfoPane.java Tue Jun 09 13:02:00 2015 +0200 @@ -54,6 +54,8 @@ import javax.swing.SwingConstants; import net.sourceforge.jnlp.security.CertVerifier; import net.sourceforge.jnlp.security.SecurityDialog; +import net.sourceforge.jnlp.security.dialogresults.SetValueHandler; +import net.sourceforge.jnlp.security.dialogresults.Yes; /** * Provides the panel for the More Info dialog. This dialog shows details about an @@ -63,7 +65,7 @@ */ public class MoreInfoPane extends SecurityDialogPanel { - private boolean showSignedJNLPWarning; + private final boolean showSignedJNLPWarning; public MoreInfoPane(SecurityDialog x, CertVerifier certVerifier) { super(x, certVerifier); @@ -108,7 +110,7 @@ JButton certDetails = new JButton(R("SCertificateDetails")); certDetails.addActionListener(new CertInfoButtonListener()); JButton close = new JButton(R("ButClose")); - close.addActionListener(createSetValueListener(parent, 0)); + close.addActionListener(SetValueHandler.createSetValueListener(parent, new Yes())); buttonsPanel.add(certDetails, BorderLayout.WEST); buttonsPanel.add(close, BorderLayout.EAST); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
--- a/netx/net/sourceforge/jnlp/security/dialogs/PasswordAuthenticationPane.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/PasswordAuthenticationPane.java Tue Jun 09 13:02:00 2015 +0200 @@ -51,6 +51,7 @@ import javax.swing.JPasswordField; import javax.swing.JTextField; import net.sourceforge.jnlp.security.SecurityDialog; +import net.sourceforge.jnlp.security.dialogresults.NamePassword; /** * Modal non-minimizable dialog to request http authentication credentials @@ -80,7 +81,7 @@ * Initialized the dialog components */ - public void addComponents() { + public final void addComponents() { JLabel jlInfo = new JLabel(""); jlInfo.setText("<html>" + R("SAuthenticationPrompt", type, host, prompt) + "</html>"); @@ -159,7 +160,7 @@ ActionListener acceptActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - parent.setValue(new Object[] { jtfUserName.getText(), jpfPassword.getPassword() }); + parent.setValue(new NamePassword(jtfUserName.getText(), jpfPassword.getPassword())); parent.dispose(); } };
--- a/netx/net/sourceforge/jnlp/security/dialogs/SecurityDialogPanel.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/SecurityDialogPanel.java Tue Jun 09 13:02:00 2015 +0200 @@ -38,8 +38,6 @@ package net.sourceforge.jnlp.security.dialogs; import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.JComponent; import javax.swing.JPanel; @@ -75,17 +73,6 @@ return "<html>" + s + "</html>"; } - /** - * Create an ActionListener suitable for use with buttons. When this {@link ActionListener} - * is invoked, it will set the value of the {@link SecurityDialog} and then dispossed. - * - * @param buttonIndex the index of the button. By convention 0 = Yes. 1 = No, 2 = Cancel - * @return the ActionListener instance. - */ - protected ActionListener createSetValueListener(SecurityDialog dialog, int buttonIndex) { - return new SetValueHandler(dialog, buttonIndex); - } - @Override public void setVisible(boolean aFlag) { super.setVisible(aFlag); @@ -98,24 +85,4 @@ } } - /** - * Creates a handler that sets a dialog's value and then disposes it when activated - * - */ - private static class SetValueHandler implements ActionListener { - - Integer buttonIndex; - SecurityDialog dialog; - - public SetValueHandler(SecurityDialog dialog, int buttonIndex) { - this.dialog = dialog; - this.buttonIndex = buttonIndex; - } - - @Override - public void actionPerformed(ActionEvent e) { - dialog.setValue(buttonIndex); - dialog.dispose(); - } - } }
--- a/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/security/dialogs/remember/RememberPanel.java Tue Jun 09 13:02:00 2015 +0200 @@ -51,6 +51,7 @@ 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 { @@ -159,7 +160,8 @@ Container p = RememberPanel.this.getParent(); while (p != null) { if (p instanceof SecurityDialog) { - ((SecurityDialog) p).setValue(action); + //TODO this must not set value, this must return something absolutely different + ((SecurityDialog) p).setValue(new Garbage(action)); ((SecurityDialog) p).dispose(); break; } @@ -168,4 +170,36 @@ } }; } + + //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."); + } + + } }
--- a/netx/net/sourceforge/jnlp/services/ServiceUtil.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/services/ServiceUtil.java Tue Jun 09 13:02:00 2015 +0200 @@ -260,8 +260,8 @@ Boolean b = AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { - boolean b = SecurityDialogs.showAccessWarningDialogB(tmpType, - tmpApp.getJNLPFile(), tmpExtras); + boolean b = SecurityDialogs.showAccessWarningDialog(tmpType, + tmpApp.getJNLPFile(), tmpExtras).toBoolean(); return b; } });
--- a/netx/net/sourceforge/jnlp/util/XDesktopEntry.java Mon Jun 01 14:43:43 2015 +0200 +++ b/netx/net/sourceforge/jnlp/util/XDesktopEntry.java Tue Jun 09 13:02:00 2015 +0200 @@ -46,7 +46,7 @@ import net.sourceforge.jnlp.cache.UpdatePolicy; import net.sourceforge.jnlp.config.PathsAndFiles; import net.sourceforge.jnlp.runtime.JNLPRuntime; -import net.sourceforge.jnlp.security.dialogs.AccessWarningPaneComplexReturn; +import net.sourceforge.jnlp.security.dialogresults.AccessWarningPaneComplexReturn; /** * This class builds a (freedesktop.org) desktop entry out of a {@link JNLPFile}
--- a/tests/netx/unit/net/sourceforge/jnlp/security/SecurityDialogsTest.java Mon Jun 01 14:43:43 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +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; - -import static net.sourceforge.jnlp.security.SecurityDialogs.getIntegerResponseAsAppletAction; -import static net.sourceforge.jnlp.security.SecurityDialogs.getIntegerResponseAsBoolean; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static net.sourceforge.jnlp.security.SecurityDialogs.AppletAction.*; - -import org.junit.Test; - -public class SecurityDialogsTest { - - @Test - public void testGetIntegerResponseAsBoolean() throws Exception { - Object nullRef = null; - Object objRef = new Object(); - Float floatRef = 0.0f; - Double doubleRef = 0.0d; - Long longRef = (long) 0; - Byte byteRef = (byte)0; - Short shortRef = (short)0; - String strRef = "0"; - Integer intRef1 = 5; - Integer intRef2 = 0; - - assertFalse("null reference should have resulted in false", getIntegerResponseAsBoolean(nullRef)); - assertFalse("Object reference should have resulted in false", getIntegerResponseAsBoolean(objRef)); - assertFalse("Float reference should have resulted in false", getIntegerResponseAsBoolean(floatRef)); - assertFalse("Double reference should have resulted in false", getIntegerResponseAsBoolean(doubleRef)); - assertFalse("Long reference should have resulted in false", getIntegerResponseAsBoolean(longRef)); - assertFalse("Byte reference should have resulted in false", getIntegerResponseAsBoolean(byteRef)); - assertFalse("Short reference should have resulted in false", getIntegerResponseAsBoolean(shortRef)); - assertFalse("String reference should have resulted in false", getIntegerResponseAsBoolean(strRef)); - assertFalse("Non-0 Integer reference should have resulted in false", getIntegerResponseAsBoolean(intRef1)); - assertTrue("0 Integer reference should have resulted in true", getIntegerResponseAsBoolean(intRef2)); - } - - @Test - public void testGetIntegerResponseAsAppletAction() throws Exception { - Object nullRef = null; - Object objRef = new Object(); - Float floatRef = 0.0f; - Double doubleRef = 0.0d; - Long longRef = (long) 0; - Byte byteRef = (byte) 0; - Short shortRef = (short) 0; - String strRef = "0"; - Integer intRef1 = 0; - Integer intRef2 = 1; - Integer intRef3 = 2; - Integer intRef4 = 3; - - assertEquals("null reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(nullRef), CANCEL); - assertEquals("Object reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(objRef), CANCEL); - assertEquals("Float reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(floatRef), CANCEL); - assertEquals("Double reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(doubleRef), CANCEL); - assertEquals("Long reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(longRef), CANCEL); - assertEquals("Byte reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(byteRef), CANCEL); - assertEquals("Short reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(shortRef), CANCEL); - assertEquals("String reference should have resulted in CANCEL", getIntegerResponseAsAppletAction(strRef), CANCEL); - assertEquals("Integer reference 0 should have resulted in RUN", getIntegerResponseAsAppletAction(intRef1), RUN); - assertEquals("Integer reference 1 should have resulted in SANDBOX", getIntegerResponseAsAppletAction(intRef2), SANDBOX); - assertEquals("Integer reference 2 should have resulted in CANCEL", getIntegerResponseAsAppletAction(intRef3), CANCEL); - assertEquals("Integer reference 3 should have resulted in CANCEL", getIntegerResponseAsAppletAction(intRef4), CANCEL); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/AccessWarningPaneComplexReturnTest.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,118 @@ +package net.sourceforge.jnlp.security.dialogresults; + +import org.junit.Assert; +import org.junit.Test; + +/* + Copyright (C) 2008 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. + */ +public class AccessWarningPaneComplexReturnTest { + + @Test + public void AccessWarningPaneComplexReturnTestReadWrite1() { + AccessWarningPaneComplexReturn aw1 = new AccessWarningPaneComplexReturn(true); + Assert.assertEquals(aw1.getRegularReturn().getValue(), BasicDialogValue.Primitive.YES); + Assert.assertEquals(aw1.getRegularReturn().getValue(), new AccessWarningPaneComplexReturn(BasicDialogValue.Primitive.YES).getRegularReturn().getValue()); + String s1 = aw1.writeValue(); + AccessWarningPaneComplexReturn aw11 = AccessWarningPaneComplexReturn.readValue(s1); + Assert.assertEquals(aw1.getRegularReturn().getValue(), aw11.getRegularReturn().getValue()); + Assert.assertEquals(aw1.getDekstop(), aw11.getDekstop()); + Assert.assertEquals(aw1.getMenu(), aw11.getMenu()); + Assert.assertEquals(null, aw11.getDekstop()); + Assert.assertEquals(null, aw11.getMenu()); + } + + public void AccessWarningPaneComplexReturnTestReadWrite2() { + AccessWarningPaneComplexReturn aw2 = new AccessWarningPaneComplexReturn(false); + Assert.assertEquals(aw2.getRegularReturn().getValue(), BasicDialogValue.Primitive.NO); + Assert.assertEquals(aw2.getRegularReturn().getValue(), new AccessWarningPaneComplexReturn(BasicDialogValue.Primitive.NO).getRegularReturn().getValue()); + String s2 = aw2.writeValue(); + AccessWarningPaneComplexReturn aw22 = AccessWarningPaneComplexReturn.readValue(s2); + Assert.assertEquals(aw2.getRegularReturn().getValue(), aw22.getRegularReturn().getValue()); + Assert.assertEquals(aw2.getDekstop(), aw22.getDekstop()); + Assert.assertEquals(aw2.getMenu(), aw22.getMenu()); + Assert.assertEquals(null, aw22.getDekstop()); + Assert.assertEquals(null, aw22.getMenu()); + + } + + @Test(expected = Exception.class) + public void AccessWarningPaneComplexReturnTestReadWriteBad1() { + AccessWarningPaneComplexReturn accessWarningPaneComplexReturn = new AccessWarningPaneComplexReturn(BasicDialogValue.Primitive.CANCEL); +} + @Test(expected = Exception.class) + public void AccessWarningPaneComplexReturnTestReadWriteBad2() { + AccessWarningPaneComplexReturn accessWarningPaneComplexReturn = new AccessWarningPaneComplexReturn(BasicDialogValue.Primitive.SANDBOX); +} + + @Test + public void AccessWarningPaneComplexReturnTestReadWrite3() { + AccessWarningPaneComplexReturn aw1 = new AccessWarningPaneComplexReturn(true); + aw1.setDekstop(new AccessWarningPaneComplexReturn.ShortcutResult(true)); + aw1.setMenu(new AccessWarningPaneComplexReturn.ShortcutResult(false)); + String s1 = aw1.writeValue(); + AccessWarningPaneComplexReturn aw11 = AccessWarningPaneComplexReturn.readValue(s1); + Assert.assertEquals(aw1.getRegularReturn().getValue(), aw11.getRegularReturn().getValue()); + Assert.assertEquals(aw1.getDekstop(), aw11.getDekstop()); + Assert.assertEquals(aw1.getMenu(), aw11.getMenu()); + Assert.assertNotEquals(null, aw11.getDekstop()); + Assert.assertNotEquals(null, aw11.getMenu()); + Assert.assertEquals(true, aw11.getDekstop().isCreate()); + Assert.assertEquals(false, aw11.getMenu().isCreate()); + } + + @Test + public void AccessWarningPaneComplexReturnTestReadWrite4() { + AccessWarningPaneComplexReturn aw1 = new AccessWarningPaneComplexReturn(true); + aw1.setDekstop(new AccessWarningPaneComplexReturn.ShortcutResult("b1",true, AccessWarningPaneComplexReturn.ShortcutResult.Shortcut.BROWSER, false)); + aw1.setMenu(new AccessWarningPaneComplexReturn.ShortcutResult("b2",false, AccessWarningPaneComplexReturn.ShortcutResult.Shortcut.JAVAWS_HTML, true)); + String s1 = aw1.writeValue(); + AccessWarningPaneComplexReturn aw11 = AccessWarningPaneComplexReturn.readValue(s1); + Assert.assertEquals(aw1.getRegularReturn().getValue(), aw11.getRegularReturn().getValue()); + Assert.assertEquals(aw1.getDekstop(), aw11.getDekstop()); + Assert.assertEquals(aw1.getMenu(), aw11.getMenu()); + Assert.assertNotEquals(null, aw11.getDekstop()); + Assert.assertNotEquals(null, aw11.getMenu()); + Assert.assertEquals(false, aw11.getDekstop().isCreate()); + Assert.assertEquals(true, aw11.getMenu().isCreate()); + Assert.assertEquals("b1", aw11.getDekstop().getBrowser()); + Assert.assertEquals("b2", aw11.getMenu().getBrowser()); + Assert.assertEquals(AccessWarningPaneComplexReturn.ShortcutResult.Shortcut.BROWSER, aw11.getDekstop().getShortcutType()); + Assert.assertEquals(AccessWarningPaneComplexReturn.ShortcutResult.Shortcut.JAVAWS_HTML, aw11.getMenu().getShortcutType()); + Assert.assertEquals(true, aw11.getDekstop().isFixHref()); + Assert.assertEquals(false, aw11.getMenu().isFixHref()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesCancelTest.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,77 @@ +/* + 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 org.junit.Assert; +import org.junit.Test; + +public class YesCancelTest { + + @Test + public void yesReadWrite() { + YesCancel y = YesCancel.yes(); + String s = y.writeValue(); + YesCancel yy = YesCancel.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + + } + + @Test + public void cacnelReadWrite() { + YesCancel y = YesCancel.cancel(); + String s = y.writeValue(); + YesCancel yy = YesCancel.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertFalse(y.toBoolean()); + } + + + @Test(expected = Exception.class) + public void sandboxRead() { + YesCancel y = YesCancel.readValue(BasicDialogValue.Primitive.SANDBOX.name()); + } + + public void cacnelRead() { + YesCancel y = YesCancel.readValue(BasicDialogValue.Primitive.CANCEL.name()); + Assert.assertFalse(y.toBoolean()); + } + + @Test(expected = Exception.class) + public void nonsenseRead() { + YesCancel y = YesCancel.readValue("blah"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesNoCancelTest.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,96 @@ +/* + 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 org.junit.Assert; +import org.junit.Test; + +public class YesNoCancelTest { + + @Test + public void yesReadWrite() { + YesNoCancel y = YesNoCancel.yes(); + String s = y.writeValue(); + YesNoCancel yy = YesNoCancel.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertTrue(y.toBoolean()); + } + + @Test + public void noReadWrite() { + YesNoCancel y = YesNoCancel.no(); + String s = y.writeValue(); + YesNoCancel yy = YesNoCancel.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertFalse(y.toBoolean()); + } + + @Test + public void sandboxReadWrite() { + YesNoCancel y = YesNoCancel.cancel(); + String s = y.writeValue(); + YesNoCancel yy = YesNoCancel.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertFalse(y.toBoolean()); + + } + + @Test(expected = Exception.class) + public void sandboxRead() { + YesNoCancel y = YesNoCancel.readValue(BasicDialogValue.Primitive.SANDBOX.name()); + } + + public void cancelRead() { + YesNoCancel y = YesNoCancel.readValue(BasicDialogValue.Primitive.CANCEL.name()); + Assert.assertFalse(y.toBoolean()); + } + + public void noRead() { + YesNoCancel y = YesNoCancel.readValue(BasicDialogValue.Primitive.NO.name()); + Assert.assertFalse(y.toBoolean()); + } + + public void yesRead() { + YesNoCancel y = YesNoCancel.readValue(BasicDialogValue.Primitive.YES.name()); + Assert.assertTrue(y.toBoolean()); + } + + @Test(expected = Exception.class) + public void nonsenseRead() { + YesNoCancel y = YesNoCancel.readValue("blah"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesNoSandboxTest.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,97 @@ +/* + 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 org.junit.Assert; +import org.junit.Test; + +public class YesNoSandboxTest { + + @Test + public void yesReadWrite() { + YesNoSandbox y = YesNoSandbox.yes(); + String s = y.writeValue(); + YesNoSandbox yy = YesNoSandbox.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertTrue(y.toBoolean()); + } + + @Test + public void noReadWrite() { + YesNoSandbox y = YesNoSandbox.no(); + String s = y.writeValue(); + YesNoSandbox yy = YesNoSandbox.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertFalse(y.toBoolean()); + + } + + @Test + public void sandboxReadWrite() { + YesNoSandbox y = YesNoSandbox.sandbox(); + String s = y.writeValue(); + YesNoSandbox yy = YesNoSandbox.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertTrue(y.toBoolean()); + } + + @Test(expected = Exception.class) + public void cancelRead() { + YesNoSandbox y = YesNoSandbox.readValue(BasicDialogValue.Primitive.CANCEL.name()); + } + + @Test(expected = Exception.class) + public void nonsenseRead() { + YesNoSandbox y = YesNoSandbox.readValue("blah"); + } + + + public void noRead() { + YesNoSandbox y = YesNoSandbox.readValue(BasicDialogValue.Primitive.NO.name()); + Assert.assertFalse(y.toBoolean()); + } + + public void yesRead() { + YesNoSandbox y = YesNoSandbox.readValue(BasicDialogValue.Primitive.YES.name()); + Assert.assertTrue(y.toBoolean()); + } + + public void sandboxRead() { + YesNoSandbox y = YesNoSandbox.readValue(BasicDialogValue.Primitive.SANDBOX.name()); + Assert.assertTrue(y.toBoolean()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesNoTestTest.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,88 @@ +/* + 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 org.junit.Assert; +import org.junit.Test; + +public class YesNoTestTest { + + @Test + public void yesReadWrite() { + YesNo y = YesNo.yes(); + String s = y.writeValue(); + YesNo yy = YesNo.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertTrue(y.toBoolean()); + } + + @Test + public void noReadWrite() { + YesNo y = YesNo.no(); + String s = y.writeValue(); + YesNo yy = YesNo.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertFalse(y.toBoolean()); + + } + + @Test(expected = Exception.class) + public void cancelRead() { + YesNo y = YesNo.readValue(BasicDialogValue.Primitive.CANCEL.name()); + } + + @Test(expected = Exception.class) + public void sandboxRead() { + YesNo y = YesNo.readValue(BasicDialogValue.Primitive.SANDBOX.name()); + } + + @Test(expected = Exception.class) + public void nonsenseRead() { + YesNo y = YesNo.readValue("blah"); + } + + public void noRead() { + YesNo y = YesNo.readValue(BasicDialogValue.Primitive.NO.name()); + Assert.assertFalse(y.toBoolean()); + } + + public void yesRead() { + YesNo y = YesNo.readValue(BasicDialogValue.Primitive.YES.name()); + Assert.assertTrue(y.toBoolean()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/dialogresults/YesTest.java Tue Jun 09 13:02:00 2015 +0200 @@ -0,0 +1,79 @@ +/* + 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 org.junit.Assert; +import org.junit.Test; + +public class YesTest { + + @Test + public void yesReadWrite() { + Yes y = new Yes(); + String s = y.writeValue(); + Yes yy = Yes.readValue(s); + Assert.assertEquals(y.getValue(), yy.getValue()); + Assert.assertTrue(y.toBoolean()); + + } + @Test(expected = Exception.class) + public void yesReadOk() { + Yes yy = Yes.readValue(BasicDialogValue.Primitive.YES.toString()); + + } + + @Test(expected = Exception.class) + public void yesReadNonsense1() { + Yes yy = Yes.readValue("blah"); + + } + @Test(expected = Exception.class) + public void yesReadNonsense2() { + Yes yy = Yes.readValue(BasicDialogValue.Primitive.CANCEL.toString()); + + } + @Test(expected = Exception.class) + public void yesReadNonsense3() { + Yes yy = Yes.readValue(BasicDialogValue.Primitive.NO.toString()); + } + + @Test(expected = Exception.class) + public void yesReadNonsense4() { + Yes yy = Yes.readValue(BasicDialogValue.Primitive.SANDBOX.toString()); + + } +}