diff options
Diffstat (limited to 'netx/net/sourceforge/jnlp/security/SecurityDialogs.java')
-rw-r--r-- | netx/net/sourceforge/jnlp/security/SecurityDialogs.java | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java index 5f10d69..9b93a73 100644 --- a/netx/net/sourceforge/jnlp/security/SecurityDialogs.java +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogs.java @@ -40,6 +40,7 @@ package net.sourceforge.jnlp.security; import java.awt.Dialog.ModalityType; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.net.NetPermission; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.Semaphore; @@ -69,7 +70,8 @@ public class SecurityDialogs { SINGLE_CERT_INFO, ACCESS_WARNING, NOTALLSIGNED_WARNING, - APPLET_WARNING + APPLET_WARNING, + AUTHENTICATION, } /** The types of access which may need user permission. */ @@ -208,6 +210,40 @@ public class SecurityDialogs { } /** + * Present a dialog to the user asking them for authentication information, + * and returns the user's response. The caller must have + * NetPermission("requestPasswordAuthentication") for this to work. + * + * @param host The host for with authentication is needed + * @param port The port being accessed + * @param prompt The prompt (realm) as presented by the server + * @param type The type of server (proxy/web) + * @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) { + + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + NetPermission requestPermission + = new NetPermission("requestPasswordAuthentication"); + sm.checkPermission(requestPermission); + } + + final SecurityDialogMessage message = new SecurityDialogMessage(); + + message.dialogType = DialogType.AUTHENTICATION; + message.extras = new Object[] { host, port, prompt, type }; + + Object response = getUserResponse(message); + if (response == null) { + return null; + } else { + return (Object[]) response; + } + } + + /** * FIXME This is unused. Remove it? * @return (0, 1, 2) => (Yes, No, Cancel) */ |