Class HubSwingClientAuthorizer

  • All Implemented Interfaces:
    ClientAuthorizer

    public class HubSwingClientAuthorizer
    extends java.lang.Object
    implements ClientAuthorizer
    ClientAuthorizer implementation that queries the user for permission via a popup dialogue.
    Since:
    2 Feb 2011
    Author:
    Mark Taylor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.logging.Logger logger_  
      private static int MAX_POPUP_WIDTH  
      private java.awt.Component parent_  
    • Constructor Summary

      Constructors 
      Constructor Description
      HubSwingClientAuthorizer​(java.awt.Component parent)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void attemptSetAlwaysOnTop​(java.awt.Window win, boolean isOnTop)
      Tries to set the always-on-top property of a window.
      boolean authorize​(HttpServer.Request request, java.lang.String appName)
      Indicates whether an HTTP request representing an otherwise unauthorized connection attempt will be permitted access to sensitive system resources.
      private javax.swing.JComponent createLabelledFields​(java.util.Map infoMap, java.lang.String undeclaredWord)
      Returns a component displaying name/value pairs represented by a given String->String map.
      private java.lang.Object[] getMessageLines​(HttpServer.Request request, java.lang.String appName, AuthResourceBundle.Content authContent)
      Returns a "message" object describing the applying client to the user.
      private java.lang.String getOrigin​(java.lang.String uri)
      Returns the serialized origin for a given URI string.
      private static java.util.List toLineList​(java.lang.String linesTxt)
      Turns a multi-line string into a List of strings.
      private static java.lang.String[] toLines​(java.lang.String linesTxt)
      Turns a multi-line string into an array of strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • parent_

        private final java.awt.Component parent_
      • logger_

        private static final java.util.logging.Logger logger_
    • Constructor Detail

      • HubSwingClientAuthorizer

        public HubSwingClientAuthorizer​(java.awt.Component parent)
        Constructor.
        Parameters:
        parent - parent component
    • Method Detail

      • authorize

        public boolean authorize​(HttpServer.Request request,
                                 java.lang.String appName)
        Description copied from interface: ClientAuthorizer
        Indicates whether an HTTP request representing an otherwise unauthorized connection attempt will be permitted access to sensitive system resources. The client submitting the request provides the appName parameter by way of additional information about its identity. However, the value of this name is supplied by the (potentially malicious) applicant, so cannot in itself be regarded as an additional security measure.
        Specified by:
        authorize in interface ClientAuthorizer
        Parameters:
        request - incoming HTTP request
        appName - name by which the application submitting the request wishes to be known
        Returns:
        true iff submitter of the request should be permitted access to sensitive system resources in the future
      • getMessageLines

        private java.lang.Object[] getMessageLines​(HttpServer.Request request,
                                                   java.lang.String appName,
                                                   AuthResourceBundle.Content authContent)
        Returns a "message" object describing the applying client to the user. The return value is suitable for use as the msg argument of one of JOptionPane's methods.
        Parameters:
        request - HTTP request bearing the application
        appName - application name claimed by the applicant
        authContent - content of AuthResourceBundle bundle
        Returns:
        message array describing the applicant to the user
        See Also:
        JOptionPane
      • createLabelledFields

        private javax.swing.JComponent createLabelledFields​(java.util.Map infoMap,
                                                            java.lang.String undeclaredWord)
        Returns a component displaying name/value pairs represented by a given String->String map.
        Parameters:
        infoMap - String->String map of key->value pairs
        undeclaredWord - text to use to indicate a null value
        Returns:
        display component
      • getOrigin

        private java.lang.String getOrigin​(java.lang.String uri)
        Returns the serialized origin for a given URI string.
        Parameters:
        uri - URI
        Returns:
        origin of uri, null (note: not "null") if it cannot be determined
        See Also:
        The Web Origin Concept
      • toLines

        private static java.lang.String[] toLines​(java.lang.String linesTxt)
        Turns a multi-line string into an array of strings.
        Parameters:
        linesTxt - string perhaps with embedded \n characters
        Returns:
        array of lines
      • toLineList

        private static java.util.List toLineList​(java.lang.String linesTxt)
        Turns a multi-line string into a List of strings.
        Parameters:
        linesTxt - string perhaps with embedded \n characters
        Returns:
        list of String lines
      • attemptSetAlwaysOnTop

        private static void attemptSetAlwaysOnTop​(java.awt.Window win,
                                                  boolean isOnTop)
        Tries to set the always-on-top property of a window. This is only possible in JRE1.5 and later, so it's done here by reflection. If it fails, a logging message is emitted.
        Parameters:
        win - window to set
        isOnTop - true for on top, false for not