Changeset 2239

Show
Ignore:
Timestamp:
06/13/08 10:01:20 (3 months ago)
Author:
dsugar
Message:

bunch of cleanup of network resource stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/framework-plugin/src/com/tresys/framework/compiler/linkage/net/NetworkConfig.java

    r2218 r2239  
    250250        public void accessAdded (AccessNetwork i_access) 
    251251        { 
    252 //              m_accesses.add (i_access); 
    253          
    254 ///             System.out.println ("Add network access " + i_access); 
    255                  
    256252                NetworkResource netResource = (NetworkResource) i_access.getResource (); 
    257253 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/model/NetworkResourceShape.java

    r2234 r2239  
    9595        public static final String DISPLAY_NAME_NETWORK_PROTOCOL = Messages.network_protocol; 
    9696 
    97         public static final String NetworkResource_ipv4_address_pattern = "^(((25[0-5])|(2[0-4][0-9])|([01]?[0-9][0-9]?))\\.){3}((25[0-5])|(2[0-4][0-9])|([01]?[0-9][0-9]?))$"; 
    98         public static final String NetworkResource_ipv6_address_pattern = "^(^(([0-9a-fA-F]{1,4}(((:[0-9a-fA-F]{1,4}){5}::[0-9a-fA-F]{1,4})|((:[0-9a-fA-F]{1,4}){4}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,1})|((:[0-9a-fA-F]{1,4}){3}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,2})|((:[0-9a-fA-F]{1,4}){2}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,3})|(:[0-9a-fA-F]{1,4}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,4})|(::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,5})|(:[0-9a-fA-F]{1,4}){7}))$|^(::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,6})$)|^::$)|^((([0-9a-fA-F]{1,4}(((:[0-9a-fA-F]{1,4}){3}::([0-9a-fA-F]{1,4}){1})|((:[0-9a-fA-F]{1,4}){2}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,1})|((:[0-9a-fA-F]{1,4}){1}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,2})|(::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,3})|((:[0-9a-fA-F]{1,4}){0,5})))|([:]{2}[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,4})):|::)((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{0,2})\\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{0,2})$$"; 
    99         public static final String NetworkResource_ip_address_pattern = "\\w+.\\w+((.\\w+)+)"; 
    100  
    101         public static final String NetworkResource_ip_ports_pattern = "([0-9]+( [0-9]+)*)?"; 
    102  
    10397        public static final String NETWORK_INFO_LOCAL = "NetworkResourceInfo.local"; 
    10498        public static final String NETWORK_INFO_REMOTE = "NetworkResourceInfo.remote"; 
     
    820814                int[] ports = null; 
    821815 
    822                 if (!Ports.trim ().equals ("")
     816                if (Ports.trim ().length () > 0
    823817                { 
    824818                        Pattern portsPattern = Pattern.compile (" +"); 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/wizards/shape/NetworkResourceShapePropertyPage.java

    r2236 r2239  
    6060        private static final String FIELD_PROTOCOL = "protocol"; 
    6161         
     62        private static final String NetworkResource_ipv4_address_pattern = "^(((25[0-5])|(2[0-4][0-9])|([01]?[0-9][0-9]?))\\.){3}((25[0-5])|(2[0-4][0-9])|([01]?[0-9][0-9]?))$"; 
     63        private static final String NetworkResource_ipv6_address_pattern = "^(^(([0-9a-fA-F]{1,4}(((:[0-9a-fA-F]{1,4}){5}::[0-9a-fA-F]{1,4})|((:[0-9a-fA-F]{1,4}){4}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,1})|((:[0-9a-fA-F]{1,4}){3}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,2})|((:[0-9a-fA-F]{1,4}){2}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,3})|(:[0-9a-fA-F]{1,4}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,4})|(::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,5})|(:[0-9a-fA-F]{1,4}){7}))$|^(::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,6})$)|^::$)|^((([0-9a-fA-F]{1,4}(((:[0-9a-fA-F]{1,4}){3}::([0-9a-fA-F]{1,4}){1})|((:[0-9a-fA-F]{1,4}){2}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,1})|((:[0-9a-fA-F]{1,4}){1}::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,2})|(::[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,3})|((:[0-9a-fA-F]{1,4}){0,5})))|([:]{2}[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,4})):|::)((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{0,2})\\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{0,2})$$"; 
     64        private static final String NetworkResource_dns_name_pattern = "[a-zA-Z0-9_-]+.[a-zA-Z0-9_-]+((.[a-zA-Z0-9_-]+)+)"; 
     65 
     66        private static final String NetworkResource_ip_ports_pattern = "([0-9]+( +[0-9]+)*)?"; 
     67         
     68 
     69        private static final Pattern pat_ipv4 = Pattern.compile (NetworkResource_ipv4_address_pattern); 
     70        private static final Pattern pat_ipv6 = Pattern.compile (NetworkResource_ipv6_address_pattern); 
     71        private static final Pattern pat_dns = Pattern.compile (NetworkResource_dns_name_pattern); 
     72        private static final Pattern pat_ip_ports = Pattern.compile (NetworkResource_ip_ports_pattern);  
     73        private static final Pattern pat_numeric = Pattern.compile ("[0-9]+"); 
     74         
    6275        private ComboViewer m_combo; 
    6376        protected Label m_description; 
     
    203216                                String value = (String)selection.getFirstElement (); 
    204217                                modifyValue (value); 
    205                                 checkInput (); 
     218//                              checkInput (); 
     219                                DialogChanged (); 
    206220                        } 
    207221 
     
    222236 
    223237                        modifyValue (s); 
    224                         checkInput (); 
     238//                      checkInput (); 
     239                        DialogChanged (); 
    225240                } 
    226241 
     
    239254 
    240255                        modifyValue (s); 
    241                         checkInput (); 
     256//                      checkInput (); 
     257                        DialogChanged (); 
    242258                }                
    243259        } 
     
    255271 
    256272                        modifyValue (s); 
    257                         checkInput (); 
     273//                      checkInput (); 
     274                        DialogChanged (); 
    258275                } 
    259276        } 
     
    271288                         
    272289                        modifyValue (s); 
    273                         checkInput (); 
     290//                      checkInput (); 
     291                        DialogChanged (); 
    274292                } 
    275293        } 
     
    534552         
    535553         
    536         protected void checkInput() 
    537         { 
    538                 StructuredSelection sel = (StructuredSelection)m_combo.getSelection (); 
    539                 Rdef networkType = (Rdef)sel.getFirstElement (); 
    540  
    541                 if (networkType != null && 
    542                         (networkType.GetSysResourceState (SystemResourceTypes.ipsec) == SysResourceState.Yes || networkType.GetSysResourceState (SystemResourceTypes.ipsec) == SysResourceState.Optional)) 
    543                 { 
    544                         // required value 
    545                         if ( localIPAddress.length () == 0 ) 
    546                         { 
    547                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
    548                                 return; 
    549                         } 
    550                          
    551                         // this is optional value check only if it has any valid characters. 
    552                         if( localIPPorts.trim ().length () > 0 && 
    553                                 (!Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, localIPPorts.trim ())) 
    554                                 ) 
    555                         { 
    556                                 updateStatus(Messages.NetworkResourcePropertyPage_bad_local_ip_ports, false); 
    557                                 return; 
    558                         } 
    559  
    560                         { 
    561                                 // all the required value check is complete 
    562                                 // lets make sure that the value matches the requirement 
    563                                 boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, localIPAddress.trim ()); 
    564                                 boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, localIPAddress.trim ()); 
    565                                 boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, localIPAddress.trim ());  
    566                                  
    567                                 if( ! (ip4 || ip6 || match) ) 
    568                                 { 
    569                                         updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
    570                                         return; 
    571                                 } 
    572                         } 
    573                 } 
    574                 else if (networkType != null && 
    575                         (networkType.GetSysResourceState (SystemResourceTypes.secmark) == SysResourceState.Yes || networkType.GetSysResourceState (SystemResourceTypes.secmark) == SysResourceState.Optional)) 
    576                 { 
    577                          
    578                         if( localDevice.trim ().length () == 0 ) 
    579                         { 
    580                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_local_device, false); 
    581                                 return; 
    582                         } 
    583                         // local information 
    584                         if ( localIPAddress.trim ().length () == 0 ) 
    585                         { 
    586                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
    587                                 return; 
    588                         } 
    589                         if ( localMask.trim ().length () > 0  
    590                                                 && !Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, localMask.trim ()) 
    591                                                 && !Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, localMask.trim ()) 
    592                                                 ) 
    593                         { 
    594                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_mask, false); 
    595                                 return; 
    596                         } 
    597                         if( localIPPorts.trim ().length () > 0 && 
    598                                 (!Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, localIPPorts.trim ())) 
    599                                 ) 
    600                         { 
    601                                 updateStatus(Messages.NetworkResourcePropertyPage_bad_local_ip_ports, false); 
    602                                 return; 
    603                         } 
    604                          
    605                         { 
    606                                 boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, localIPAddress.trim ()); 
    607                                 boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, localIPAddress.trim ()); 
    608                                 boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, localIPAddress.trim ());  
    609                                  
    610                                 if( ! (ip4 || ip6 || match) ) 
    611                                 { 
    612                                         updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
    613                                         return; 
    614                                 } 
    615                         } 
    616                          
    617                          
    618                         // remote information all of them are optional 
    619                         if( remoteDevice.trim ().length () > 0  && remoteIPAddress.trim ().length () == 0) 
    620                         { 
    621                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_ip_address, false); 
    622                                 return; 
    623                         } 
    624                         if ( remoteIPAddress.trim ().length () > 0  && remoteDevice.trim ().length () == 0 ) 
    625                         { 
    626                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_device, false); 
    627                                 return; 
    628                         } 
    629                         if ( remoteIPAddress.trim ().length () > 0 ) 
    630                         { 
    631                                 boolean match = Pattern.matches(NetworkResourceShape.NetworkResource_ip_address_pattern, remoteIPAddress.trim ()); 
    632                                 boolean ip4 = Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, remoteIPAddress.trim ()); 
    633                                 boolean ip6 = Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, remoteIPAddress.trim ());  
    634                                  
    635                                 if( ! (ip4 || ip6 || match) ) 
    636                                 { 
    637                                         updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_ip_address, false); 
    638                                         return; 
    639                                 } 
    640                         } 
    641                         if ( remoteMask.trim ().length () > 0  
    642                                                 && !Pattern.matches (NetworkResourceShape.NetworkResource_ipv4_address_pattern, remoteMask.trim ()) 
    643                                                 && !Pattern.matches(NetworkResourceShape.NetworkResource_ipv6_address_pattern, remoteMask.trim ()) 
    644                                                 ) 
    645                         { 
    646                                 updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_ip_mask, false); 
    647                                 return; 
    648                         } 
    649                         if( remoteIPPorts.trim ().length () > 0 && 
    650                                 (!Pattern.matches (NetworkResourceShape.NetworkResource_ip_ports_pattern, remoteIPPorts.trim ())) 
    651                                 ) 
    652                         { 
    653                                 updateStatus(Messages.NetworkResourcePropertyPage_bad_local_ip_ports, false); 
    654                                 return; 
    655                         } 
    656                          
    657                 } 
    658                  
    659                 // no error go ahead and allow user to complete 
    660                 updateStatus (null, true); 
    661         } 
    662  
    663554        /** 
    664555         * I had to copy stuff from the parent. 
     
    668559        public void DialogChanged() 
    669560        {                
    670                 String name = getShapeName(); 
    671                  
    672                 if (name == null || name.length() == 0) 
    673                 { 
    674                         m_errorMessage = NLS.bind (Messages.ShapePropertyPage_err1, getShape ().getType()); 
    675                         updateStatus(m_errorMessage, false); 
     561                super.DialogChanged (); 
     562                 
     563                if (getErrorMessage () != null) 
     564                { 
     565                        updateStatus (getErrorMessage (), false); 
    676566                        return; 
    677567                } 
    678568                 
    679                 //Need to test if name is valid 
    680                 m_errorMessage = getShape ().testValidity(name); 
    681                  
    682                 if (m_errorMessage != null) 
    683                 { 
    684                         updateStatus(m_errorMessage, false); 
    685                         return; 
    686                 } 
    687                  
    688                 // check all the fields. 
    689                 checkInput (); 
     569                StructuredSelection sel = (StructuredSelection)m_combo.getSelection (); 
     570                Rdef networkType = (Rdef)sel.getFirstElement (); 
     571 
     572                if (networkType != null && 
     573                        networkType.GetSysResourceState (SystemResourceTypes.ipsec) != SysResourceState.No) 
     574                { 
     575                        // required value 
     576                        if (localIPAddress.length () == 0) 
     577                        { 
     578                                updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
     579                                return; 
     580                        } 
     581                         
     582                        // this is optional value check only if it has any valid characters. 
     583                        if( localIPPorts.trim ().length () > 0 && 
     584                                !pat_ip_ports.matcher (localIPPorts.trim ()).matches () 
     585                                ) 
     586                        { 
     587                                updateStatus(Messages.NetworkResourcePropertyPage_bad_local_ip_ports, false); 
     588                                return; 
     589                        } 
     590 
     591                        { 
     592                                // all the required value check is complete 
     593                                // lets make sure that the value matches the requirement 
     594                                boolean dns = isFormattedDNS (localIPAddress.trim ()); 
     595                                boolean ip4 = pat_ipv4.matcher (localIPAddress.trim ()).matches (); 
     596                                boolean ip6 = pat_ipv6.matcher (localIPAddress.trim ()).matches ();  
     597                                 
     598                                if (! (ip4 || ip6 || dns)) 
     599                                { 
     600                                        updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
     601                                        return; 
     602                                } 
     603                        } 
     604                } 
     605                else if (networkType != null && 
     606                        networkType.GetSysResourceState (SystemResourceTypes.secmark) != SysResourceState.No) 
     607                { 
     608                         
     609                        // local information 
     610                        if (localDevice.trim ().length () == 0 && localIPAddress.trim ().length () == 0) 
     611                        { 
     612                                updateStatus (Messages.NetworkResourcePropertyPage_err_local_device_or_ip, false); 
     613                                return; 
     614                        } 
     615 
     616                        if (localIPAddress.trim ().length () > 0) 
     617                        { 
     618                                boolean dns = isFormattedDNS (localIPAddress.trim ()); 
     619                                boolean ip4 = pat_ipv4.matcher (localIPAddress.trim ()).matches (); 
     620                                boolean ip6 = pat_ipv6.matcher (localIPAddress.trim ()).matches ();  
     621                                 
     622                                if (! (ip4 || ip6 || dns)) 
     623                                { 
     624                                        updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_address, false); 
     625                                        return; 
     626                                } 
     627                        } 
     628 
     629                        if (localMask.trim ().length () > 0  
     630                                && !pat_ipv4.matcher (localMask.trim ()).matches () 
     631                                && !pat_ipv6.matcher (localMask.trim ()).matches () 
     632                        ) 
     633                        { 
     634                                updateStatus (Messages.NetworkResourcePropertyPage_bad_local_ip_mask, false); 
     635                        } 
     636 
     637                        if (localIPPorts.trim ().length () > 0 && 
     638                                !pat_ip_ports.matcher (localIPPorts.trim ()).matches () 
     639                                ) 
     640                        { 
     641                                updateStatus(Messages.NetworkResourcePropertyPage_bad_local_ip_ports, false); 
     642                                return; 
     643                        } 
     644                         
     645                         
     646                         
     647                        // remote information all of them are optional 
     648                /* 
     649                        if (remoteDevice.trim ().length () > 0  && remoteIPAddress.trim ().length () == 0) 
     650                        { 
     651                                updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_ip_address, false); 
     652                                return; 
     653                        } 
     654                        /* 
     655                        if (remoteIPAddress.trim ().length () > 0  && remoteDevice.trim ().length () > 0 ) 
     656                        { 
     657                                updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_device, false); 
     658                                return; 
     659                        } 
     660                        */ 
     661                        if (remoteIPAddress.trim ().length () > 0) 
     662                        { 
     663                                boolean dns = isFormattedDNS (remoteIPAddress.trim ()); 
     664                                boolean ip4 = pat_ipv4.matcher (remoteIPAddress.trim ()).matches (); 
     665                                boolean ip6 = pat_ipv6.matcher (remoteIPAddress.trim ()).matches ();  
     666                                 
     667                                if( ! (ip4 || ip6 || dns) ) 
     668                                { 
     669                                        updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_ip_address, false); 
     670                                        return; 
     671                                } 
     672                        } 
     673                        if (remoteMask.trim ().length () > 0  
     674                                && !pat_ipv4.matcher (remoteMask.trim ()).matches () 
     675                                && !pat_ipv6.matcher (remoteMask.trim ()).matches () 
     676                                ) 
     677                        { 
     678                                updateStatus (Messages.NetworkResourcePropertyPage_bad_remote_ip_mask, false); 
     679                                return; 
     680                        } 
     681                        if (remoteIPPorts.trim ().length () > 0 && 
     682                                !pat_ip_ports.matcher (remoteIPPorts.trim ()).matches () 
     683                                ) 
     684                        { 
     685                                updateStatus(Messages.NetworkResourcePropertyPage_bad_local_ip_ports, false); 
     686                                return; 
     687                        } 
     688                         
     689                } 
     690                 
     691                // no error go ahead and allow user to complete 
     692                updateStatus (null, true); 
     693        } 
     694         
     695        private boolean isFormattedDNS (String i_sPossibleDNS) 
     696        { 
     697                if (!pat_dns.matcher (i_sPossibleDNS).matches ()) 
     698                        return false; 
     699 
     700                boolean bAllNumeric = true; 
     701                String [] pieces = i_sPossibleDNS.split ("\\."); 
     702                for (int i = 0; i < pieces.length; i++) 
     703                { 
     704                        if (!pat_numeric.matcher (pieces[i]).matches ()) 
     705                                bAllNumeric = false; 
     706                } 
     707                 
     708                return !bAllNumeric; 
    690709        } 
    691710