< prev index next >

src/java.base/share/classes/java/net/SocketPermission.java

Print this page




 270      * The <i>actions</i> parameter contains a comma-separated list of the
 271      * actions granted for the specified host (and port(s)). Possible actions are
 272      * "connect", "listen", "accept", "resolve", or
 273      * any combination of those. "resolve" is automatically added
 274      * when any of the other three are specified.
 275      * <p>
 276      * Examples of SocketPermission instantiation are the following:
 277      * <pre>
 278      *    nr = new SocketPermission("www.example.com", "connect");
 279      *    nr = new SocketPermission("www.example.com:80", "connect");
 280      *    nr = new SocketPermission("*.example.com", "connect");
 281      *    nr = new SocketPermission("*.edu", "resolve");
 282      *    nr = new SocketPermission("204.160.241.0", "connect");
 283      *    nr = new SocketPermission("localhost:1024-65535", "listen");
 284      *    nr = new SocketPermission("204.160.241.0:1024-65535", "connect");
 285      * </pre>
 286      *
 287      * @param host the hostname or IP address of the computer, optionally
 288      * including a colon followed by a port or port range.
 289      * @param action the action string.





 290      */
 291     public SocketPermission(String host, String action) {
 292         super(getHost(host));
 293         // name initialized to getHost(host); NPE detected in getHost()
 294         init(getName(), getMask(action));
 295     }
 296 
 297 
 298     SocketPermission(String host, int mask) {
 299         super(getHost(host));
 300         // name initialized to getHost(host); NPE detected in getHost()
 301         init(getName(), mask);
 302     }
 303 
 304     private void setDeny() {
 305         defaultDeny = true;
 306     }
 307 
 308     private static String getHost(String host) {
 309         if (host.isEmpty()) {


 572             } else if (i >= 5 && (a[i-5] == 'a' || a[i-5] == 'A') &&
 573                                  (a[i-4] == 'c' || a[i-4] == 'C') &&
 574                                  (a[i-3] == 'c' || a[i-3] == 'C') &&
 575                                  (a[i-2] == 'e' || a[i-2] == 'E') &&
 576                                  (a[i-1] == 'p' || a[i-1] == 'P') &&
 577                                  (a[i] == 't' || a[i] == 'T'))
 578             {
 579                 matchlen = 6;
 580                 mask |= ACCEPT;
 581 
 582             } else {
 583                 // parse error
 584                 throw new IllegalArgumentException(
 585                         "invalid permission: " + action);
 586             }
 587 
 588             // make sure we didn't just match the tail of a word
 589             // like "ackbarfaccept".  Also, skip to the comma.
 590             boolean seencomma = false;
 591             while (i >= matchlen && !seencomma) {
 592                 switch(a[i-matchlen]) {
 593                 case ',':
 594                     seencomma = true;
 595                     break;
 596                 case ' ': case '\r': case '\n':
 597                 case '\f': case '\t':
 598                     break;
 599                 default:




 600                     throw new IllegalArgumentException(
 601                             "invalid permission: " + action);
 602                 }
 603                 i--;
 604             }
 605 
 606             // point i at the location of the comma minus one (or -1).
 607             i -= matchlen;
 608         }
 609 
 610         return mask;
 611     }
 612 
 613     private boolean isUntrusted()
 614         throws UnknownHostException
 615     {
 616         if (trusted) return false;
 617         if (invalid || untrusted) return true;
 618         try {
 619             if (!trustNameService && (defaultDeny ||




 270      * The <i>actions</i> parameter contains a comma-separated list of the
 271      * actions granted for the specified host (and port(s)). Possible actions are
 272      * "connect", "listen", "accept", "resolve", or
 273      * any combination of those. "resolve" is automatically added
 274      * when any of the other three are specified.
 275      * <p>
 276      * Examples of SocketPermission instantiation are the following:
 277      * <pre>
 278      *    nr = new SocketPermission("www.example.com", "connect");
 279      *    nr = new SocketPermission("www.example.com:80", "connect");
 280      *    nr = new SocketPermission("*.example.com", "connect");
 281      *    nr = new SocketPermission("*.edu", "resolve");
 282      *    nr = new SocketPermission("204.160.241.0", "connect");
 283      *    nr = new SocketPermission("localhost:1024-65535", "listen");
 284      *    nr = new SocketPermission("204.160.241.0:1024-65535", "connect");
 285      * </pre>
 286      *
 287      * @param host the hostname or IP address of the computer, optionally
 288      * including a colon followed by a port or port range.
 289      * @param action the action string.
 290      *
 291      * @throws NullPointerException if any parameters are null
 292      * @throws IllegalArgumentException if the format of {@code host} is
 293      *         invalid, or if the {@code action} string is empty, malformed, or
 294      *         contains an action other than the specified possible actions
 295      */
 296     public SocketPermission(String host, String action) {
 297         super(getHost(host));
 298         // name initialized to getHost(host); NPE detected in getHost()
 299         init(getName(), getMask(action));
 300     }
 301 
 302 
 303     SocketPermission(String host, int mask) {
 304         super(getHost(host));
 305         // name initialized to getHost(host); NPE detected in getHost()
 306         init(getName(), mask);
 307     }
 308 
 309     private void setDeny() {
 310         defaultDeny = true;
 311     }
 312 
 313     private static String getHost(String host) {
 314         if (host.isEmpty()) {


 577             } else if (i >= 5 && (a[i-5] == 'a' || a[i-5] == 'A') &&
 578                                  (a[i-4] == 'c' || a[i-4] == 'C') &&
 579                                  (a[i-3] == 'c' || a[i-3] == 'C') &&
 580                                  (a[i-2] == 'e' || a[i-2] == 'E') &&
 581                                  (a[i-1] == 'p' || a[i-1] == 'P') &&
 582                                  (a[i] == 't' || a[i] == 'T'))
 583             {
 584                 matchlen = 6;
 585                 mask |= ACCEPT;
 586 
 587             } else {
 588                 // parse error
 589                 throw new IllegalArgumentException(
 590                         "invalid permission: " + action);
 591             }
 592 
 593             // make sure we didn't just match the tail of a word
 594             // like "ackbarfaccept".  Also, skip to the comma.
 595             boolean seencomma = false;
 596             while (i >= matchlen && !seencomma) {
 597                 switch (c = a[i-matchlen]) {



 598                 case ' ': case '\r': case '\n':
 599                 case '\f': case '\t':
 600                     break;
 601                 default:
 602                     if (c == ',' && i > matchlen) {
 603                         seencomma = true;
 604                         break;
 605                     }
 606                     throw new IllegalArgumentException(
 607                             "invalid permission: " + action);
 608                 }
 609                 i--;
 610             }
 611 
 612             // point i at the location of the comma minus one (or -1).
 613             i -= matchlen;
 614         }
 615 
 616         return mask;
 617     }
 618 
 619     private boolean isUntrusted()
 620         throws UnknownHostException
 621     {
 622         if (trusted) return false;
 623         if (invalid || untrusted) return true;
 624         try {
 625             if (!trustNameService && (defaultDeny ||


< prev index next >