1 package com.ca.directory.jxplorer; 2 3 import com.ca.commons.cbutil.*; 4 import com.ca.commons.jndi.JNDIOps; 5 import com.ca.commons.jndi.JndiSocketFactory; 6 import com.ca.commons.naming.*; 7 import com.ca.commons.security.cert.CertViewer; 8 import com.ca.directory.BuildNumber; 9 import com.ca.directory.jxplorer.broker.*; 10 import com.ca.directory.jxplorer.event.*; 11 import com.ca.directory.jxplorer.search.SearchBar; 12 import com.ca.directory.jxplorer.tree.*; 13 import com.ca.directory.jxplorer.viewer.AttributeDisplay; 14 15 import javax.swing.*; 16 import javax.swing.event.*; 17 import javax.swing.tree.TreePath ; 18 import java.awt.*; 19 import java.awt.event.WindowAdapter ; 20 import java.awt.event.WindowEvent ; 21 import java.io.*; 22 import java.security.Provider ; 23 import java.security.Security ; 24 import java.util.*; 25 import java.util.logging.*; 26 27 30 public class 31 JXplorer extends JFrame implements JXplorerEventGenerator 33 { 34 static String version = BuildNumber.value; 35 36 private static JFrame rootFrame; Container mainPane; 39 transient JXplorerListener jxplorerListener; 40 41 EventListenerList eventListeners = new EventListenerList(); 42 43 JScrollPane explorePanel; JScrollPane resultsPanel; JScrollPane schemaPanel; 47 JTabbedPane treeTabPane; 48 49 JPanel userViewPanel; 50 51 CBPanel topPanel; JToolBar searchBar; ButtonBar buttonBar; 55 public static Properties myProperties; public static String propertyFile; public static String localDir; 59 public static JFrame jx; 60 61 JNDIBroker jndiBroker = null; JNDIBroker searchBroker = null; OfflineBroker offlineBroker = null; SchemaBroker schemaBroker = null; 66 SmartTree mrTree = null; SmartTree searchTree = null; SmartTree schemaTree = null; 70 AttributeDisplay mainViewer; 72 CBPanel statusDisplay; 73 JLabel displayLabel; 74 75 boolean workOffline = false; 76 77 public static boolean debug = false; 78 public static int debugLevel = 0; 79 80 protected Stack statusStack = new Stack(); 81 82 protected MainMenu mainMenu; 83 84 protected static ButtonRegister buttonRegister = null; 86 protected CBHelpSystem helpSystem; 87 88 protected StopMonitor stopMonitor; 89 90 public Thread jndiThread, schemaThread, searchThread, offlineThread; 91 92 public String url = "Disconnected"; 94 CBResourceLoader resourceLoader; CBClassLoader classLoader; 97 100 101 public static final String CLIENT_TYPE_PROPERTY = "keystoreType.clientcerts"; 102 public static final String CA_TYPE_PROPERTY = "keystoreType.cacerts"; 103 public static final String CLIENT_PATH_PROPERTY = "option.ssl.clientcerts"; 104 public static final String CA_PATH_PROPERTY = "option.ssl.cacerts"; 105 public static final String ALLOW_CONNECTION_CERT_IMPORT = "option.ssl.import.cert.during.connection"; 106 107 private static Logger log = Logger.getLogger(JXplorer.class.getName()); 109 112 113 116 boolean connected = false; 118 public JXplorer() 119 { 120 super(); 121 122 JWindow splash = new JWindow(); 123 124 showSplashScreen(splash); 125 126 rootFrame = this; 127 mainPane = rootFrame.getContentPane(); 128 mrTree = null; 129 130 loadProperties(myProperties); 131 132 setupLogger(); 134 initUtilityFtns(this); 135 136 setupResourceFiles(); 137 138 CBIntText.init("language.JX", classLoader); 140 141 if (checkFileEnvironment() == false) return; 142 143 initJNDIBroker(); 144 145 initSearchBroker(); 146 147 initSchemaBroker(); 148 149 initOfflineBroker(); 150 151 initStopMonitor(); 152 153 buttonRegister = new ButtonRegister(); 154 155 setupGUI(); 156 157 setStatus(CBIntText.get("Not Connected")); 158 159 setBackground(Color.white); 160 161 setVisible(true); 162 163 splash.dispose(); 164 } 165 166 public static void printTime(String msg) 167 { 168 long time = System.currentTimeMillis(); 169 log.info(msg + "\nTIME: " + new Date().toString() + " (" + (time % 1000) + ")\n"); 170 } 171 172 179 180 public static void main(String [] args) 181 { 182 printTime("main start"); 183 184 log.fine("running JXplorer version " + version); 185 186 if (checkJavaEnvironment() == false) 187 System.exit(-1); 188 189 new JXplorer(); 190 191 printTime("main end"); 192 } 193 194 197 198 protected static void setupBackupLogger() 199 { 200 Logger mainLogger = LogManager.getLogManager().getLogger("com.ca"); 201 202 mainLogger.setLevel(Level.parse(getProperty("java.util.logging.ConsoleHandler.level"))); 204 Handler handler = new ConsoleHandler(); 205 handler.setLevel(Level.ALL); 206 mainLogger.addHandler(handler); 207 } 208 209 212 protected static void setupLogger() 213 { 214 216 log.info("setting up logger"); 217 218 try 219 { 220 Logger.getLogger("com"); 222 Logger.getLogger("com.ca"); 223 Logger.getLogger("com.ca.directory"); 224 Logger.getLogger("com.ca.directory.jxplorer"); 225 226 log = Logger.getLogger(JXplorer.class.getName()); 229 230 LogManager logManager = LogManager.getLogManager(); 231 logManager.reset(); 232 233 241 242 logManager.readConfiguration(new FileInputStream(propertyFile)); 243 System.out.println("XXX logging initially level " + CBUtility.getTrueLogLevel(log) + " with " + log.getHandlers().length + " parents=" + log.getUseParentHandlers()); 244 245 log.info("Using configuration file: " + propertyFile); 246 log.info("logging initialised to global level " + CBUtility.getTrueLogLevel(log)); 247 248 257 if (false) throw new IOException(); 258 } 259 catch (IOException e) 260 { 261 log.log(Level.SEVERE, "Unable to load log configuration from config file: " + propertyFile, e); 262 System.err.println("Unable to load log configuration from config file: " + propertyFile); 263 e.printStackTrace(); 264 setupBackupLogger(); 265 266 } 267 268 int currentLogLevel = CBUtility.getTrueLogLevel(log).intValue(); 269 270 272 if (currentLogLevel <= Level.FINE.intValue()) 273 { 274 Vector sortedKeys = new Vector(); 275 Enumeration baseKeys = myProperties.keys(); 276 while (baseKeys.hasMoreElements()) 277 { 278 String key = (String ) baseKeys.nextElement(); 279 sortedKeys.addElement(key); 280 } 281 Collections.sort(sortedKeys); 282 283 Enumeration propNames = sortedKeys.elements(); 284 285 StringBuffer propertyData = new StringBuffer (); 286 String propName; 287 288 while (propNames.hasMoreElements()) 289 { 290 propName = (String ) propNames.nextElement(); 291 propertyData.append("property: ").append(propName).append(" = ").append(myProperties.getProperty(propName)).append("\n"); 292 } 293 294 log.fine("property:\n" + propertyData.toString()); 295 } 296 297 345 } 346 347 350 public void initUtilityFtns(JFrame rootFrame) 351 { 352 353 CBUtility.initDefaultDisplay(rootFrame); 354 } 355 356 363 375 379 380 public static boolean checkJavaEnvironment() 381 { 382 log.info("running java from: " + System.getProperty("java.home")); 383 String javaVersion = System.getProperty("java.version"); 384 log.info("running java version " + javaVersion); 385 if (javaVersion.compareTo("1.4") < 0) 386 { 387 log.severe(CBIntText.get("TERMINATING: JXplorer requires Security Extensions and other features found only in java 1.4.0 or better.")); 388 JOptionPane.showMessageDialog(null, CBIntText.get("TERMINATING: JXplorer requires java 1.4.0 or better"), CBIntText.get("The Current Java Version is {0}", new String []{javaVersion}), JOptionPane.ERROR_MESSAGE); 389 return false; 390 } 391 392 return true; 393 } 394 395 399 400 public static boolean checkFileEnvironment() 401 { 402 return true; 403 } 404 405 412 413 public static String getProperty(String key) 414 { 415 if (System.getProperty(key) != null) 416 return System.getProperty(key); 417 418 if (myProperties.containsKey(key)) 419 return myProperties.getProperty(key); 420 421 return null; 422 } 423 424 425 431 432 public static String getProperty(String key, String defaultValue) 433 { 434 if (myProperties == null) return defaultValue; 435 return myProperties.getProperty(key, defaultValue); 436 } 437 438 442 443 public static Properties getMyProperties() 444 { 445 return myProperties; 446 } 447 448 449 452 public static void setProperty(String key, String value) 453 { 454 if (key != null) 455 myProperties.setProperty(key, value); 456 457 } 458 459 463 public void checkSpecialLoggingActions() 464 { 465 if (CBUtility.getTrueLogLevel(log) == Level.ALL) 466 jndiBroker.setTracing(true); 467 else 468 jndiBroker.setTracing(false); 469 } 470 471 480 481 public static String setDefaultProperty(String key, String value) 482 { 483 if (System.getProperty(key) != null) 484 return System.getProperty(key); 485 486 if (myProperties.containsKey(key)) 487 return myProperties.getProperty(key); 488 489 myProperties.setProperty(key, value); 490 return value; 491 } 492 493 505 public static String setDefaultProperty(String key, String value, String comment) 506 { 507 if (comment != null && comment.length() > 0) 508 { 509 myProperties.put(key + ".comment", comment); 510 } 511 512 return setDefaultProperty(key, value); 513 } 514 515 516 523 524 525 public static void loadProperties(Properties suppliedProperties) 526 { 527 localDir = System.getProperty("user.dir") + File.separator; 528 529 if (suppliedProperties == null) { 531 String configFileName = "jxconfig.txt"; 532 propertyFile = CBUtility.getPropertyConfigPath(configFileName); 533 534 myProperties = CBUtility.readPropertyFile(propertyFile); 535 536 } 537 else 538 { 539 myProperties = suppliedProperties; 540 } 541 542 544 setDefaultProperty("url.defaultdirectory", "localhost", "default for empty connection screen GUI - rarely used"); 545 setDefaultProperty("url.defaultdirectory.port", "389", "default for empty connection screen GUI - rarely used"); 546 setDefaultProperty("url.defaultadmin", "localhost", "default value for a specific 3rd party plug in; rarely used"); 547 setDefaultProperty("url.defaultadminport", "3389", "default value for a specific 3rd party plug in; rarely used"); 548 setDefaultProperty("baseAdminDN", "cn=Management System", "default value for a specific 3rd party plug in; rarely used"); 549 550 551 565 566 setProperty("dir.comment", "this sets the directories that JXplorer reads its resources from."); 567 setDefaultLocationProperty("dir.local", localDir); 568 setDefaultLocationProperty("dir.htmldocs", localDir + "htmldocs" + File.separator); 569 setDefaultLocationProperty("dir.templates", localDir + "templates" + File.separator); 570 setDefaultLocationProperty("dir.icons", localDir + "icons" + File.separator); 571 setDefaultLocationProperty("dir.images", localDir + "images" + File.separator); 572 setDefaultLocationProperty("dir.help", localDir + "help" + File.separator); 573 setDefaultLocationProperty("dir.plugins", localDir + "plugins" + File.separator); 574 575 setDefaultProperty("width", "800", "set by client GUI - don't change"); 576 577 setDefaultProperty("height", "600", "set by client GUI - don't change"); 578 579 setDefaultProperty("baseDN", "c=au", "the default base DN for an empty connection - rarely used"); 580 581 setDefaultProperty("ldapversion", "3", "set by client GUI - don't change"); 582 583 585 setDefaultProperty(".level", "WARNING", "(java loggin variable) - allowable values are 'OFF', 'SEVERE', 'WARNING', 'INFO', 'FINE', 'FINER', 'FINEST' and 'ALL'"); 586 587 setDefaultProperty("com.ca.level", "UNUSED", " (java loggin variable) partial logging is also available. Be warned that the Sun logging system is a very buggy partial reimplementation of log4j, and doesn't seem to do inheritance well."); 588 589 590 595 setDefaultProperty("handlers", "java.util.logging.ConsoleHandler", "(java logging variable) This sets the log level for console reporting"); 596 597 setDefaultProperty("java.util.logging.ConsoleHandler.level", "ALL", "(java logging variable) This sets the log level for console reporting"); 598 599 setDefaultProperty("java.util.logging.ConsoleHandler.formatter", "java.util.logging.SimpleFormatter", "(java logging variable) This sets the built in formatter to use for console reporting"); 600 601 setDefaultProperty("java.util.logging.FileHandler.level", "ALL", "(java loggin variable) This sets the log level for log file reporting"); 602 603 setDefaultProperty("java.util.logging.FileHandler.pattern", "JX%u.log", "(java loggin variable) The name of the log file (see java.util.logging.FileHandler java doc)"); 604 605 setDefaultProperty("java.util.logging.FileHandler.formatter", "java.util.logging.SimpleFormatter", "(java loggin variable) This sets the built in formatter to use for file reporting"); 606 607 608 610 setDefaultProperty("null.entry.editor", "defaulteditor", "the editor displayed for null entries is pluggable and can be set to a custom java class"); 611 612 setDefaultProperty("plugins.ignoreUniqueness", "false", "whether to allow multiple plugins for the same object class: 'true' or 'false"); 613 614 setDefaultProperty("option.ignoreSchemaOnSubmission", "false", "Skip client side schema checks; useful if JXplorer is getting confused or the schema is inconsistent"); 615 616 setDefaultProperty("option.ldap.timeout", "0", "the maximum time to allow a query to run before cancelling - '0' = 'as long as the server allows'"); 617 618 setDefaultProperty("option.ldap.limit", "0", "The maximum number of entries to return - '0' = 'all the server allows'"); 619 620 setDefaultProperty("option.ldap.referral", JNDIOps.DEFAULT_REFERRAL_HANDLING, "this is a jdni variable determinning how referrals are handled: 'ignore','follow' or 'throw'"); 622 623 setDefaultProperty("option.ldap.browseAliasBehaviour", JNDIOps.DEFAULT_ALIAS_HANDLING, "jndi variable setting how aliases are handled while browsing: 'always','never','finding','searching'"); 625 setDefaultProperty("option.ldap.searchAliasBehaviour", "searching", "jndi variable setting how aliases are handled while searching: 'always','never','finding','searching'"); 627 setDefaultProperty("option.confirmTableEditorUpdates", "false", "whether the user is prompted before updates; usually set by GUI"); 629 setDefaultProperty("option.url.handling", "JXplorer", "override URL handling to launch JXplorer rather than default browser"); 631 setDefaultProperty("option.ldap.sendVerboseBinarySuffix", "false", "some directories require ';binary' to be explicitly appended to binary attribute names: 'true' or 'false'"); 632 633 setDefaultProperty("option.drag.and.drop", "true", "set to 'false' to disable drag and drop in the left hand tree view"); 634 635 setDefaultProperty("jxplorer.cache.passwords", "true", "whether JX should keep a (run time only) cache of passwords for reuse and reconnection"); 636 637 setDefaultProperty("sort.by.naming.attribute", "false", "if true, this sorts entries in the tree editor by naming attribute first, then by attribute value"); 638 639 if ("true".equals(getProperty("option.ldap.sendVerboseBinarySuffix"))) 640 { 641 log.fine("using verbose binary suffix ';binary'"); DXAttribute.setVerboseBinary(true); } 644 647 648 setDefaultProperty(CA_PATH_PROPERTY, localDir + "security" + File.separator + "cacerts"); 649 setDefaultProperty(CLIENT_PATH_PROPERTY, localDir + "security" + File.separator + "clientcerts"); 650 setDefaultProperty(CLIENT_TYPE_PROPERTY, "JKS"); 651 setDefaultProperty(CA_TYPE_PROPERTY, "JKS"); 652 setDefaultProperty(ALLOW_CONNECTION_CERT_IMPORT, "true"); 653 System.setProperty(ALLOW_CONNECTION_CERT_IMPORT, getProperty(ALLOW_CONNECTION_CERT_IMPORT)); 655 656 setDefaultProperty("securityProvider", "com.sun.net.ssl.internal.ssl.Provider"); 659 setProperty("securityProvider.comment", "the security provider can be changed, and three more can be added by creating 'securityProperty0', 'securityProperty1' and 'securityProperty2'."); 660 661 setDefaultProperty("ldap.sslsocketfactory", "com.ca.commons.jndi.JndiSocketFactory"); 663 setProperty("ldap.sslsocketfactory.comment", "This is the built in ssl factory - it can be changed if required."); 664 665 setDefaultProperty("gui.lookandfeel", UIManager.getSystemLookAndFeelClassName()); setDefaultProperty("gui.lookandfeel.comment", "Can set to com.sun.java.swing.plaf.mac.MacLookAndFeel for OSX"); 668 setDefaultProperty("last.search.filter", "default"); 670 673 674 setDefaultProperty("getSystemEnvironment.comment", "Set this to true if you wish to add the system environment properties to the JX list (e.g. if you are setting JX properties via system variables)"); 675 setDefaultProperty("getSystemEnvironment", "false"); 676 677 if (getProperty("getSystemEnvironment").equalsIgnoreCase("true")) 678 { 679 CBSystemProperties.loadSystemProperties(); 680 } 681 682 683 684 688 CertViewer.setProperties(myProperties); 689 690 CertViewer.setupHelpLink(HelpIDs.SSL_VIEW); 693 694 695 696 setDefaultProperty("xml.ldif.rfc", "false"); setDefaultProperty("xml.ldif.rfc.comment", "Experimental support for saving XML in LDIF files in editable form (e.g. not base64 encoded)"); 699 if ("true".equals(getProperty("xml.ldif.rfc"))) 700 LdifUtility.setSupportXML_LDIF_RFC(true); 701 702 703 705 if (new File(propertyFile).exists() == false) 706 writePropertyFile(); 707 } 708 709 714 protected static void setDefaultLocationProperty(String propName, String defaultLocation) 715 { 716 setDefaultProperty(propName, defaultLocation); 717 String newLocation = getProperty(propName); 718 if (!newLocation.equals(defaultLocation)) 719 { 720 File test = new File(newLocation); 721 if (!test.exists()) 722 { 723 log.warning("Uunable to find location '" + newLocation + "' -> reverting to '" + defaultLocation + "'"); 724 setProperty(propName, defaultLocation); 725 } 726 } 727 } 728 729 public void initJNDIBroker() 730 { 731 jndiBroker = new JNDIBroker(); 732 if (CBUtility.getTrueLogLevel(log) == Level.ALL) 733 jndiBroker.setTracing(true); 735 jndiBroker.setTimeout(Integer.parseInt(getProperty("option.ldap.timeout"))); 736 jndiBroker.setLimit(Integer.parseInt(getProperty("option.ldap.limit"))); 737 738 jndiThread = new Thread (jndiBroker, "jndiBroker Thread"); 739 jndiThread.start(); 740 } 741 742 public void initSearchBroker() 743 { 744 searchBroker = new JNDIBroker(jndiBroker); 745 searchThread = new Thread (searchBroker, "searchBroker Thread"); 746 searchThread.start(); 747 } 748 749 750 public void initSchemaBroker() 751 { 752 schemaBroker = new SchemaBroker(jndiBroker); 753 754 schemaThread = new Thread (schemaBroker, "schemaBroker Thread"); 755 schemaThread.start(); 756 } 757 758 762 public void initOfflineBroker() 763 { 764 offlineBroker = new OfflineBroker(this); 765 766 offlineThread = new Thread (offlineBroker, "offlineBroker Thread"); 767 offlineThread.start(); 768 } 769 770 public void initStopMonitor() 771 { 772 Broker[] brokerList = {jndiBroker, searchBroker, schemaBroker, offlineBroker}; 773 stopMonitor = new StopMonitor(brokerList, this); 774 } 775 776 779 780 public StopMonitor getStopMonitor() 781 { 782 return stopMonitor; 783 } 784 785 789 790 protected void setupGUI() 791 { 792 setupLookAndFeel(); 793 794 setupWindowButtons(); 796 setupHelp(); 798 setupMenu(); 800 setupMainPanel(); 802 setupStatusDisplay(); 804 setupFrills(); 806 positionBrowser(); } 808 809 810 814 815 protected void positionBrowser() 816 { 817 int width, height, xpos, ypos; 818 819 try 820 { 821 width = Integer.parseInt(getProperty("width")); 822 height = Integer.parseInt(getProperty("height")); 823 xpos = Integer.parseInt(getProperty("xpos")); 824 ypos = Integer.parseInt(getProperty("ypos")); 825 } 826 catch (Exception e) 827 { 828 width = 800; 829 height = 600; Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 831 xpos = (screen.width - width) / 2; 832 ypos = (screen.height - height) / 2; 833 } 834 835 if (width < 100) width = 100; 837 if (height < 100) height = 100; 838 839 setBounds(xpos, ypos, width, height); 840 setSize(width, height); 841 } 842 843 849 850 protected void setupLookAndFeel() 851 { 852 try 853 { 854 UIManager.setLookAndFeel(getProperty("gui.lookandfeel")); } 856 catch (Exception exc) 857 { 858 log.warning("WARNING: Can't load Look and Feel: " + exc); 859 try 860 { 861 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 862 setProperty("gui.lookandfeel", UIManager.getCrossPlatformLookAndFeelClassName()); 863 } 864 catch (Exception exc2) 865 { 866 log.warning("ERRROR: Can't load sys Look and Feel either! : " + exc2); 867 } 868 } 869 } 870 871 875 876 protected void setupWindowButtons() 877 { 878 addWindowListener(new WindowAdapter () 879 { 880 public void windowClosing(WindowEvent ev) 881 { 882 shutdown(); 883 } 884 }); 885 } 886 887 888 891 892 protected void setupMenu() 893 { 894 if (getProperty("gui.menu", "true").equals("true")) 895 mainMenu = new MainMenu(this); 896 } 897 898 899 904 905 public MainMenu getMainMenu() 906 { 907 return mainMenu; 908 } 909 910 911 916 917 public JNDIBroker getSearchBroker() 918 { 919 return searchBroker; 920 } 921 922 923 928 929 public JTabbedPane getTreeTabPane() 930 { 931 return treeTabPane; 932 } 933 934 935 940 941 public JScrollPane getExplorePanel() 942 { 943 return explorePanel; 944 } 945 946 947 952 953 public JScrollPane getResultsPanel() 954 { 955 return resultsPanel; 956 } 957 958 959 964 965 public SmartTree getSearchTree() 966 { 967 return searchTree; 968 } 969 970 971 976 977 public SmartTree getTree() 978 { 979 return mrTree; 980 } 981 982 983 988 989 public SmartTree getSchemaTree() 990 { 991 return schemaTree; 992 } 993 994 995 1000 1001 public static JFrame getRootFrame() 1002 { 1003 return rootFrame; 1004 } 1005 1006 1007 1012 1013 public AttributeDisplay getAttributeDisplay() 1014 { 1015 return mainViewer; 1016 } 1017 1018 1019 1023 1024 protected void setupMainPanel() 1025 { 1026 1027 setupToolBars(); 1028 1029 1035 1041 setupActiveComponents(); setupMainWorkArea(); 1045 mainPane.setBackground(Color.lightGray); 1046 1047 mainViewer.registerClassLoader(classLoader); 1048 1049 validate(); 1050 1056 } 1057 1058 protected void setupToolBars() 1059 { 1060 1061 topPanel = new CBPanel(); 1062 searchBar = new SearchBar(this); buttonBar = new ButtonBar(this); 1065 topPanel.makeWide(); 1067 1068 topPanel.addln(buttonBar); 1069 topPanel.addln(searchBar); 1070 mainPane.add(topPanel, BorderLayout.NORTH); 1071 1072 mainPane.setBackground(Color.white); 1073 1074 if (getProperty("gui.buttonbar", "true").equals("false")) 1075 buttonBar.setVisible(false); 1076 if (getProperty("gui.searchbar", "true").equals("false")) 1077 searchBar.setVisible(false); 1078 } 1079 1080 1085 protected void setupActiveComponents() 1086 { 1087 mainViewer = new AttributeDisplay(myProperties, JXplorer.this, resourceLoader); 1088 1089 1091 mrTree = new SmartTree(this, CBIntText.get("Explore"), resourceLoader); 1092 mrTree.setBackground(new Color(0xF7F9FF)); 1093 initialiseTree(mrTree, mainViewer, this); 1094 1095 searchTree = new SmartTree(this, CBIntText.get("Results"), resourceLoader); 1096 searchTree.setBackground(new Color(0xEEFFFF)); 1097 initialiseTree(searchTree, mainViewer, this); 1098 1099 schemaTree = new SmartTree(this, CBIntText.get("Schema"), resourceLoader); 1100 schemaTree.setBackground(new Color(0xEEFFEE)); 1101 schemaTree.getTree().setEditable(false); 1102 initialiseTree(schemaTree, mainViewer, this); 1103 1104 mainViewer.registerComponents(mainMenu, buttonBar, mrTree.getTree(), mrTree.getPopupTool(), this); 1105 } 1106 1107 public void initialiseTree(SmartTree tree, DataSink viewer, JXplorerEventGenerator gen) 1108 { 1109 if (viewer != null) tree.registerDataSink(viewer); 1110 if (gen != null) tree.registerEventPublisher(gen); 1111 } 1112 1117 protected void setupStatusDisplay() 1118 { 1119 statusDisplay = new CBPanel(); 1120 statusDisplay.makeHeavy(); 1121 displayLabel = new JLabel(CBIntText.get("initialising...")); 1122 statusDisplay.addln(displayLabel); 1123 mainPane.add(statusDisplay, BorderLayout.SOUTH); 1124 } 1125 1126 public String getStatus() 1127 { 1128 return displayLabel.getText(); 1129 } 1130 1131 1135 1136 public void setStatus(String s) 1137 { 1138 displayLabel.setText(s); 1139 displayLabel.repaint(); } 1141 1142 1149 1150 public void pushStatus(String newMessage) 1151 { 1152 statusStack.push(displayLabel.getText()); 1153 setStatus(newMessage); 1154 } 1155 1156 1162 1163 public String popStatus() 1164 { 1165 String status; 1166 if (statusStack.empty()) 1167 status = ""; else 1169 status = (String ) statusStack.pop(); 1170 1171 setStatus(status); 1172 return status; } 1174 1175 1180 1181 protected void setupMainWorkArea() 1182 { 1183 1185 1186 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false); 1187 mainPane.add(splitPane, BorderLayout.CENTER); 1188 1189 treeTabPane = new JTabbedPane(); 1190 treeTabPane.setMinimumSize(new Dimension(100, 100)); 1191 1192 if (isLinux()) 1193 treeTabPane.setPreferredSize(new Dimension(265, 100)); else 1195 treeTabPane.setPreferredSize(new Dimension(240, 100)); 1197 1202 1203 explorePanel = new JScrollPane(mrTree); 1204 resultsPanel = new JScrollPane(searchTree); 1205 schemaPanel = new JScrollPane(schemaTree); 1206 1207 explorePanel.getVerticalScrollBar().setUnitIncrement(16); resultsPanel.getVerticalScrollBar().setUnitIncrement(16); 1209 schemaPanel.getVerticalScrollBar().setUnitIncrement(16); 1210 1211 splitPane.add(treeTabPane, JSplitPane.LEFT, 0); 1212 1213 if (JXplorer.getProperty("gui.viewPanel", "true").equals("true")) 1214 { 1215 userViewPanel = new JPanel(new BorderLayout()); 1216 userViewPanel.add(mainViewer, BorderLayout.CENTER); 1217 splitPane.add(userViewPanel, JSplitPane.RIGHT, 1); 1218 } 1219 1220 if (mrTree != null) treeTabPane.addTab(mrTree.getName(), new ImageIcon("images" + File.separator + "explore.gif"), explorePanel, "Displays the directory tree, and allows the user to graphically browse the directory."); if (searchTree != null) treeTabPane.addTab(searchTree.getName(), new ImageIcon("images" + File.separator + "find.gif"), resultsPanel, "Displays the search results, and allows the user to graphically browse these results."); 1222 if (schemaTree != null) treeTabPane.addTab(schemaTree.getName(), new ImageIcon("icons" + File.separator + "schema.gif"), schemaPanel, "Displays the directory schema, and allows the user to graphically browse the schema."); 1223 1224 1225 1228 1235 1236 treeTabPane.addChangeListener(new ChangeListener() 1237 { 1238 public void stateChanged(ChangeEvent e) 1239 { 1240 Component treePane = treeTabPane.getSelectedComponent(); 1241 ButtonRegister br = JXplorer.getButtonRegister(); 1242 if (treePane == explorePanel) { 1244 setStatus(CBIntText.get("Connected To ''{0}''", new String []{url})); 1245 if (br != null && isConnected()) br.setCommonState(true); mrTree.refreshEditorPane(); 1248 } 1249 else if (treePane == resultsPanel) { 1251 setStatus("Number of search results: " + String.valueOf(searchTree.getNumOfResults())); 1252 searchTree.refreshEditorPane(); 1253 } 1254 else if (treePane == schemaPanel) { 1256 setStatus(CBIntText.get("Connected To ''{0}''", new String []{url})); 1257 if (br != null) br.setCommonState(false); 1259 schemaTree.refreshEditorPane(); 1260 } 1261 } 1262 }); 1263 1264 1265 1266 1267 1268 1294 } 1295 1296 1303 public boolean isConnected() 1304 { 1305 return connected; 1306 } 1307 1308 1315 public void setConnected(boolean connected) 1316 { 1317 this.connected = connected; 1318 } 1319 1320 1324 1325 public SmartTree getActiveTree() 1326 { 1327 int paneNumber = treeTabPane.getSelectedIndex(); 1328 1329 if (paneNumber == treeTabPane.indexOfTab(CBIntText.get("Explore"))) 1330 return mrTree; 1331 else if (paneNumber == treeTabPane.indexOfTab(CBIntText.get("Results"))) 1332 return searchTree; 1333 else if (paneNumber == treeTabPane.indexOfTab(CBIntText.get("Schema"))) 1334 return schemaTree; 1335 1336 log.warning("ERROR: Unable to establish active tree - panel = " + paneNumber); 1338 return null; 1339 } 1340 1341 1345 1346 protected void setupFrills() 1347 { 1348 this.setIconImage(getImageIcon("ODlogo.gif").getImage()); 1350 this.setTitle("JXplorer"); 1351 } 1352 1353 1359 1360 public static ImageIcon getImageIcon(String name) 1361 { 1362 ImageIcon newIcon = new ImageIcon(getProperty("dir.images") + name); 1363 return newIcon; 1364 } 1365 1366 1369 1370 protected void setupHelp() 1371 { 1372 helpSystem = new CBHelpSystem("JXplorerHelp.hs"); } 1374 1375 1381 1382 public CBHelpSystem getHelpSystem() 1383 { 1384 return helpSystem; 1385 } 1386 1387 1390 1391 public void shutdown() 1392 { 1393 shutdown(null); 1394 } 1395 1396 1401 1402 public void shutdown(String msg) 1403 { 1404 setProperty("width", String.valueOf(((int) getSize().getWidth()))); 1405 setProperty("height", String.valueOf(((int) getSize().getHeight()))); 1406 1407 setProperty("xpos", String.valueOf(getX())); 1408 setProperty("ypos", String.valueOf(getY())); 1409 1410 setProperty("last.search.filter", "default"); 1412 writePropertyFile(); 1413 1414 if (msg != null) 1415 log.severe("shutting down\n" + msg); 1416 else 1417 log.warning("shutting down"); 1418 1419 System.exit(0); 1420 } 1421 1422 public static void writePropertyFile() 1423 { 1424 CBUtility.writePropertyFile(propertyFile, myProperties, new String ("# The property file location defaults to where JXplorer is installed\n" + 1425 "# - this can be over-ridden with the system property 'jxplorer.config'\n" + 1426 "# with a config directory location, or set to user home using the\n" + 1427 "# flag 'user.home' (e.g. -Djxplorer.config='user.home' on the command line).\n")); 1428 } 1429 1430 public String toString() 1431 { 1432 return "JXplorer version " + version; 1433 } 1434 1435 1436 1439 public void preConnectionSetup() 1440 { 1441 if (mrTree == null) return; 1442 mrTree.clearTree(); 1443 mrTree.setRoot(SmartTree.NODATA); 1444 1445 treeTabPane.setSelectedIndex(0); 1446 1447 if (searchTree == null) return; 1448 searchTree.clearTree(); 1449 searchTree.setRoot(SmartTree.NODATA); 1450 1451 if (schemaTree == null) return; 1452 schemaTree.clearTree(); 1453 schemaTree.setRoot(SmartTree.NODATA); 1454 1455 } 1457 1458 1466 1467 public boolean postConnectionSetup(JNDIBroker.DataConnectionQuery request) 1468 { 1469 searchTree.clearTree(); 1470 if (workOffline == true) 1471 { 1472 workOffline = false; 1473 offlineBroker.clear(); 1474 } 1476 1477 String baseDN = request.conData.baseDN; 1478 DN base = new DN(baseDN); 1479 DN[] namingContexts = null; 1480 1481 int ldapV = request.conData.version; 1482 1483 try 1484 { 1485 if (base == null || base.size() == 0 || jndiBroker.getDirOp().exists(base) == false) 1486 { 1487 if (ldapV == 2) 1488 { 1489 if (jndiBroker.getDirOp().exists(base) == false) { 1491 CBUtility.error("Error opening ldap v2 connection - bad base DN '" + ((base == null) ? "*null*" : base.toString()) + "' "); 1492 disconnect(); 1493 return false; 1494 } 1495 } 1496 else { 1498 if (base != null && base.size() > 0) 1499 log.warning("The Base DN '" + base + "' cannot be found."); 1500 1501 base = null; 1503 namingContexts = jndiBroker.readFallbackRoot(); 1505 if (baseDN.trim().length() > 0) 1506 { 1507 if (namingContexts != null && namingContexts[0] != null) 1509 log.warning("Cannot find the user-specified Base DN - Using the fall back DN '" + namingContexts[0].toString() + "'"); 1510 else 1511 log.warning("WARNING: Cannot find the user-specified Base DN, and cannot read alternative from directory. Leaving unset for the present."); 1512 } 1513 1514 if (namingContexts != null && namingContexts.length == 1) base = namingContexts[0]; } 1517 } 1518 1519 mrTree.clearTree(); 1520 mrTree.registerDataSource(jndiBroker); 1521 } 1522 catch (Exception ex) { 1524 if (ldapV != 2) 1525 { 1526 CBUtility.error("Possible errors occurred while opening connection.", ex); } 1528 else { 1530 CBUtility.error("Error opening ldap v2 connection (possibly bad base DN?) ", ex); 1531 disconnect(); 1532 return false; 1533 } 1534 } 1535 1536 1542 if (base != null) { 1544 mrTree.setRoot(base); 1545 1546 if (base.size() == 0) 1547 { 1548 mrTree.expandRoot(); 1549 mrTree.getRootNode().setAlwaysRefresh(true); 1550 } 1551 else 1552 { 1553 mrTree.expandDN(base); 1554 makeDNAutoRefreshing(base); 1555 } 1556 1557 } 1558 else if (namingContexts != null) { 1560 mrTree.setRoot(""); 1561 for (int i = 0; i < namingContexts.length; i++) { 1563 DN namingContext = namingContexts[i]; SmartNode node = mrTree.addNode(namingContext); 1566 if (node.getChildCount() == 0) node.add(new SmartNode()); } 1570 1571 for (int i = 0; i < namingContexts.length; i++) { 1573 mrTree.expandDN(namingContexts[i]); makeDNAutoRefreshing(namingContexts[i]); 1575 1576 } 1577 } 1578 else { 1580 mrTree.expandRoot(); 1581 mrTree.getRootNode().setAlwaysRefresh(true); 1582 } 1583 1584 searchTree.clearTree(); 1585 searchBroker.registerDirectoryConnection(jndiBroker); 1586 searchTree.registerDataSource(searchBroker); 1587 searchTree.setRoot(new DN(SmartTree.NODATA)); 1588 1589 schemaTree.clearTree(); 1590 1591 if (Integer.toString(ldapV) != null && ldapV > 2) 1592 { 1593 schemaBroker.registerDirectoryConnection(jndiBroker); 1594 schemaTree.registerDataSource(schemaBroker); 1595 schemaTree.setRoot(new DN("cn=schema")); 1596 1597 DXAttribute.setDefaultSchema(jndiBroker.getSchemaOps()); 1598 DXAttributes.setDefaultSchema(jndiBroker.getSchemaOps()); 1599 } 1600 else 1601 { 1602 DXAttribute.setDefaultSchema(null); 1603 DXAttributes.setDefaultSchema(null); 1604 } 1605 1606 if (base != null) 1607 { 1608 jndiBroker.getEntry(base); JXplorer.setDefaultProperty("baseDN", base.toString()); 1610 1611 url = request.conData.url; 1612 setStatus(CBIntText.get("Connected To ''{0}''", new String []{url})); 1613 } 1614 1615 getButtonRegister().setConnectedState(); 1616 mainMenu.setConnected(true); 1617 setConnected(true); 1618 1619 return true; 1620 } 1621 1622 protected void makeDNAutoRefreshing(DN dn) 1623 { 1624 try 1625 { 1626 TreePath path = ((SmartModel) mrTree.getModel()).getPathForDN(dn); 1627 if (path == null) throw new Exception ("null path returned"); 1628 Object [] nodes = path.getPath(); 1629 for (int j = 0; j < nodes.length - 1; j++) 1630 { 1631 ((SmartNode) nodes[j]).setAlwaysRefresh(true); } 1633 1634 } 1635 catch (Exception e) 1636 { 1637 log.info("INFO: messed up setting auto-expanding nodes for context '" + dn + "'"); 1638 } 1639 } 1640 1641 1642 1647 1648 public void disconnect() 1649 { 1650 jndiBroker.disconnect(); 1651 mrTree.clearTree(); 1652 schemaTree.clearTree(); 1653 searchTree.clearTree(); 1654 searchTree.setNumOfResults(0); 1655 1656 getButtonRegister().setDisconnectState(); 1657 1658 mainMenu.setDisconnected(); 1659 setConnected(false); 1660 1661 setStatus(CBIntText.get("Disconnected")); 1662 } 1663 1664 1665 1669 1670 public void setDisconnectView() 1671 { 1672 mainMenu.setDisconnected(); 1673 getButtonRegister().setDisconnectState(); 1674 1675 setStatus(CBIntText.get("Disconnected")); 1676 } 1677 1678 1679 1680 1685 1693 1694 public synchronized void addJXplorerListener(JXplorerListener l) 1695 { 1696 if (l != null) 1697 eventListeners.add(JXplorerListener.class, l); 1698 } 1699 1700 1709 public synchronized void removeJXplorerListener(JXplorerListener l) 1710 { 1711 if (l != null) 1712 eventListeners.remove(JXplorerListener.class, l); 1713 } 1714 1715 1716 1728 public void fireJXplorerEvent(JXplorerEvent e) 1729 { 1730 Object [] list = eventListeners.getListenerList(); 1731 for (int index = list.length - 2; index >= 0; index -= 2) 1732 { 1733 if (list[index] == JXplorerListener.class) 1734 { 1735 ((JXplorerListener) list[index + 1]).JXplorerDNSelected(e); 1736 } 1737 } 1738 } 1739 1740 1741 1745 1746 public void showSplashScreen(JWindow splash) 1747 { 1748 ImageIcon splashIcon = new ImageIcon("templates" + File.separator + "JXsplash.gif"); 1749 int width = splashIcon.getIconWidth(); 1750 int height = splashIcon.getIconHeight(); 1751 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 1752 splash.setBounds((screen.width - width) / 2, (screen.height - height) / 2, width, height); 1753 JLabel pic = new JLabel(splashIcon); 1754 JPanel content = (JPanel) splash.getContentPane(); 1755 content.add(pic); 1756 splash.setVisible(true); 1757 } 1758 1759 1760 1766 1767 public void setupResourceFiles() 1768 { 1769 resourceLoader = new CBResourceLoader(); 1770 classLoader = new CBClassLoader(resourceLoader); 1771 1772 String pluginPath = JXplorer.getProperty("dir.plugins"); 1773 String [] pluginFiles = CBUtility.readFilteredDirectory(pluginPath, new String []{"zip", "jar"}); 1774 if (pluginFiles == null) 1775 { 1776 log.warning("Unable to access plugins directory: '" + pluginPath + "'"); 1777 return; 1778 } 1779 1780 for (int i = 0; i < pluginFiles.length; i++) 1781 resourceLoader.addResource(new CBJarResource(pluginPath + pluginFiles[i])); 1782 1783 setupSecurityProviders(); 1784 1785 setupGSSAPIConfig(); 1786 1787 } 1788 1789 1793 1794 protected void setupGSSAPIConfig() 1795 { 1796 try 1797 { 1798 String sep = System.getProperty("line.separator"); 1799 1800 String defaultFileText = "com.ca.commons.jndi.JNDIOps {" + sep + 1802 " com.sun.security.auth.module.Krb5LoginModule required client=TRUE" + sep + 1803 " \t\t\t\t\t\t\t\t\t\t\t\t\t\tuseTicketCache=TRUE;" + sep + 1804 "};"; 1805 1806 String configFile = CBUtility.getPropertyConfigPath("gssapi.conf"); 1807 File gssapi_conf = new File(configFile); 1808 1809 if (gssapi_conf.exists() == false) 1812 { 1813 FileWriter confWriter = new FileWriter(gssapi_conf); 1814 confWriter.write(defaultFileText); 1815 confWriter.close(); 1816 } 1817 1818 1819 System.setProperty("java.security.auth.login.config", gssapi_conf.getCanonicalPath().toString()); 1820 } 1821 catch (IOException e) 1822 { 1823 log.warning("ERROR: Unable to initialise GSSAPI config file " + e); 1824 } 1825 } 1826 1827 protected void setupSecurityProviders() 1828 { 1829 1832 String providerName = getProperty("securityProvider2", null); 1833 if (providerName != null) 1834 addSecurityProvider(providerName); 1835 1836 providerName = getProperty("securityProvider1", null); 1837 if (providerName != null) 1838 addSecurityProvider(providerName); 1839 1840 providerName = getProperty("securityProvider0", null); 1841 if (providerName != null) 1842 addSecurityProvider(providerName); 1843 1844 providerName = getProperty("securityProvider", null); 1845 if (providerName != null) 1846 addSecurityProvider(providerName); 1847 1848 1851 providerName = getProperty("securityProvider3", null); 1852 if (providerName != null) 1853 { 1854 CBUtility.error(CBIntText.get("Too many security providers in config file.")); 1855 printSecurityProviders(); 1856 } 1857 else if (debugLevel >= 2) 1859 printSecurityProviders(); 1860 1861 1865 JndiSocketFactory.setClassLoader(classLoader); 1866 } 1867 1868 1874 1875 protected void addSecurityProvider(String providerName) 1876 { 1877 1878 1881 try 1882 { 1883 1884 Class providerClass = classLoader.loadClass(providerName); 1885 Object providerObject = providerClass.newInstance(); 1886 1887 Security.insertProviderAt((Provider ) providerObject, 1); 1888 1889 } 1891 catch (Exception e) 1892 { 1893 System.err.println("\n*** unable to load new security provider: " + ((providerName == null) ? "null" : providerName)); 1894 System.err.println(e); 1895 } 1896 1897 } 1898 1899 protected static void printSecurityProviders() 1900 { 1901 log.fine("\n***\n*** LIST OF CURRENT SECURITY PROVIDERS\n***"); 1902 Provider [] current = Security.getProviders(); 1903 { 1904 for (int i = 0; i < current.length; i++) 1905 { 1906 log.fine("provider: " + i + " = " + current[i].getName() + " " + current[i].getInfo()); 1907 log.fine(" (" + current[i].getClass().toString() + ")\n"); 1908 } 1909 } 1910 log.fine("\n***\n*** END LIST\n***\n"); 1911 } 1912 1913 1917 1918 public static boolean isSolaris() 1919 { 1920 String os = System.getProperty("os.name"); 1921 if (os == null) return false; 1922 1923 os = os.toLowerCase(); 1924 if (os.indexOf("sun") > -1) return true; 1925 if (os.indexOf("solaris") > -1) return true; 1926 return false; 1927 } 1928 1929 1930 1936 1937 public static boolean isLinux() 1938 { 1939 String os = System.getProperty("os.name"); 1940 1941 if (os != null && os.toLowerCase().indexOf("linux") > -1) 1942 return true; 1943 1944 return false; 1945 } 1946 1947 1953 1954 public static boolean isMac() 1955 { 1956 String os = System.getProperty("mrj.version"); return (os != null); 1958 } 1959 1960 1966 1967 public static boolean isWindows() 1968 { 1969 String os = System.getProperty("os.name"); 1971 if (os != null && os.toLowerCase().indexOf("windows") > -1) 1972 return true; 1973 1974 return false; 1975 } 1976 1977 1984 1985 public static ButtonRegister getButtonRegister() 1986 { 1987 return buttonRegister; 1988 } 1989} | Popular Tags |