Defaults.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 1999-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/**
* Defaults class stores all defaults that are recorded locally on the
* client side. It is also resonsible for showing the DefaultsFrame
* which allows the user to see and change these values.
*/
public class Defaults {
// These gui components are the actual components that go on the editing frame
// that allows the user to change the defaults. The reason they are public is
// that they need to be accessible to KdcGui so that it can set up the
// listeners for them in setupDefaultsNormalListeners() and
// setupDefaultsHelpListeners().
public Checkbox disableAccount;
public Checkbox forcePasswordChange;
public Checkbox allowPostdatedTix;
public Checkbox allowForwardableTix;
public Checkbox allowRenewableTix;
public Checkbox allowProxiableTix;
public Checkbox allowServiceTix;
public Checkbox allowTGTAuth;
public Checkbox allowDupAuth;
public Checkbox requirePreauth;
public Checkbox requireHWAuth;
public Checkbox serverSide;
public TextField maxTicketLife;
public TextField maxTicketRenewableLife;
public TextField accountExpiryDate;
public Label maxTicketLifeLabel;
public Label maxTicketRenewableLifeLabel;
public Label accountExpiryDateLabel;
public Checkbox staticLists;
public Label cacheTimeLabel;
public Button lifeMoreButton;
public Button renewalMoreButton;
public Button dateMoreButton;
public Button cacheMoreButton;
public Button saveButton;
public Button applyButton;
public Button cancelButton;
// These data items correspond to fields in struct struct
// _kadm5_config_params
private boolean serverSideValue;
private int maxTicketLifeValue;
private int maxTicketRenewableLifeValue;
private Date accountExpiryDateValue;
private boolean showListsValue;
private boolean staticListsValue;
private long cacheTimeValue;
private String defaultsFile;
private Color background;
private boolean helpMode = false;
// For I18N
private static DateFormat df;
private static NumberFormat nf;
private static ResourceBundle rb;
// no help data since help is handled by KdcGui class
private static String neverString;
// For debugging the window arrangement
/**
* Constructor for Defaults.
* @param defaultsFile the file from which to read the defaults.
*/
this.defaultsFile = defaultsFile;
this.background = background;
serverSideValue = true;
maxTicketLifeValue = 144000;
maxTicketRenewableLifeValue = 144000;
// set expiry to now + one year
accountExpiryDateValue = c.getTime();
showListsValue = true;
staticListsValue = false;
cacheTimeValue = 300;
readFromFile();
}
/**
* Constructor for Defaults.
* @param old an existing defaults object to clone
*/
}
}
/**
* Returns a gui Frame with the defaults on it for editing.
*/
public Frame getEditingFrame() {
frame = new EditingFrame();
frame.setResizable(true);
}
return frame;
}
/**
* Reread the defaults file in case it has changed, and refresh view
*/
public void refreshDefaults() {
readFromFile();
}
/**
* Update the duration and date text fields from gui.
* Check to see if any one of them had a parse error.
* @return true if all is ok, false if an error occurs
*/
// Quits as soon as the first error is detected. The method that
// detects the error also shows a dialog box with a message.
public final boolean updateFromGui() {
return (setMaxTicketLife() && setMaxTicketRenewableLife()
&& setAccountExpiryDate() && setCacheTime());
}
boolean setServerSide() {
return true;
}
private void enableTicketLifeFields(boolean fromServer) {
}
boolean setMaxTicketLife() {
try {
} catch (ParseException e) {
return false;
}
return true;
}
/**
* Sets the maxTicketRenewable field value from the corresponding text
* field.
*/
boolean setMaxTicketRenewableLife() {
try {
} catch (ParseException e) {
return false;
}
return true;
}
/**
* Sets the accountExpiryDate field value from the corresponding text field.
*/
boolean setAccountExpiryDate() {
else {
try {
} catch (ParseException e) {
return false;
} catch (NullPointerException e) {
// gets thrown when parse string begins with text
// probable JDK bug
return false;
} catch (IndexOutOfBoundsException e) {
// gets thrown when parse string contains only one number
// probable JDK bug
return false;
}
}
return true;
}
/**
* Sets the cacheTime field value from the corresponding text field.
*/
boolean setCacheTime() {
try {
} catch (ParseException e) {
return false;
}
return true;
}
boolean setShowLists() {
return true;
}
boolean setStaticLists() {
return true;
}
private void enableCacheTimeFields(boolean staticLists) {
}
public boolean getServerSide() {
return serverSideValue;
}
public Integer getMaxTicketLife() {
return new Integer(maxTicketLifeValue);
}
public Integer getMaxTicketRenewableLife() {
return new Integer(maxTicketRenewableLifeValue);
}
public Date getAccountExpiryDate() {
}
public boolean getShowLists() {
return showListsValue;
}
public boolean getStaticLists() {
return staticListsValue;
}
public boolean getCacheLists() {
return staticListsValue;
}
public long getCacheTime() {
return cacheTimeValue;
}
return flags;
}
/**
* Toggles the value of the bit specified.
*/
public void toggleFlag(int bitmask) {
}
}
/**
* Saves the fields onto a file.
*/
private void saveToFile() {
try {
outFile = new PrintWriter(
} catch (IOException e) { /* xxx: warn user */ }
}
/**
* Reads the fields from a file.
*/
private void readFromFile() {
try {
String s;
if (s == null)
showListsValue = true;
else
if (s == null)
staticListsValue = false;
else
if (s == null)
cacheTimeValue = 300;
else try {
} catch (ParseException e) {
cacheTimeValue = 300;
}
} catch (FileNotFoundException e) {
/* default values. new file will be created automatically. */}
catch (IOException e) { /* will create new one */}
catch (ParseException e) { /* leave default values in */}
catch (NumberFormatException e) { /* leave default values in */}
catch (NullPointerException e) { /* leave default values in */}
catch (StringIndexOutOfBoundsException e) {
/* leave default values in */}
}
/**
* Sets the value of the gui components from the instance variables
* that get filled from the defaultsFile.
*/
public void updateGuiComponents() {
else {
updateFlags();
}
}
private void updateFlags() {
}
/**
* Call rb.getString(), but catch exception and return English
* key so that small spelling errors don't cripple the GUI
*
*/
try {
return res;
} catch (MissingResourceException e) {
return key;
}
}
/*
**********************************************
* I N N E R C L A S S E S
**********************************************
*/
private class EditingFrame extends Frame {
public EditingFrame() {
super(getString("Properties"));
setLayout(new GridBagLayout());
Label l;
// l.setBackground(LABEL_COLOR);
addFlags();
addButtons();
addWindowListener(new WindowCloseListener());
addHelpMenu();
}
/**
* Helper method for constructor to add checkboxes and labels for
* flags.
*/
private void addFlags() {
p.setLayout(new GridBagLayout());
disableAccount = new Checkbox();
forcePasswordChange = new Checkbox();
allowPostdatedTix = new Checkbox();
allowForwardableTix = new Checkbox();
allowRenewableTix = new Checkbox();
allowProxiableTix = new Checkbox();
allowServiceTix = new Checkbox();
allowTGTAuth = new Checkbox();
allowDupAuth = new Checkbox();
requirePreauth = new Checkbox();
requireHWAuth = new Checkbox();
gbc = new GridBagConstraints();
}
/**
* Helper method for addFlags. It adds a line seperator with text
* inside it.
* @param text the text to put in the line seperator
* @p the panel to which this line seperator must be added
*/
// subP.setBackground(SEPERATOR_COLOR);
gbc = new GridBagConstraints();
}
/**
* Helper method for addFlags. It adds the label and the checkbox
* corresponding to the flag specified by the single bit that is set
* in mask.
* @param cb the Checkbox which has to be added corresponding to
* this flag
* @param mask the flag
* @param p the panel to add this to
*/
// cb.setBackground(CHECKBOX_COLOR);
if (eol)
else
}
/**
* Helper method for constructor - adds Max ticket time, max renewal and def
* account expiry.
*/
private void addTextFields() {
// p.setBackground(PANEL_COLOR1);
p.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
// accountExpiryDateLabel.setBackground(LABEL_COLOR);
// maxTicketLifeLabel.setBackground(LABEL_COLOR);
// maxTicketRenewableLifeLabel.setBackground(LABEL_COLOR);
gbc = new GridBagConstraints();
serverSide = new Checkbox();
// serverSide.setBackground(CHECKBOX_COLOR);
"Let the KDC control the ticket lifetime values"));
gbc = new GridBagConstraints();
}
private void addListFields() {
// p.setBackground(PANEL_COLOR1);
p.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
// showLists.setBackground(CHECKBOX_COLOR);
staticLists = new Checkbox();
// staticLists.setBackground(CHECKBOX_COLOR);
// cacheTimeLabel.setBackground(Color.green);
// cacheTime.setBackground(Color.cyan);
}
/**
* Helper method for constructor - adds Save and Cancel
* buttons.
*/
private void addButtons() {
p.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
}
private void addHelpMenu() {
setMenuBar(mb);
mb.setHelpMenu(m);
}
/**
* window. If errors exist in the values entered in the fields, then
* it will not exit.
*/
if (save) {
if (!Defaults.this.updateFromGui())
return;
else
Defaults.this.saveToFile();
}
setVisible(false);
}
// Listeners for the gui components:
private class WindowCloseListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
close(false);
}
}
} // class EditingFrame
Frame f = d.getEditingFrame();
f.setVisible(true);
}
static {
}
}