1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * ident "%Z%%M% %I% %E% SMI" 24*7c478bd9Sstevel@tonic-gate * 25*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2000 by Sun Microsystems, Inc. 26*7c478bd9Sstevel@tonic-gate * All rights reserved. 27*7c478bd9Sstevel@tonic-gate */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate import java.awt.*; 30*7c478bd9Sstevel@tonic-gate import java.awt.event.*; 31*7c478bd9Sstevel@tonic-gate import java.util.*; 32*7c478bd9Sstevel@tonic-gate import java.text.*; 33*7c478bd9Sstevel@tonic-gate import java.io.*; 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate /** 36*7c478bd9Sstevel@tonic-gate * Defaults class stores all defaults that are recorded locally on the 37*7c478bd9Sstevel@tonic-gate * client side. It is also resonsible for showing the DefaultsFrame 38*7c478bd9Sstevel@tonic-gate * which allows the user to see and change these values. 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate public class Defaults { 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate // These gui components are the actual components that go on the editing frame 43*7c478bd9Sstevel@tonic-gate // that allows the user to change the defaults. The reason they are public is 44*7c478bd9Sstevel@tonic-gate // that they need to be accessible to KdcGui so that it can set up the 45*7c478bd9Sstevel@tonic-gate // listeners for them in setupDefaultsNormalListeners() and 46*7c478bd9Sstevel@tonic-gate // setupDefaultsHelpListeners(). 47*7c478bd9Sstevel@tonic-gate public Checkbox disableAccount; 48*7c478bd9Sstevel@tonic-gate public Checkbox forcePasswordChange; 49*7c478bd9Sstevel@tonic-gate public Checkbox allowPostdatedTix; 50*7c478bd9Sstevel@tonic-gate public Checkbox allowForwardableTix; 51*7c478bd9Sstevel@tonic-gate public Checkbox allowRenewableTix; 52*7c478bd9Sstevel@tonic-gate public Checkbox allowProxiableTix; 53*7c478bd9Sstevel@tonic-gate public Checkbox allowServiceTix; 54*7c478bd9Sstevel@tonic-gate public Checkbox allowTGTAuth; 55*7c478bd9Sstevel@tonic-gate public Checkbox allowDupAuth; 56*7c478bd9Sstevel@tonic-gate public Checkbox requirePreauth; 57*7c478bd9Sstevel@tonic-gate public Checkbox requireHWAuth; 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate public Checkbox serverSide; 60*7c478bd9Sstevel@tonic-gate public TextField maxTicketLife; 61*7c478bd9Sstevel@tonic-gate public TextField maxTicketRenewableLife; 62*7c478bd9Sstevel@tonic-gate public TextField accountExpiryDate; 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate public Label maxTicketLifeLabel; 65*7c478bd9Sstevel@tonic-gate public Label maxTicketRenewableLifeLabel; 66*7c478bd9Sstevel@tonic-gate public Label accountExpiryDateLabel; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate public Checkbox showLists; 69*7c478bd9Sstevel@tonic-gate public Checkbox staticLists; 70*7c478bd9Sstevel@tonic-gate public TextField cacheTime; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate public Label cacheTimeLabel; 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate public Button lifeMoreButton; 75*7c478bd9Sstevel@tonic-gate public Button renewalMoreButton; 76*7c478bd9Sstevel@tonic-gate public Button dateMoreButton; 77*7c478bd9Sstevel@tonic-gate public Button cacheMoreButton; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate public Button saveButton; 80*7c478bd9Sstevel@tonic-gate public Button applyButton; 81*7c478bd9Sstevel@tonic-gate public Button cancelButton; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate public MenuItem csHelp; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate // These data items correspond to fields in struct struct 86*7c478bd9Sstevel@tonic-gate // _kadm5_config_params 87*7c478bd9Sstevel@tonic-gate private Flags flags; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate private boolean serverSideValue; 90*7c478bd9Sstevel@tonic-gate private int maxTicketLifeValue; 91*7c478bd9Sstevel@tonic-gate private int maxTicketRenewableLifeValue; 92*7c478bd9Sstevel@tonic-gate private Date accountExpiryDateValue; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate private boolean showListsValue; 95*7c478bd9Sstevel@tonic-gate private boolean staticListsValue; 96*7c478bd9Sstevel@tonic-gate private long cacheTimeValue; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate private String defaultsFile; 99*7c478bd9Sstevel@tonic-gate private Color background; 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate private EditingFrame frame = null; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate private boolean helpMode = false; 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate // For I18N 106*7c478bd9Sstevel@tonic-gate private static DateFormat df; 107*7c478bd9Sstevel@tonic-gate private static NumberFormat nf; 108*7c478bd9Sstevel@tonic-gate private static ResourceBundle rb; 109*7c478bd9Sstevel@tonic-gate // no help data since help is handled by KdcGui class 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate private static String neverString; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate // For debugging the window arrangement 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate Color SEPERATOR_COLOR = Color.blue; 116*7c478bd9Sstevel@tonic-gate Color CHECKBOX_COLOR = Color.orange; 117*7c478bd9Sstevel@tonic-gate Color LABEL_COLOR = Color.pink; 118*7c478bd9Sstevel@tonic-gate Color PANEL_COLOR1 = Color.lightGray; 119*7c478bd9Sstevel@tonic-gate Color PANEL_COLOR2 = Color.darkGray; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /** 122*7c478bd9Sstevel@tonic-gate * Constructor for Defaults. 123*7c478bd9Sstevel@tonic-gate * @param defaultsFile the file from which to read the defaults. 124*7c478bd9Sstevel@tonic-gate */ Defaults(String defaultsFile, Color background)125*7c478bd9Sstevel@tonic-gate Defaults(String defaultsFile, Color background) { 126*7c478bd9Sstevel@tonic-gate this.defaultsFile = defaultsFile; 127*7c478bd9Sstevel@tonic-gate this.background = background; 128*7c478bd9Sstevel@tonic-gate flags = new Flags(); 129*7c478bd9Sstevel@tonic-gate serverSideValue = true; 130*7c478bd9Sstevel@tonic-gate maxTicketLifeValue = 144000; 131*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeValue = 144000; 132*7c478bd9Sstevel@tonic-gate // set expiry to now + one year 133*7c478bd9Sstevel@tonic-gate Calendar c = Calendar.getInstance(); 134*7c478bd9Sstevel@tonic-gate c.roll(Calendar.YEAR, true); 135*7c478bd9Sstevel@tonic-gate accountExpiryDateValue = c.getTime(); 136*7c478bd9Sstevel@tonic-gate showListsValue = true; 137*7c478bd9Sstevel@tonic-gate staticListsValue = false; 138*7c478bd9Sstevel@tonic-gate cacheTimeValue = 300; 139*7c478bd9Sstevel@tonic-gate readFromFile(); 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate /** 143*7c478bd9Sstevel@tonic-gate * Constructor for Defaults. 144*7c478bd9Sstevel@tonic-gate * @param old an existing defaults object to clone 145*7c478bd9Sstevel@tonic-gate */ Defaults(Defaults old)146*7c478bd9Sstevel@tonic-gate Defaults(Defaults old) { 147*7c478bd9Sstevel@tonic-gate defaultsFile = old.defaultsFile; 148*7c478bd9Sstevel@tonic-gate background = old.background; 149*7c478bd9Sstevel@tonic-gate flags = new Flags(old.flags.getBits()); 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate maxTicketLifeValue = old.maxTicketLifeValue; 152*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeValue = old.maxTicketRenewableLifeValue; 153*7c478bd9Sstevel@tonic-gate accountExpiryDateValue = old.accountExpiryDateValue; 154*7c478bd9Sstevel@tonic-gate showListsValue = old.showListsValue; 155*7c478bd9Sstevel@tonic-gate staticListsValue = old.staticListsValue; 156*7c478bd9Sstevel@tonic-gate cacheTimeValue = old.cacheTimeValue; 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate restoreValues(Defaults old)159*7c478bd9Sstevel@tonic-gate public void restoreValues(Defaults old) { 160*7c478bd9Sstevel@tonic-gate flags = new Flags(old.flags.getBits()); 161*7c478bd9Sstevel@tonic-gate maxTicketLifeValue = old.maxTicketLifeValue; 162*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeValue = old.maxTicketRenewableLifeValue; 163*7c478bd9Sstevel@tonic-gate accountExpiryDateValue = old.accountExpiryDateValue; 164*7c478bd9Sstevel@tonic-gate showListsValue = old.showListsValue; 165*7c478bd9Sstevel@tonic-gate staticListsValue = old.staticListsValue; 166*7c478bd9Sstevel@tonic-gate cacheTimeValue = old.cacheTimeValue; 167*7c478bd9Sstevel@tonic-gate updateGuiComponents(); 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /** 171*7c478bd9Sstevel@tonic-gate * Returns a gui Frame with the defaults on it for editing. 172*7c478bd9Sstevel@tonic-gate */ getEditingFrame()173*7c478bd9Sstevel@tonic-gate public Frame getEditingFrame() { 174*7c478bd9Sstevel@tonic-gate if (frame == null) { 175*7c478bd9Sstevel@tonic-gate frame = new EditingFrame(); 176*7c478bd9Sstevel@tonic-gate updateGuiComponents(); 177*7c478bd9Sstevel@tonic-gate frame.setSize(500, 680); 178*7c478bd9Sstevel@tonic-gate frame.setResizable(true); 179*7c478bd9Sstevel@tonic-gate frame.setBackground(background); 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate return frame; 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate /** 185*7c478bd9Sstevel@tonic-gate * Reread the defaults file in case it has changed, and refresh view 186*7c478bd9Sstevel@tonic-gate */ refreshDefaults()187*7c478bd9Sstevel@tonic-gate public void refreshDefaults() { 188*7c478bd9Sstevel@tonic-gate readFromFile(); 189*7c478bd9Sstevel@tonic-gate updateGuiComponents(); 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate /** 194*7c478bd9Sstevel@tonic-gate * Update the duration and date text fields from gui. 195*7c478bd9Sstevel@tonic-gate * Check to see if any one of them had a parse error. 196*7c478bd9Sstevel@tonic-gate * @return true if all is ok, false if an error occurs 197*7c478bd9Sstevel@tonic-gate */ 198*7c478bd9Sstevel@tonic-gate // Quits as soon as the first error is detected. The method that 199*7c478bd9Sstevel@tonic-gate // detects the error also shows a dialog box with a message. updateFromGui()200*7c478bd9Sstevel@tonic-gate public final boolean updateFromGui() { 201*7c478bd9Sstevel@tonic-gate return (setMaxTicketLife() && setMaxTicketRenewableLife() 202*7c478bd9Sstevel@tonic-gate && setAccountExpiryDate() && setCacheTime()); 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate setServerSide()205*7c478bd9Sstevel@tonic-gate boolean setServerSide() { 206*7c478bd9Sstevel@tonic-gate serverSideValue = serverSide.getState(); 207*7c478bd9Sstevel@tonic-gate enableTicketLifeFields(serverSideValue); 208*7c478bd9Sstevel@tonic-gate return true; 209*7c478bd9Sstevel@tonic-gate } 210*7c478bd9Sstevel@tonic-gate enableTicketLifeFields(boolean fromServer)211*7c478bd9Sstevel@tonic-gate private void enableTicketLifeFields(boolean fromServer) { 212*7c478bd9Sstevel@tonic-gate maxTicketLifeLabel.setEnabled(!fromServer); 213*7c478bd9Sstevel@tonic-gate maxTicketLife.setEnabled(!fromServer); 214*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeLabel.setEnabled(!fromServer); 215*7c478bd9Sstevel@tonic-gate maxTicketRenewableLife.setEnabled(!fromServer); 216*7c478bd9Sstevel@tonic-gate lifeMoreButton.setEnabled(!fromServer); 217*7c478bd9Sstevel@tonic-gate renewalMoreButton.setEnabled(!fromServer); 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate setMaxTicketLife()220*7c478bd9Sstevel@tonic-gate boolean setMaxTicketLife() { 221*7c478bd9Sstevel@tonic-gate try { 222*7c478bd9Sstevel@tonic-gate maxTicketLifeValue = 223*7c478bd9Sstevel@tonic-gate nf.parse(maxTicketLife.getText().trim()).intValue(); 224*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 225*7c478bd9Sstevel@tonic-gate KdcGui.showDataFormatError(maxTicketLife, KdcGui.DURATION_DATA); 226*7c478bd9Sstevel@tonic-gate return false; 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate return true; 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate /** 233*7c478bd9Sstevel@tonic-gate * Sets the maxTicketRenewable field value from the corresponding text 234*7c478bd9Sstevel@tonic-gate * field. 235*7c478bd9Sstevel@tonic-gate */ setMaxTicketRenewableLife()236*7c478bd9Sstevel@tonic-gate boolean setMaxTicketRenewableLife() { 237*7c478bd9Sstevel@tonic-gate try { 238*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeValue = 239*7c478bd9Sstevel@tonic-gate nf.parse(maxTicketRenewableLife.getText().trim()).intValue(); 240*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 241*7c478bd9Sstevel@tonic-gate KdcGui.showDataFormatError(maxTicketRenewableLife, 242*7c478bd9Sstevel@tonic-gate KdcGui.DURATION_DATA); 243*7c478bd9Sstevel@tonic-gate return false; 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate return true; 247*7c478bd9Sstevel@tonic-gate } 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate /** 250*7c478bd9Sstevel@tonic-gate * Sets the accountExpiryDate field value from the corresponding text field. 251*7c478bd9Sstevel@tonic-gate */ setAccountExpiryDate()252*7c478bd9Sstevel@tonic-gate boolean setAccountExpiryDate() { 253*7c478bd9Sstevel@tonic-gate String value = accountExpiryDate.getText().trim(); 254*7c478bd9Sstevel@tonic-gate if (value.equalsIgnoreCase(neverString)) 255*7c478bd9Sstevel@tonic-gate accountExpiryDateValue = new Date(0); 256*7c478bd9Sstevel@tonic-gate else { 257*7c478bd9Sstevel@tonic-gate try { 258*7c478bd9Sstevel@tonic-gate accountExpiryDateValue = df.parse(value); 259*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 260*7c478bd9Sstevel@tonic-gate KdcGui.showDataFormatError(accountExpiryDate, KdcGui.DATE_DATA); 261*7c478bd9Sstevel@tonic-gate return false; 262*7c478bd9Sstevel@tonic-gate } catch (NullPointerException e) { 263*7c478bd9Sstevel@tonic-gate // gets thrown when parse string begins with text 264*7c478bd9Sstevel@tonic-gate // probable JDK bug 265*7c478bd9Sstevel@tonic-gate KdcGui.showDataFormatError(accountExpiryDate, KdcGui.DATE_DATA); 266*7c478bd9Sstevel@tonic-gate return false; 267*7c478bd9Sstevel@tonic-gate } catch (IndexOutOfBoundsException e) { 268*7c478bd9Sstevel@tonic-gate // gets thrown when parse string contains only one number 269*7c478bd9Sstevel@tonic-gate // probable JDK bug 270*7c478bd9Sstevel@tonic-gate KdcGui.showDataFormatError(accountExpiryDate, KdcGui.DATE_DATA); 271*7c478bd9Sstevel@tonic-gate return false; 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate return true; 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate /** 278*7c478bd9Sstevel@tonic-gate * Sets the cacheTime field value from the corresponding text field. 279*7c478bd9Sstevel@tonic-gate */ setCacheTime()280*7c478bd9Sstevel@tonic-gate boolean setCacheTime() { 281*7c478bd9Sstevel@tonic-gate try { 282*7c478bd9Sstevel@tonic-gate cacheTimeValue = nf.parse(cacheTime.getText().trim()).intValue(); 283*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 284*7c478bd9Sstevel@tonic-gate KdcGui.showDataFormatError(cacheTime, KdcGui.DURATION_DATA); 285*7c478bd9Sstevel@tonic-gate return false; 286*7c478bd9Sstevel@tonic-gate } 287*7c478bd9Sstevel@tonic-gate return true; 288*7c478bd9Sstevel@tonic-gate } 289*7c478bd9Sstevel@tonic-gate setShowLists()290*7c478bd9Sstevel@tonic-gate boolean setShowLists() { 291*7c478bd9Sstevel@tonic-gate showListsValue = showLists.getState(); 292*7c478bd9Sstevel@tonic-gate return true; 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate setStaticLists()295*7c478bd9Sstevel@tonic-gate boolean setStaticLists() { 296*7c478bd9Sstevel@tonic-gate staticListsValue = staticLists.getState(); 297*7c478bd9Sstevel@tonic-gate enableCacheTimeFields(staticListsValue); 298*7c478bd9Sstevel@tonic-gate return true; 299*7c478bd9Sstevel@tonic-gate } 300*7c478bd9Sstevel@tonic-gate enableCacheTimeFields(boolean staticLists)301*7c478bd9Sstevel@tonic-gate private void enableCacheTimeFields(boolean staticLists) { 302*7c478bd9Sstevel@tonic-gate cacheTime.setEnabled(!staticLists); 303*7c478bd9Sstevel@tonic-gate cacheTimeLabel.setEnabled(!staticLists); 304*7c478bd9Sstevel@tonic-gate cacheMoreButton.setEnabled(!staticLists); 305*7c478bd9Sstevel@tonic-gate } 306*7c478bd9Sstevel@tonic-gate getServerSide()307*7c478bd9Sstevel@tonic-gate public boolean getServerSide() { 308*7c478bd9Sstevel@tonic-gate return serverSideValue; 309*7c478bd9Sstevel@tonic-gate } 310*7c478bd9Sstevel@tonic-gate getMaxTicketLife()311*7c478bd9Sstevel@tonic-gate public Integer getMaxTicketLife() { 312*7c478bd9Sstevel@tonic-gate return new Integer(maxTicketLifeValue); 313*7c478bd9Sstevel@tonic-gate } 314*7c478bd9Sstevel@tonic-gate getMaxTicketRenewableLife()315*7c478bd9Sstevel@tonic-gate public Integer getMaxTicketRenewableLife() { 316*7c478bd9Sstevel@tonic-gate return new Integer(maxTicketRenewableLifeValue); 317*7c478bd9Sstevel@tonic-gate } 318*7c478bd9Sstevel@tonic-gate getAccountExpiryDate()319*7c478bd9Sstevel@tonic-gate public Date getAccountExpiryDate() { 320*7c478bd9Sstevel@tonic-gate return new Date(accountExpiryDateValue.getTime()); 321*7c478bd9Sstevel@tonic-gate } 322*7c478bd9Sstevel@tonic-gate getShowLists()323*7c478bd9Sstevel@tonic-gate public boolean getShowLists() { 324*7c478bd9Sstevel@tonic-gate return showListsValue; 325*7c478bd9Sstevel@tonic-gate } 326*7c478bd9Sstevel@tonic-gate getStaticLists()327*7c478bd9Sstevel@tonic-gate public boolean getStaticLists() { 328*7c478bd9Sstevel@tonic-gate return staticListsValue; 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate getCacheLists()331*7c478bd9Sstevel@tonic-gate public boolean getCacheLists() { 332*7c478bd9Sstevel@tonic-gate return staticListsValue; 333*7c478bd9Sstevel@tonic-gate } 334*7c478bd9Sstevel@tonic-gate getCacheTime()335*7c478bd9Sstevel@tonic-gate public long getCacheTime() { 336*7c478bd9Sstevel@tonic-gate return cacheTimeValue; 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate getFlags()339*7c478bd9Sstevel@tonic-gate public Flags getFlags() { 340*7c478bd9Sstevel@tonic-gate return flags; 341*7c478bd9Sstevel@tonic-gate } 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate /** 344*7c478bd9Sstevel@tonic-gate * Toggles the value of the bit specified. 345*7c478bd9Sstevel@tonic-gate */ toggleFlag(int bitmask)346*7c478bd9Sstevel@tonic-gate public void toggleFlag(int bitmask) { 347*7c478bd9Sstevel@tonic-gate flags.toggleFlags(bitmask); 348*7c478bd9Sstevel@tonic-gate } 349*7c478bd9Sstevel@tonic-gate close(boolean save)350*7c478bd9Sstevel@tonic-gate public void close(boolean save) { 351*7c478bd9Sstevel@tonic-gate if (frame != null) 352*7c478bd9Sstevel@tonic-gate frame.close(save); 353*7c478bd9Sstevel@tonic-gate } 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate /** 357*7c478bd9Sstevel@tonic-gate * Saves the fields onto a file. 358*7c478bd9Sstevel@tonic-gate */ saveToFile()359*7c478bd9Sstevel@tonic-gate private void saveToFile() { 360*7c478bd9Sstevel@tonic-gate try { 361*7c478bd9Sstevel@tonic-gate PrintWriter outFile = null; 362*7c478bd9Sstevel@tonic-gate outFile = new PrintWriter( 363*7c478bd9Sstevel@tonic-gate new BufferedWriter(new FileWriter(defaultsFile))); 364*7c478bd9Sstevel@tonic-gate outFile.println(flags.getBits()); 365*7c478bd9Sstevel@tonic-gate outFile.println(maxTicketRenewableLifeValue); 366*7c478bd9Sstevel@tonic-gate outFile.println(df.format(accountExpiryDateValue)); 367*7c478bd9Sstevel@tonic-gate outFile.println((new Boolean(showListsValue)).toString()); 368*7c478bd9Sstevel@tonic-gate outFile.println((new Boolean(staticListsValue)).toString()); 369*7c478bd9Sstevel@tonic-gate outFile.println((new Long(cacheTimeValue)).toString()); 370*7c478bd9Sstevel@tonic-gate outFile.println(serverSideValue); 371*7c478bd9Sstevel@tonic-gate outFile.println(maxTicketLifeValue); 372*7c478bd9Sstevel@tonic-gate outFile.flush(); 373*7c478bd9Sstevel@tonic-gate outFile.close(); 374*7c478bd9Sstevel@tonic-gate } catch (IOException e) { /* xxx: warn user */ } 375*7c478bd9Sstevel@tonic-gate } 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate /** 378*7c478bd9Sstevel@tonic-gate * Reads the fields from a file. 379*7c478bd9Sstevel@tonic-gate */ readFromFile()380*7c478bd9Sstevel@tonic-gate private void readFromFile() { 381*7c478bd9Sstevel@tonic-gate try { 382*7c478bd9Sstevel@tonic-gate BufferedReader inFile = null; 383*7c478bd9Sstevel@tonic-gate inFile = new BufferedReader(new FileReader(defaultsFile)); 384*7c478bd9Sstevel@tonic-gate flags = new Flags(new Integer(inFile.readLine()).intValue()); 385*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeValue = 386*7c478bd9Sstevel@tonic-gate new Integer(inFile.readLine()).intValue(); 387*7c478bd9Sstevel@tonic-gate accountExpiryDateValue = df.parse(inFile.readLine()); 388*7c478bd9Sstevel@tonic-gate String s; 389*7c478bd9Sstevel@tonic-gate s = inFile.readLine(); 390*7c478bd9Sstevel@tonic-gate if (s == null) 391*7c478bd9Sstevel@tonic-gate showListsValue = true; 392*7c478bd9Sstevel@tonic-gate else 393*7c478bd9Sstevel@tonic-gate showListsValue = (new Boolean(s)).booleanValue(); 394*7c478bd9Sstevel@tonic-gate s = inFile.readLine(); 395*7c478bd9Sstevel@tonic-gate if (s == null) 396*7c478bd9Sstevel@tonic-gate staticListsValue = false; 397*7c478bd9Sstevel@tonic-gate else 398*7c478bd9Sstevel@tonic-gate staticListsValue = (new Boolean(s)).booleanValue(); 399*7c478bd9Sstevel@tonic-gate s = inFile.readLine(); 400*7c478bd9Sstevel@tonic-gate if (s == null) 401*7c478bd9Sstevel@tonic-gate cacheTimeValue = 300; 402*7c478bd9Sstevel@tonic-gate else try { 403*7c478bd9Sstevel@tonic-gate cacheTimeValue = nf.parse(s).longValue(); 404*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 405*7c478bd9Sstevel@tonic-gate cacheTimeValue = 300; 406*7c478bd9Sstevel@tonic-gate } 407*7c478bd9Sstevel@tonic-gate serverSideValue = new Boolean(inFile.readLine()).booleanValue(); 408*7c478bd9Sstevel@tonic-gate maxTicketLifeValue = new Integer(inFile.readLine()).intValue(); 409*7c478bd9Sstevel@tonic-gate } catch (FileNotFoundException e) { 410*7c478bd9Sstevel@tonic-gate /* default values. new file will be created automatically. */} 411*7c478bd9Sstevel@tonic-gate catch (IOException e) { /* will create new one */} 412*7c478bd9Sstevel@tonic-gate catch (ParseException e) { /* leave default values in */} 413*7c478bd9Sstevel@tonic-gate catch (NumberFormatException e) { /* leave default values in */} 414*7c478bd9Sstevel@tonic-gate catch (NullPointerException e) { /* leave default values in */} 415*7c478bd9Sstevel@tonic-gate catch (StringIndexOutOfBoundsException e) { 416*7c478bd9Sstevel@tonic-gate /* leave default values in */} 417*7c478bd9Sstevel@tonic-gate } 418*7c478bd9Sstevel@tonic-gate 419*7c478bd9Sstevel@tonic-gate /** 420*7c478bd9Sstevel@tonic-gate * Sets the value of the gui components from the instance variables 421*7c478bd9Sstevel@tonic-gate * that get filled from the defaultsFile. 422*7c478bd9Sstevel@tonic-gate */ updateGuiComponents()423*7c478bd9Sstevel@tonic-gate public void updateGuiComponents() { 424*7c478bd9Sstevel@tonic-gate if (frame == null) 425*7c478bd9Sstevel@tonic-gate getEditingFrame(); 426*7c478bd9Sstevel@tonic-gate else { 427*7c478bd9Sstevel@tonic-gate updateFlags(); 428*7c478bd9Sstevel@tonic-gate serverSide.setState(serverSideValue); 429*7c478bd9Sstevel@tonic-gate enableTicketLifeFields(serverSideValue); 430*7c478bd9Sstevel@tonic-gate maxTicketLife.setText(nf.format(maxTicketLifeValue)); 431*7c478bd9Sstevel@tonic-gate maxTicketRenewableLife.setText( 432*7c478bd9Sstevel@tonic-gate nf.format(maxTicketRenewableLifeValue)); 433*7c478bd9Sstevel@tonic-gate String text = (accountExpiryDateValue.getTime() == 0 ? neverString 434*7c478bd9Sstevel@tonic-gate : df.format(accountExpiryDateValue)); 435*7c478bd9Sstevel@tonic-gate accountExpiryDate.setText(text); 436*7c478bd9Sstevel@tonic-gate showLists.setState(showListsValue); 437*7c478bd9Sstevel@tonic-gate staticLists.setState(staticListsValue); 438*7c478bd9Sstevel@tonic-gate enableCacheTimeFields(staticListsValue); 439*7c478bd9Sstevel@tonic-gate cacheTime.setText((new Long(cacheTimeValue)).toString()); 440*7c478bd9Sstevel@tonic-gate } 441*7c478bd9Sstevel@tonic-gate } 442*7c478bd9Sstevel@tonic-gate updateFlags()443*7c478bd9Sstevel@tonic-gate private void updateFlags() { 444*7c478bd9Sstevel@tonic-gate disableAccount.setState(flags.getFlag(Flags.DISALLOW_ALL_TIX)); 445*7c478bd9Sstevel@tonic-gate forcePasswordChange.setState(flags.getFlag(Flags.REQUIRES_PWCHANGE)); 446*7c478bd9Sstevel@tonic-gate allowPostdatedTix.setState(!flags.getFlag(Flags.DISALLOW_POSTDATED)); 447*7c478bd9Sstevel@tonic-gate allowForwardableTix.setState(!flags.getFlag( 448*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_FORWARDABLE)); 449*7c478bd9Sstevel@tonic-gate allowRenewableTix.setState(!flags.getFlag(Flags.DISALLOW_RENEWABLE)); 450*7c478bd9Sstevel@tonic-gate allowProxiableTix.setState(!flags.getFlag(Flags.DISALLOW_PROXIABLE)); 451*7c478bd9Sstevel@tonic-gate allowServiceTix.setState(!flags.getFlag(Flags.DISALLOW_SVR)); 452*7c478bd9Sstevel@tonic-gate allowTGTAuth.setState(!flags.getFlag(Flags.DISALLOW_TGT_BASED)); 453*7c478bd9Sstevel@tonic-gate allowDupAuth.setState(!flags.getFlag(Flags.DISALLOW_DUP_SKEY)); 454*7c478bd9Sstevel@tonic-gate requirePreauth.setState(flags.getFlag(Flags.REQUIRE_PRE_AUTH)); 455*7c478bd9Sstevel@tonic-gate requireHWAuth.setState(flags.getFlag(Flags.REQUIRE_HW_AUTH)); 456*7c478bd9Sstevel@tonic-gate } 457*7c478bd9Sstevel@tonic-gate 458*7c478bd9Sstevel@tonic-gate /** 459*7c478bd9Sstevel@tonic-gate * Call rb.getString(), but catch exception and return English 460*7c478bd9Sstevel@tonic-gate * key so that small spelling errors don't cripple the GUI 461*7c478bd9Sstevel@tonic-gate * 462*7c478bd9Sstevel@tonic-gate */ getString(String key)463*7c478bd9Sstevel@tonic-gate private static final String getString(String key) { 464*7c478bd9Sstevel@tonic-gate try { 465*7c478bd9Sstevel@tonic-gate String res = rb.getString(key); 466*7c478bd9Sstevel@tonic-gate return res; 467*7c478bd9Sstevel@tonic-gate } catch (MissingResourceException e) { 468*7c478bd9Sstevel@tonic-gate System.out.println("Missing resource "+key+", using English."); 469*7c478bd9Sstevel@tonic-gate return key; 470*7c478bd9Sstevel@tonic-gate } 471*7c478bd9Sstevel@tonic-gate } 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate /* 474*7c478bd9Sstevel@tonic-gate ********************************************** 475*7c478bd9Sstevel@tonic-gate * I N N E R C L A S S E S 476*7c478bd9Sstevel@tonic-gate ********************************************** 477*7c478bd9Sstevel@tonic-gate */ 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate private class EditingFrame extends Frame { EditingFrame()480*7c478bd9Sstevel@tonic-gate public EditingFrame() { 481*7c478bd9Sstevel@tonic-gate super(getString("Properties")); 482*7c478bd9Sstevel@tonic-gate setLayout(new GridBagLayout()); 483*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 484*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 485*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 486*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 487*7c478bd9Sstevel@tonic-gate Label l; 488*7c478bd9Sstevel@tonic-gate l = new Label(getString("Defaults for New Principals"), 489*7c478bd9Sstevel@tonic-gate Label.CENTER); 490*7c478bd9Sstevel@tonic-gate l.setFont(new Font("Dialog", Font.PLAIN, 16)); 491*7c478bd9Sstevel@tonic-gate // l.setBackground(LABEL_COLOR); 492*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(10, 10, 0, 10); 493*7c478bd9Sstevel@tonic-gate add(l, gbc); 494*7c478bd9Sstevel@tonic-gate addFlags(); 495*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(10, 10, 10, 10); 496*7c478bd9Sstevel@tonic-gate add(new LineSeparator(), gbc); 497*7c478bd9Sstevel@tonic-gate addTextFields(); 498*7c478bd9Sstevel@tonic-gate add(new LineSeparator(), gbc); 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(0, 10, 10, 10); 501*7c478bd9Sstevel@tonic-gate l = new Label(getString("List Controls"), Label.CENTER); 502*7c478bd9Sstevel@tonic-gate l.setFont(new Font("Dialog", Font.PLAIN, 16)); 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate add(l, gbc); 505*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(0, 10, 10, 10); 506*7c478bd9Sstevel@tonic-gate add(new LineSeparator(), gbc); 507*7c478bd9Sstevel@tonic-gate addListFields(); 508*7c478bd9Sstevel@tonic-gate addButtons(); 509*7c478bd9Sstevel@tonic-gate addWindowListener(new WindowCloseListener()); 510*7c478bd9Sstevel@tonic-gate addHelpMenu(); 511*7c478bd9Sstevel@tonic-gate } 512*7c478bd9Sstevel@tonic-gate 513*7c478bd9Sstevel@tonic-gate /** 514*7c478bd9Sstevel@tonic-gate * Helper method for constructor to add checkboxes and labels for 515*7c478bd9Sstevel@tonic-gate * flags. 516*7c478bd9Sstevel@tonic-gate */ addFlags()517*7c478bd9Sstevel@tonic-gate private void addFlags() { 518*7c478bd9Sstevel@tonic-gate Panel p = new Panel(); 519*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 520*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 521*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 522*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 523*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(0, 10, 0, 10); 524*7c478bd9Sstevel@tonic-gate p.setLayout(new GridBagLayout()); 525*7c478bd9Sstevel@tonic-gate add(p, gbc); 526*7c478bd9Sstevel@tonic-gate 527*7c478bd9Sstevel@tonic-gate disableAccount = new Checkbox(); 528*7c478bd9Sstevel@tonic-gate forcePasswordChange = new Checkbox(); 529*7c478bd9Sstevel@tonic-gate allowPostdatedTix = new Checkbox(); 530*7c478bd9Sstevel@tonic-gate allowForwardableTix = new Checkbox(); 531*7c478bd9Sstevel@tonic-gate allowRenewableTix = new Checkbox(); 532*7c478bd9Sstevel@tonic-gate allowProxiableTix = new Checkbox(); 533*7c478bd9Sstevel@tonic-gate allowServiceTix = new Checkbox(); 534*7c478bd9Sstevel@tonic-gate allowTGTAuth = new Checkbox(); 535*7c478bd9Sstevel@tonic-gate allowDupAuth = new Checkbox(); 536*7c478bd9Sstevel@tonic-gate requirePreauth = new Checkbox(); 537*7c478bd9Sstevel@tonic-gate requireHWAuth = new Checkbox(); 538*7c478bd9Sstevel@tonic-gate 539*7c478bd9Sstevel@tonic-gate addSeperatorPanel(getString("Security"), p); 540*7c478bd9Sstevel@tonic-gate 541*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 542*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 543*7c478bd9Sstevel@tonic-gate 544*7c478bd9Sstevel@tonic-gate addFlag(disableAccount, 545*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_ALL_TIX, p, gbc, false); 546*7c478bd9Sstevel@tonic-gate addFlag(forcePasswordChange, 547*7c478bd9Sstevel@tonic-gate Flags.REQUIRES_PWCHANGE, p, gbc, true); 548*7c478bd9Sstevel@tonic-gate 549*7c478bd9Sstevel@tonic-gate addSeperatorPanel(getString("Ticket"), p); 550*7c478bd9Sstevel@tonic-gate addFlag(allowPostdatedTix, 551*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_POSTDATED, p, gbc, false); 552*7c478bd9Sstevel@tonic-gate addFlag(allowForwardableTix, 553*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_FORWARDABLE, p, gbc, true); 554*7c478bd9Sstevel@tonic-gate addFlag(allowRenewableTix, 555*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_RENEWABLE, p, gbc, false); 556*7c478bd9Sstevel@tonic-gate addFlag(allowProxiableTix, 557*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_PROXIABLE, p, gbc, true); 558*7c478bd9Sstevel@tonic-gate addFlag(allowServiceTix, 559*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_SVR, p, gbc, true); 560*7c478bd9Sstevel@tonic-gate 561*7c478bd9Sstevel@tonic-gate addSeperatorPanel(getString("Miscellaneous"), p); 562*7c478bd9Sstevel@tonic-gate addFlag(allowTGTAuth, 563*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_TGT_BASED, p, gbc, false); 564*7c478bd9Sstevel@tonic-gate addFlag(allowDupAuth, 565*7c478bd9Sstevel@tonic-gate Flags.DISALLOW_DUP_SKEY, p, gbc, true); 566*7c478bd9Sstevel@tonic-gate addFlag(requirePreauth, 567*7c478bd9Sstevel@tonic-gate Flags.REQUIRE_PRE_AUTH, p, gbc, false); 568*7c478bd9Sstevel@tonic-gate addFlag(requireHWAuth, 569*7c478bd9Sstevel@tonic-gate Flags.REQUIRE_HW_AUTH, p, gbc, true); 570*7c478bd9Sstevel@tonic-gate } 571*7c478bd9Sstevel@tonic-gate 572*7c478bd9Sstevel@tonic-gate /** 573*7c478bd9Sstevel@tonic-gate * Helper method for addFlags. It adds a line seperator with text 574*7c478bd9Sstevel@tonic-gate * inside it. 575*7c478bd9Sstevel@tonic-gate * @param text the text to put in the line seperator 576*7c478bd9Sstevel@tonic-gate * @p the panel to which this line seperator must be added 577*7c478bd9Sstevel@tonic-gate */ addSeperatorPanel(String text, Panel p)578*7c478bd9Sstevel@tonic-gate private void addSeperatorPanel(String text, Panel p) { 579*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 580*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 581*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 582*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 583*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(7, 0, 7, 0); 584*7c478bd9Sstevel@tonic-gate 585*7c478bd9Sstevel@tonic-gate Panel subP = new Panel(); 586*7c478bd9Sstevel@tonic-gate // subP.setBackground(SEPERATOR_COLOR); 587*7c478bd9Sstevel@tonic-gate subP.setLayout(new GridBagLayout()); 588*7c478bd9Sstevel@tonic-gate p.add(subP, gbc); 589*7c478bd9Sstevel@tonic-gate 590*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 591*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 592*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = .02; 593*7c478bd9Sstevel@tonic-gate subP.add(new LineSeparator(), gbc); 594*7c478bd9Sstevel@tonic-gate 595*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = .001; 596*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.NONE; 597*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.EAST; 598*7c478bd9Sstevel@tonic-gate Label l = new Label(text); 599*7c478bd9Sstevel@tonic-gate l.setFont(new Font("Dialog", Font.ITALIC, 12)); 600*7c478bd9Sstevel@tonic-gate subP.add(l, gbc); 601*7c478bd9Sstevel@tonic-gate 602*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 603*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 604*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 605*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 606*7c478bd9Sstevel@tonic-gate subP.add(new LineSeparator(), gbc); 607*7c478bd9Sstevel@tonic-gate } 608*7c478bd9Sstevel@tonic-gate 609*7c478bd9Sstevel@tonic-gate /** 610*7c478bd9Sstevel@tonic-gate * Helper method for addFlags. It adds the label and the checkbox 611*7c478bd9Sstevel@tonic-gate * corresponding to the flag specified by the single bit that is set 612*7c478bd9Sstevel@tonic-gate * in mask. 613*7c478bd9Sstevel@tonic-gate * @param cb the Checkbox which has to be added corresponding to 614*7c478bd9Sstevel@tonic-gate * this flag 615*7c478bd9Sstevel@tonic-gate * @param mask the flag 616*7c478bd9Sstevel@tonic-gate * @param p the panel to add this to 617*7c478bd9Sstevel@tonic-gate */ addFlag(Checkbox cb, int mask, Panel p, GridBagConstraints gbc, boolean eol)618*7c478bd9Sstevel@tonic-gate private void addFlag(Checkbox cb, int mask, Panel p, 619*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc, boolean eol) { 620*7c478bd9Sstevel@tonic-gate // cb.setBackground(CHECKBOX_COLOR); 621*7c478bd9Sstevel@tonic-gate cb.setState(flags.getFlag(mask)); 622*7c478bd9Sstevel@tonic-gate cb.setLabel(Flags.getLabel(mask)); 623*7c478bd9Sstevel@tonic-gate if (eol) 624*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 625*7c478bd9Sstevel@tonic-gate else 626*7c478bd9Sstevel@tonic-gate gbc.gridwidth = 1; 627*7c478bd9Sstevel@tonic-gate p.add(cb, gbc); 628*7c478bd9Sstevel@tonic-gate } 629*7c478bd9Sstevel@tonic-gate 630*7c478bd9Sstevel@tonic-gate /** 631*7c478bd9Sstevel@tonic-gate * Helper method for constructor - adds Max ticket time, max renewal and def 632*7c478bd9Sstevel@tonic-gate * account expiry. 633*7c478bd9Sstevel@tonic-gate */ addTextFields()634*7c478bd9Sstevel@tonic-gate private void addTextFields() { 635*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 636*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 637*7c478bd9Sstevel@tonic-gate 638*7c478bd9Sstevel@tonic-gate Panel p = new Panel(); 639*7c478bd9Sstevel@tonic-gate // p.setBackground(PANEL_COLOR1); 640*7c478bd9Sstevel@tonic-gate p.setLayout(new GridBagLayout()); 641*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.VERTICAL; 642*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 643*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 644*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(0, 10, 0, 10); 645*7c478bd9Sstevel@tonic-gate add(p, gbc); 646*7c478bd9Sstevel@tonic-gate 647*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 648*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 649*7c478bd9Sstevel@tonic-gate 650*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.EAST; 651*7c478bd9Sstevel@tonic-gate gbc.weightx = 0; 652*7c478bd9Sstevel@tonic-gate gbc.gridx = 0; 653*7c478bd9Sstevel@tonic-gate gbc.gridy = 0; 654*7c478bd9Sstevel@tonic-gate accountExpiryDateLabel = new Label(getString("Account Expiry:")); 655*7c478bd9Sstevel@tonic-gate // accountExpiryDateLabel.setBackground(LABEL_COLOR); 656*7c478bd9Sstevel@tonic-gate p.add(accountExpiryDateLabel, gbc); 657*7c478bd9Sstevel@tonic-gate gbc.gridy = 2; 658*7c478bd9Sstevel@tonic-gate maxTicketLifeLabel = 659*7c478bd9Sstevel@tonic-gate new Label(getString("Maximum Ticket Lifetime (seconds):")); 660*7c478bd9Sstevel@tonic-gate // maxTicketLifeLabel.setBackground(LABEL_COLOR); 661*7c478bd9Sstevel@tonic-gate p.add(maxTicketLifeLabel, gbc); 662*7c478bd9Sstevel@tonic-gate gbc.gridy = 3; 663*7c478bd9Sstevel@tonic-gate maxTicketRenewableLifeLabel = 664*7c478bd9Sstevel@tonic-gate new Label(getString("Maximum Ticket Renewal (seconds):")); 665*7c478bd9Sstevel@tonic-gate // maxTicketRenewableLifeLabel.setBackground(LABEL_COLOR); 666*7c478bd9Sstevel@tonic-gate p.add(maxTicketRenewableLifeLabel, gbc); 667*7c478bd9Sstevel@tonic-gate 668*7c478bd9Sstevel@tonic-gate gbc.gridx = 1; 669*7c478bd9Sstevel@tonic-gate gbc.gridy = 0; 670*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.NONE; 671*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 672*7c478bd9Sstevel@tonic-gate accountExpiryDate = new TextField("1-Jan-70 00:00:00 PM"); 673*7c478bd9Sstevel@tonic-gate accountExpiryDate.setColumns(22); 674*7c478bd9Sstevel@tonic-gate p.add(accountExpiryDate, gbc); 675*7c478bd9Sstevel@tonic-gate gbc.gridy = 2; 676*7c478bd9Sstevel@tonic-gate maxTicketLife = new TextField("144000"); 677*7c478bd9Sstevel@tonic-gate maxTicketLife.setColumns(22); 678*7c478bd9Sstevel@tonic-gate p.add(maxTicketLife, gbc); 679*7c478bd9Sstevel@tonic-gate gbc.gridy = 3; 680*7c478bd9Sstevel@tonic-gate maxTicketRenewableLife = new TextField("144000"); 681*7c478bd9Sstevel@tonic-gate maxTicketRenewableLife.setColumns(22); 682*7c478bd9Sstevel@tonic-gate p.add(maxTicketRenewableLife, gbc); 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 685*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 0; 686*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 687*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 688*7c478bd9Sstevel@tonic-gate gbc.gridx = 2; 689*7c478bd9Sstevel@tonic-gate gbc.gridy = 0; 690*7c478bd9Sstevel@tonic-gate dateMoreButton = new Button("..."); 691*7c478bd9Sstevel@tonic-gate p.add(dateMoreButton, gbc); 692*7c478bd9Sstevel@tonic-gate gbc.gridy = 2; 693*7c478bd9Sstevel@tonic-gate lifeMoreButton = new Button("..."); 694*7c478bd9Sstevel@tonic-gate p.add(lifeMoreButton, gbc); 695*7c478bd9Sstevel@tonic-gate gbc.gridy = 3; 696*7c478bd9Sstevel@tonic-gate renewalMoreButton = new Button("..."); 697*7c478bd9Sstevel@tonic-gate p.add(renewalMoreButton, gbc); 698*7c478bd9Sstevel@tonic-gate 699*7c478bd9Sstevel@tonic-gate serverSide = new Checkbox(); 700*7c478bd9Sstevel@tonic-gate // serverSide.setBackground(CHECKBOX_COLOR); 701*7c478bd9Sstevel@tonic-gate serverSide.setLabel(getString( 702*7c478bd9Sstevel@tonic-gate "Let the KDC control the ticket lifetime values")); 703*7c478bd9Sstevel@tonic-gate 704*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 705*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 706*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 707*7c478bd9Sstevel@tonic-gate gbc.gridx = 0; 708*7c478bd9Sstevel@tonic-gate gbc.gridy = 1; 709*7c478bd9Sstevel@tonic-gate p.add(serverSide, gbc); 710*7c478bd9Sstevel@tonic-gate 711*7c478bd9Sstevel@tonic-gate } 712*7c478bd9Sstevel@tonic-gate addListFields()713*7c478bd9Sstevel@tonic-gate private void addListFields() { 714*7c478bd9Sstevel@tonic-gate Panel p = new Panel(); 715*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 716*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 717*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.VERTICAL; 718*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 719*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 720*7c478bd9Sstevel@tonic-gate // p.setBackground(PANEL_COLOR1); 721*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(0, 10, 0, 10); 722*7c478bd9Sstevel@tonic-gate p.setLayout(new GridBagLayout()); 723*7c478bd9Sstevel@tonic-gate add(p, gbc); 724*7c478bd9Sstevel@tonic-gate 725*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 726*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 727*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 728*7c478bd9Sstevel@tonic-gate showLists = new Checkbox(); 729*7c478bd9Sstevel@tonic-gate // showLists.setBackground(CHECKBOX_COLOR); 730*7c478bd9Sstevel@tonic-gate showLists.setLabel(getString("Show Lists")); 731*7c478bd9Sstevel@tonic-gate p.add(showLists, gbc); 732*7c478bd9Sstevel@tonic-gate 733*7c478bd9Sstevel@tonic-gate gbc.gridwidth = 1; 734*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.EAST; 735*7c478bd9Sstevel@tonic-gate staticLists = new Checkbox(); 736*7c478bd9Sstevel@tonic-gate // staticLists.setBackground(CHECKBOX_COLOR); 737*7c478bd9Sstevel@tonic-gate staticLists.setLabel(getString("Cache Lists Forever")); 738*7c478bd9Sstevel@tonic-gate p.add(staticLists, gbc); 739*7c478bd9Sstevel@tonic-gate 740*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.EAST; 741*7c478bd9Sstevel@tonic-gate cacheTimeLabel = new Label(getString("List Cache Timeout (seconds):")); 742*7c478bd9Sstevel@tonic-gate // cacheTimeLabel.setBackground(Color.green); 743*7c478bd9Sstevel@tonic-gate p.add(cacheTimeLabel, gbc); 744*7c478bd9Sstevel@tonic-gate 745*7c478bd9Sstevel@tonic-gate gbc.anchor = GridBagConstraints.WEST; 746*7c478bd9Sstevel@tonic-gate cacheTime = new TextField("300", 8); 747*7c478bd9Sstevel@tonic-gate // cacheTime.setBackground(Color.cyan); 748*7c478bd9Sstevel@tonic-gate p.add(cacheTime, gbc); 749*7c478bd9Sstevel@tonic-gate 750*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 751*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 0; 752*7c478bd9Sstevel@tonic-gate cacheMoreButton = new Button("..."); 753*7c478bd9Sstevel@tonic-gate p.add(cacheMoreButton, gbc); 754*7c478bd9Sstevel@tonic-gate } 755*7c478bd9Sstevel@tonic-gate 756*7c478bd9Sstevel@tonic-gate 757*7c478bd9Sstevel@tonic-gate /** 758*7c478bd9Sstevel@tonic-gate * Helper method for constructor - adds Save and Cancel 759*7c478bd9Sstevel@tonic-gate * buttons. 760*7c478bd9Sstevel@tonic-gate */ addButtons()761*7c478bd9Sstevel@tonic-gate private void addButtons() { 762*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 763*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 764*7c478bd9Sstevel@tonic-gate 765*7c478bd9Sstevel@tonic-gate Panel p = new Panel(); 766*7c478bd9Sstevel@tonic-gate p.setLayout(new GridBagLayout()); 767*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 768*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 769*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(10, 10, 10, 10); 770*7c478bd9Sstevel@tonic-gate add(new LineSeparator(), gbc); 771*7c478bd9Sstevel@tonic-gate gbc.insets = new Insets(0, 0, 10, 0); 772*7c478bd9Sstevel@tonic-gate add(p, gbc); 773*7c478bd9Sstevel@tonic-gate 774*7c478bd9Sstevel@tonic-gate gbc = new GridBagConstraints(); 775*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 776*7c478bd9Sstevel@tonic-gate 777*7c478bd9Sstevel@tonic-gate saveButton = new Button(getString("Save")); 778*7c478bd9Sstevel@tonic-gate p.add(saveButton, gbc); 779*7c478bd9Sstevel@tonic-gate applyButton = new Button(getString("Apply")); 780*7c478bd9Sstevel@tonic-gate p.add(applyButton, gbc); 781*7c478bd9Sstevel@tonic-gate cancelButton = new Button(getString("Cancel")); 782*7c478bd9Sstevel@tonic-gate p.add(cancelButton, gbc); 783*7c478bd9Sstevel@tonic-gate } 784*7c478bd9Sstevel@tonic-gate addHelpMenu()785*7c478bd9Sstevel@tonic-gate private void addHelpMenu() { 786*7c478bd9Sstevel@tonic-gate MenuBar mb = new MenuBar(); 787*7c478bd9Sstevel@tonic-gate setMenuBar(mb); 788*7c478bd9Sstevel@tonic-gate 789*7c478bd9Sstevel@tonic-gate Menu m = new Menu(getString("Help")); 790*7c478bd9Sstevel@tonic-gate mb.setHelpMenu(m); 791*7c478bd9Sstevel@tonic-gate 792*7c478bd9Sstevel@tonic-gate csHelp = new MenuItem(getString("Context-Sensitive Help")); 793*7c478bd9Sstevel@tonic-gate m.add(csHelp); 794*7c478bd9Sstevel@tonic-gate } 795*7c478bd9Sstevel@tonic-gate 796*7c478bd9Sstevel@tonic-gate /** 797*7c478bd9Sstevel@tonic-gate * Decides whether to save/discard edits and then closes 798*7c478bd9Sstevel@tonic-gate * window. If errors exist in the values entered in the fields, then 799*7c478bd9Sstevel@tonic-gate * it will not exit. 800*7c478bd9Sstevel@tonic-gate */ close(boolean save)801*7c478bd9Sstevel@tonic-gate public void close(boolean save) { 802*7c478bd9Sstevel@tonic-gate if (save) { 803*7c478bd9Sstevel@tonic-gate if (!Defaults.this.updateFromGui()) 804*7c478bd9Sstevel@tonic-gate return; 805*7c478bd9Sstevel@tonic-gate else 806*7c478bd9Sstevel@tonic-gate Defaults.this.saveToFile(); 807*7c478bd9Sstevel@tonic-gate } 808*7c478bd9Sstevel@tonic-gate setVisible(false); 809*7c478bd9Sstevel@tonic-gate } 810*7c478bd9Sstevel@tonic-gate 811*7c478bd9Sstevel@tonic-gate // Listeners for the gui components: 812*7c478bd9Sstevel@tonic-gate private class WindowCloseListener extends WindowAdapter { windowClosing(WindowEvent e)813*7c478bd9Sstevel@tonic-gate public void windowClosing(WindowEvent e) { 814*7c478bd9Sstevel@tonic-gate close(false); 815*7c478bd9Sstevel@tonic-gate } 816*7c478bd9Sstevel@tonic-gate } 817*7c478bd9Sstevel@tonic-gate 818*7c478bd9Sstevel@tonic-gate } // class EditingFrame 819*7c478bd9Sstevel@tonic-gate main(String argv[])820*7c478bd9Sstevel@tonic-gate public static void main(String argv[]) { 821*7c478bd9Sstevel@tonic-gate Defaults d = new Defaults("SomeFile", Color.white); 822*7c478bd9Sstevel@tonic-gate Frame f = d.getEditingFrame(); 823*7c478bd9Sstevel@tonic-gate d.showLists.setSize(new Dimension(18, 22)); 824*7c478bd9Sstevel@tonic-gate d.staticLists.setSize(new Dimension(18, 22)); 825*7c478bd9Sstevel@tonic-gate f.setVisible(true); 826*7c478bd9Sstevel@tonic-gate System.out.println(d.disableAccount.getSize().toString()); // XXX 827*7c478bd9Sstevel@tonic-gate System.out.println(d.showLists.getSize().toString()); // XXX 828*7c478bd9Sstevel@tonic-gate } 829*7c478bd9Sstevel@tonic-gate 830*7c478bd9Sstevel@tonic-gate static { 831*7c478bd9Sstevel@tonic-gate df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, 832*7c478bd9Sstevel@tonic-gate DateFormat.MEDIUM); 833*7c478bd9Sstevel@tonic-gate nf = NumberFormat.getInstance(); 834*7c478bd9Sstevel@tonic-gate rb = ResourceBundle.getBundle("GuiResource" /* NOI18N */); 835*7c478bd9Sstevel@tonic-gate neverString = getString("Never"); 836*7c478bd9Sstevel@tonic-gate } 837*7c478bd9Sstevel@tonic-gate 838*7c478bd9Sstevel@tonic-gate } 839