xref: /titanic_41/usr/src/cmd/krb5/kadmin/gui/dataclasses/Principal.java (revision 45526e9775395f5d44bad3f5430041f32c84ce1e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * ident	"%Z%%M%	%I%	%E% SMI"
247c478bd9Sstevel@tonic-gate  *
25*45526e97Ssemery  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*45526e97Ssemery  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate import java.util.Date;
307c478bd9Sstevel@tonic-gate import java.text.DateFormat;
317c478bd9Sstevel@tonic-gate import java.text.NumberFormat;
327c478bd9Sstevel@tonic-gate import java.text.ParseException;
337c478bd9Sstevel@tonic-gate import java.util.Calendar;
347c478bd9Sstevel@tonic-gate import java.util.ResourceBundle;
357c478bd9Sstevel@tonic-gate import java.util.MissingResourceException;
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /**
387c478bd9Sstevel@tonic-gate  * Class representing a Kerberos V5 principal
397c478bd9Sstevel@tonic-gate  * Class data items correspond to fields in struct _kadm5_principal_ent_t_v2
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate class Principal {
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate     private static DateFormat df;
447c478bd9Sstevel@tonic-gate     private static NumberFormat nf;
457c478bd9Sstevel@tonic-gate     private static String neverString;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate     private static Integer INFINITE_LIFE = new Integer(Integer.MAX_VALUE);
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate     Flags flags;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate     // For I18N
527c478bd9Sstevel@tonic-gate     private static ResourceBundle rb;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate     String PrName;		// krb5_principal principal;
557c478bd9Sstevel@tonic-gate     Date PrExpireTime;		// krb5_timestamp princ_expire_time;
567c478bd9Sstevel@tonic-gate     String Policy;		// char *policy;
577c478bd9Sstevel@tonic-gate     Date LastPwChange;		// krb5_timestamp last_pwd_change;
587c478bd9Sstevel@tonic-gate     Date PwExpireTime;		// krb5_timestamp pw_expiration;
597c478bd9Sstevel@tonic-gate     Integer MaxLife;	        // krb5_deltat max_life;
607c478bd9Sstevel@tonic-gate     Integer MaxRenew;		// krb5_deltat max_renewable_life;
617c478bd9Sstevel@tonic-gate     Date ModTime;		// krb5_timestamp mod_date;
627c478bd9Sstevel@tonic-gate     String ModName;		// krb5_principal mod_name;
637c478bd9Sstevel@tonic-gate     Date LastSuccess;		// krb5_timestamp last_success;
647c478bd9Sstevel@tonic-gate     Date LastFailure;		// krb5_timestamp last_failed;
657c478bd9Sstevel@tonic-gate     Integer NumFailures;	// krb5_kvno fail_auth_count;
667c478bd9Sstevel@tonic-gate     String Comments;		// ==> entry in tl_data array
677c478bd9Sstevel@tonic-gate     Integer Kvno;		// krb5_kvno kvno;
687c478bd9Sstevel@tonic-gate     Integer Mkvno;		// krb5_kvno mkvno;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate     String PrPasswd;		// standalone field in Kadmin API
717c478bd9Sstevel@tonic-gate     Kadmin Kadmin;
727c478bd9Sstevel@tonic-gate     boolean isNew;		// newly created principal?
737c478bd9Sstevel@tonic-gate     boolean dummy;		// use dummy data?
747c478bd9Sstevel@tonic-gate     boolean newComments;	// are comments new or changed?
75*45526e97Ssemery     String EncTypes;		// enc type list to be used for key gen
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate     /**
787c478bd9Sstevel@tonic-gate      * Initialize new principal to defaults - this one is for new creations
797c478bd9Sstevel@tonic-gate      */
Principal()807c478bd9Sstevel@tonic-gate     public Principal() {
817c478bd9Sstevel@tonic-gate         isNew = true;
827c478bd9Sstevel@tonic-gate         dummy = true;
837c478bd9Sstevel@tonic-gate         newComments = false;
847c478bd9Sstevel@tonic-gate         PrName = new String("");
857c478bd9Sstevel@tonic-gate         PrPasswd = new String("");
867c478bd9Sstevel@tonic-gate         Calendar cal = Calendar.getInstance();
877c478bd9Sstevel@tonic-gate         cal.setTime(new Date());	    /* start with now ... */
887c478bd9Sstevel@tonic-gate         cal.add(Calendar.YEAR, 1);	    /* ... add a year ... XXX */
897c478bd9Sstevel@tonic-gate         PrExpireTime = cal.getTime();  /* ... to get expiry */
907c478bd9Sstevel@tonic-gate         Policy = new String("");
917c478bd9Sstevel@tonic-gate         LastPwChange = new Date(0);    /* never */
927c478bd9Sstevel@tonic-gate         PwExpireTime = null; // may be server side default
937c478bd9Sstevel@tonic-gate         MaxLife = null; // may be server side default
947c478bd9Sstevel@tonic-gate         MaxRenew = null; // may be server side default
957c478bd9Sstevel@tonic-gate         ModTime = new Date();	    /* now */
967c478bd9Sstevel@tonic-gate         ModName = System.getProperty("user.name");
977c478bd9Sstevel@tonic-gate         LastSuccess = new Date(0);	    /* never */
987c478bd9Sstevel@tonic-gate         LastFailure = new Date(0);	    /* never */
997c478bd9Sstevel@tonic-gate         NumFailures = new Integer(0);
1007c478bd9Sstevel@tonic-gate         Comments = new String("");
1017c478bd9Sstevel@tonic-gate         Kvno = new Integer(0);
1027c478bd9Sstevel@tonic-gate         Mkvno = new Integer(0);
1037c478bd9Sstevel@tonic-gate         flags = new Flags();
104*45526e97Ssemery 	EncTypes = new String("");
1057c478bd9Sstevel@tonic-gate     }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate     /*
1087c478bd9Sstevel@tonic-gate      * This is used for loading an existing principal
1097c478bd9Sstevel@tonic-gate      */
Principal(String Pname)1107c478bd9Sstevel@tonic-gate     public Principal(String Pname) {
1117c478bd9Sstevel@tonic-gate 	/* Get some specific data from somewhere */
1127c478bd9Sstevel@tonic-gate 	this();
1137c478bd9Sstevel@tonic-gate 	isNew = false;
1147c478bd9Sstevel@tonic-gate 	PrName = Pname;
1157c478bd9Sstevel@tonic-gate 	PwExpireTime = new Date(0);
1167c478bd9Sstevel@tonic-gate 	loadPrincipal(Pname);
1177c478bd9Sstevel@tonic-gate     }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate     /*
1207c478bd9Sstevel@tonic-gate      * This is used for duplicating a new principal from an old one
1217c478bd9Sstevel@tonic-gate      */
Principal(Principal old)1227c478bd9Sstevel@tonic-gate     public Principal(Principal old) {
1237c478bd9Sstevel@tonic-gate 	/* Copy old principal to new one */
1247c478bd9Sstevel@tonic-gate 	this();
1257c478bd9Sstevel@tonic-gate 	copyPrincipal(old, this);
1267c478bd9Sstevel@tonic-gate     }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate     /*
1297c478bd9Sstevel@tonic-gate      * For real data, use Kadmin as a first argument
1307c478bd9Sstevel@tonic-gate      */
Principal(Kadmin session, Defaults defaults)1317c478bd9Sstevel@tonic-gate     public Principal(Kadmin session, Defaults defaults) {
1327c478bd9Sstevel@tonic-gate 	this();
1337c478bd9Sstevel@tonic-gate 	dummy = false;
1347c478bd9Sstevel@tonic-gate 	Kadmin = session;
1357c478bd9Sstevel@tonic-gate 	setDefaults(defaults);
1367c478bd9Sstevel@tonic-gate     }
1377c478bd9Sstevel@tonic-gate 
Principal(Kadmin session, String Pname)1387c478bd9Sstevel@tonic-gate     public Principal(Kadmin session, String Pname) {
1397c478bd9Sstevel@tonic-gate 	this();
1407c478bd9Sstevel@tonic-gate 	isNew = false;
1417c478bd9Sstevel@tonic-gate 	dummy = false;
1427c478bd9Sstevel@tonic-gate 	Kadmin = session;
1437c478bd9Sstevel@tonic-gate 	PrName = Pname;
1447c478bd9Sstevel@tonic-gate 	PwExpireTime = new Date(0);
1457c478bd9Sstevel@tonic-gate 	loadPrincipal(Pname);
1467c478bd9Sstevel@tonic-gate     }
1477c478bd9Sstevel@tonic-gate 
Principal(Kadmin session, Principal old)1487c478bd9Sstevel@tonic-gate     public Principal(Kadmin session, Principal old) {
1497c478bd9Sstevel@tonic-gate 	this(old);
1507c478bd9Sstevel@tonic-gate 	dummy = false;
1517c478bd9Sstevel@tonic-gate 	Kadmin = session;
1527c478bd9Sstevel@tonic-gate     }
1537c478bd9Sstevel@tonic-gate 
setDefaults(Defaults defaults)1547c478bd9Sstevel@tonic-gate     public void setDefaults(Defaults defaults) {
1557c478bd9Sstevel@tonic-gate         flags = new Flags(defaults.getFlags().getBits());
1567c478bd9Sstevel@tonic-gate         if (!defaults.getServerSide()) {
1577c478bd9Sstevel@tonic-gate             MaxLife  = defaults.getMaxTicketLife();
1587c478bd9Sstevel@tonic-gate             MaxRenew = defaults.getMaxTicketRenewableLife();
1597c478bd9Sstevel@tonic-gate         }
1607c478bd9Sstevel@tonic-gate         PrExpireTime = defaults.getAccountExpiryDate();
1617c478bd9Sstevel@tonic-gate     }
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate     /**
1647c478bd9Sstevel@tonic-gate      * Copy relevant fields from old principal, overriding as necessary
1657c478bd9Sstevel@tonic-gate      */
copyPrincipal(Principal old, Principal curr)1667c478bd9Sstevel@tonic-gate     public static void copyPrincipal(Principal old, Principal curr) {
1677c478bd9Sstevel@tonic-gate 	curr.PrName = new String("");	    /* override */
1687c478bd9Sstevel@tonic-gate 	curr.PrPasswd = new String("");	    /* override */
1697c478bd9Sstevel@tonic-gate 	curr.PrExpireTime = new Date(old.PrExpireTime.getTime());
1707c478bd9Sstevel@tonic-gate 	curr.Policy = new String(old.Policy);
171*45526e97Ssemery 	curr.EncTypes = new String(old.EncTypes);
1727c478bd9Sstevel@tonic-gate 	curr.LastPwChange = new Date(0);    /* override: never */
1737c478bd9Sstevel@tonic-gate 	if (old.PwExpireTime == null)
1747c478bd9Sstevel@tonic-gate 	    curr.PwExpireTime = null;
1757c478bd9Sstevel@tonic-gate 	else
1767c478bd9Sstevel@tonic-gate 	    curr.PwExpireTime = new Date(old.PwExpireTime.getTime());
1777c478bd9Sstevel@tonic-gate 	curr.MaxLife = new Integer(old.MaxLife.intValue());
1787c478bd9Sstevel@tonic-gate 	curr.MaxRenew = new Integer(old.MaxRenew.intValue());
1797c478bd9Sstevel@tonic-gate 	curr.ModTime = new Date();	    /* override: now */
1807c478bd9Sstevel@tonic-gate 	curr.ModName = System.getProperty("user.name");	    /* override */
1817c478bd9Sstevel@tonic-gate 	curr.LastSuccess = new Date(0);	    /* override: never */
1827c478bd9Sstevel@tonic-gate 	curr.LastFailure = new Date(0);	    /* override: never */
1837c478bd9Sstevel@tonic-gate 	curr.NumFailures = new Integer(0);  /* override: none */
1847c478bd9Sstevel@tonic-gate 	curr.Comments = new String(old.Comments);
1857c478bd9Sstevel@tonic-gate 	curr.Kvno = new Integer(old.Kvno.intValue());
1867c478bd9Sstevel@tonic-gate 	curr.Mkvno = new Integer(old.Mkvno.intValue());
1877c478bd9Sstevel@tonic-gate 	curr.flags = new Flags(old.flags.getBits());
1887c478bd9Sstevel@tonic-gate     }
1897c478bd9Sstevel@tonic-gate 
loadPrincipal(String name)1907c478bd9Sstevel@tonic-gate     public boolean loadPrincipal(String name) {
1917c478bd9Sstevel@tonic-gate 	if (dummy)
1927c478bd9Sstevel@tonic-gate 		return true;
1937c478bd9Sstevel@tonic-gate 	boolean b = Kadmin.loadPrincipal(name, this);
1947c478bd9Sstevel@tonic-gate 	// System.out.println(this.toString());
1957c478bd9Sstevel@tonic-gate 	return b;
1967c478bd9Sstevel@tonic-gate     }
1977c478bd9Sstevel@tonic-gate 
savePrincipal()1987c478bd9Sstevel@tonic-gate     public boolean savePrincipal() {
1997c478bd9Sstevel@tonic-gate 	// System.out.println(this.toString());
2007c478bd9Sstevel@tonic-gate 	if (dummy)
2017c478bd9Sstevel@tonic-gate 		return true;
2027c478bd9Sstevel@tonic-gate 	if (MaxLife == null)
2037c478bd9Sstevel@tonic-gate 	  MaxLife = INFINITE_LIFE;
2047c478bd9Sstevel@tonic-gate 	if (MaxRenew == null)
2057c478bd9Sstevel@tonic-gate 	  MaxRenew = INFINITE_LIFE;
2067c478bd9Sstevel@tonic-gate 	if (this.isNew)
2077c478bd9Sstevel@tonic-gate 	    return Kadmin.createPrincipal(this);
2087c478bd9Sstevel@tonic-gate 	else
2097c478bd9Sstevel@tonic-gate 	    return Kadmin.savePrincipal(this);
2107c478bd9Sstevel@tonic-gate     }
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 
setName(String name)2137c478bd9Sstevel@tonic-gate     public boolean setName(String name) {
2147c478bd9Sstevel@tonic-gate 	// xxx: see where this gets called from to determine if a new Principal
2157c478bd9Sstevel@tonic-gate 	// just added can have a duplicate name or whether that would have been
2167c478bd9Sstevel@tonic-gate 	// screened out earlier.
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	PrName = name;
2197c478bd9Sstevel@tonic-gate 	return true;
2207c478bd9Sstevel@tonic-gate     }
2217c478bd9Sstevel@tonic-gate 
setComments(String comments)2227c478bd9Sstevel@tonic-gate     public boolean setComments(String comments) {
2237c478bd9Sstevel@tonic-gate 	  // xxx: check to see if all characters are in the allowable list of
2247c478bd9Sstevel@tonic-gate 	  // characters. The list needs to be I18N. No length restrictions on
2257c478bd9Sstevel@tonic-gate 	  // Java side but what about the c side?
2267c478bd9Sstevel@tonic-gate         Comments = comments;
2277c478bd9Sstevel@tonic-gate         newComments = true;
2287c478bd9Sstevel@tonic-gate         return true;
2297c478bd9Sstevel@tonic-gate     }
2307c478bd9Sstevel@tonic-gate 
setPolicy(String pol)2317c478bd9Sstevel@tonic-gate     public boolean setPolicy(String pol) {
2327c478bd9Sstevel@tonic-gate 	  // xxx: is this a valid policy name? Should we assume that error is
2337c478bd9Sstevel@tonic-gate 	  // already trapped before this point?
2347c478bd9Sstevel@tonic-gate 	Policy = pol;
2357c478bd9Sstevel@tonic-gate 	return true;
2367c478bd9Sstevel@tonic-gate     }
2377c478bd9Sstevel@tonic-gate 
setPassword(String pw)2387c478bd9Sstevel@tonic-gate     public boolean setPassword(String pw) {
2397c478bd9Sstevel@tonic-gate 	  // xxx: check to see if the passwd follows the rules laid down by
2407c478bd9Sstevel@tonic-gate 	  // the policy
2417c478bd9Sstevel@tonic-gate 	PrPasswd = pw;
2427c478bd9Sstevel@tonic-gate 	return true;
2437c478bd9Sstevel@tonic-gate     }
2447c478bd9Sstevel@tonic-gate 
setEncType(String enctype)245*45526e97Ssemery     public boolean setEncType(String enctype) {
246*45526e97Ssemery 	EncTypes = enctype;
247*45526e97Ssemery 	// Don't have to check enc type list provided given that list was
248*45526e97Ssemery 	// populated from the checkbox list
249*45526e97Ssemery 	return true;
250*45526e97Ssemery     }
251*45526e97Ssemery 
2527c478bd9Sstevel@tonic-gate     /**
2537c478bd9Sstevel@tonic-gate      * @param exp Contains a date formatted by the default locale,
2547c478bd9Sstevel@tonic-gate      * representing the expiry time for the principal's expiration.
2557c478bd9Sstevel@tonic-gate      */
setExpiry(String exp)2567c478bd9Sstevel@tonic-gate     public boolean setExpiry(String exp) {
2577c478bd9Sstevel@tonic-gate         exp = exp.trim();
2587c478bd9Sstevel@tonic-gate         if (exp.equalsIgnoreCase(neverString))
2597c478bd9Sstevel@tonic-gate            PrExpireTime = new Date(0);
2607c478bd9Sstevel@tonic-gate         else {
2617c478bd9Sstevel@tonic-gate             try {
2627c478bd9Sstevel@tonic-gate    	        PrExpireTime = df.parse(exp);
2637c478bd9Sstevel@tonic-gate             } catch (ParseException e) {
2647c478bd9Sstevel@tonic-gate 	        return false;
2657c478bd9Sstevel@tonic-gate             } catch (NullPointerException e) {
2667c478bd9Sstevel@tonic-gate 	        // gets thrown when parse string begins with text
2677c478bd9Sstevel@tonic-gate 	        // probable JDK bug
2687c478bd9Sstevel@tonic-gate 	        return false;
2697c478bd9Sstevel@tonic-gate             } catch (StringIndexOutOfBoundsException e) {
2707c478bd9Sstevel@tonic-gate 	        // gets thrown when parse string contains only one number
2717c478bd9Sstevel@tonic-gate 	        // probable JDK bug
2727c478bd9Sstevel@tonic-gate 	        return false;
2737c478bd9Sstevel@tonic-gate             }
2747c478bd9Sstevel@tonic-gate         }
2757c478bd9Sstevel@tonic-gate         return true;
2767c478bd9Sstevel@tonic-gate     }
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate     /**
2797c478bd9Sstevel@tonic-gate      * @param exp Contains a date formatted by the default locale,
2807c478bd9Sstevel@tonic-gate      * representing the expiry time for the password expiration.
2817c478bd9Sstevel@tonic-gate      */
setPwExpiry(String exp)2827c478bd9Sstevel@tonic-gate     public boolean setPwExpiry(String exp) {
2837c478bd9Sstevel@tonic-gate         exp = exp.trim();
2847c478bd9Sstevel@tonic-gate         if (exp.equals(""))
2857c478bd9Sstevel@tonic-gate             PwExpireTime = null;
2867c478bd9Sstevel@tonic-gate         else if (exp.equalsIgnoreCase(neverString))
2877c478bd9Sstevel@tonic-gate             PwExpireTime = new Date(0);
2887c478bd9Sstevel@tonic-gate         else {
2897c478bd9Sstevel@tonic-gate             try {
2907c478bd9Sstevel@tonic-gate     	        PwExpireTime = df.parse(exp);
2917c478bd9Sstevel@tonic-gate             } catch (ParseException e) {
2927c478bd9Sstevel@tonic-gate 	        return false;
2937c478bd9Sstevel@tonic-gate             } catch (NullPointerException e) {
2947c478bd9Sstevel@tonic-gate 	        // gets thrown when parse string begins with text
2957c478bd9Sstevel@tonic-gate 	        // probable JDK bug
2967c478bd9Sstevel@tonic-gate 	        return false;
2977c478bd9Sstevel@tonic-gate             }  catch (StringIndexOutOfBoundsException e) {
2987c478bd9Sstevel@tonic-gate 	        // gets thrown when parse string contains only one number
2997c478bd9Sstevel@tonic-gate 	        // probable JDK bug
3007c478bd9Sstevel@tonic-gate 	        return false;
3017c478bd9Sstevel@tonic-gate             }
3027c478bd9Sstevel@tonic-gate         }
3037c478bd9Sstevel@tonic-gate         return true;
3047c478bd9Sstevel@tonic-gate     }
3057c478bd9Sstevel@tonic-gate 
getModTime()3067c478bd9Sstevel@tonic-gate     public String getModTime() {
3077c478bd9Sstevel@tonic-gate         if (ModTime.getTime() == 0)
3087c478bd9Sstevel@tonic-gate             return neverString;
3097c478bd9Sstevel@tonic-gate         else
3107c478bd9Sstevel@tonic-gate             return df.format(ModTime);
3117c478bd9Sstevel@tonic-gate     }
3127c478bd9Sstevel@tonic-gate 
getEncType()313*45526e97Ssemery     public String getEncType() {
314*45526e97Ssemery             return EncTypes;
315*45526e97Ssemery     }
316*45526e97Ssemery 
getExpiry()3177c478bd9Sstevel@tonic-gate     public String getExpiry() {
3187c478bd9Sstevel@tonic-gate         if (PrExpireTime.getTime() == 0)
3197c478bd9Sstevel@tonic-gate             return neverString;
3207c478bd9Sstevel@tonic-gate         else
3217c478bd9Sstevel@tonic-gate             return df.format(PrExpireTime);
3227c478bd9Sstevel@tonic-gate     }
3237c478bd9Sstevel@tonic-gate 
getLastSuccess()3247c478bd9Sstevel@tonic-gate     public String getLastSuccess() {
3257c478bd9Sstevel@tonic-gate         if (LastSuccess.getTime() == 0)
3267c478bd9Sstevel@tonic-gate             return neverString;
3277c478bd9Sstevel@tonic-gate         else
3287c478bd9Sstevel@tonic-gate             return df.format(LastSuccess);
3297c478bd9Sstevel@tonic-gate     }
3307c478bd9Sstevel@tonic-gate 
getLastFailure()3317c478bd9Sstevel@tonic-gate     public String getLastFailure() {
3327c478bd9Sstevel@tonic-gate         if (LastFailure.getTime() == 0)
3337c478bd9Sstevel@tonic-gate             return neverString;
3347c478bd9Sstevel@tonic-gate         else
3357c478bd9Sstevel@tonic-gate             return df.format(LastFailure);
3367c478bd9Sstevel@tonic-gate     }
3377c478bd9Sstevel@tonic-gate 
getLastPwChange()3387c478bd9Sstevel@tonic-gate     public String getLastPwChange() {
3397c478bd9Sstevel@tonic-gate         if (LastPwChange.getTime() == 0)
3407c478bd9Sstevel@tonic-gate             return neverString;
3417c478bd9Sstevel@tonic-gate         else
3427c478bd9Sstevel@tonic-gate             return df.format(LastPwChange);
3437c478bd9Sstevel@tonic-gate     }
3447c478bd9Sstevel@tonic-gate 
getPwExpireTime()3457c478bd9Sstevel@tonic-gate     public String getPwExpireTime() {
3467c478bd9Sstevel@tonic-gate         if (PwExpireTime == null)
3477c478bd9Sstevel@tonic-gate             return new String("");
3487c478bd9Sstevel@tonic-gate         else if (PwExpireTime.getTime() == 0)
3497c478bd9Sstevel@tonic-gate             return neverString;
3507c478bd9Sstevel@tonic-gate         else
3517c478bd9Sstevel@tonic-gate             return df.format(PwExpireTime);
3527c478bd9Sstevel@tonic-gate     }
3537c478bd9Sstevel@tonic-gate 
getMaxLife()3547c478bd9Sstevel@tonic-gate     public String getMaxLife() {
3557c478bd9Sstevel@tonic-gate         if (MaxLife != null)
3567c478bd9Sstevel@tonic-gate             return nf.format(MaxLife.longValue());
3577c478bd9Sstevel@tonic-gate         else
3587c478bd9Sstevel@tonic-gate             return "";
3597c478bd9Sstevel@tonic-gate     }
3607c478bd9Sstevel@tonic-gate 
getMaxRenew()3617c478bd9Sstevel@tonic-gate     public String getMaxRenew() {
3627c478bd9Sstevel@tonic-gate         if (MaxRenew != null)
3637c478bd9Sstevel@tonic-gate             return nf.format(MaxRenew.longValue());
3647c478bd9Sstevel@tonic-gate         else
3657c478bd9Sstevel@tonic-gate             return "";
3667c478bd9Sstevel@tonic-gate     }
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate     /**
3697c478bd9Sstevel@tonic-gate      * @param vers Contains a number representing the key version.
3707c478bd9Sstevel@tonic-gate      */
setKvno(String vers)3717c478bd9Sstevel@tonic-gate     public boolean setKvno(String vers) {
3727c478bd9Sstevel@tonic-gate 	try {
3737c478bd9Sstevel@tonic-gate 	    Kvno = new Integer(nf.parse(vers.trim()).intValue());
3747c478bd9Sstevel@tonic-gate 	}catch (ParseException e) {
3757c478bd9Sstevel@tonic-gate 	    return false;
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate 	return true;
3787c478bd9Sstevel@tonic-gate     }
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate     /**
3817c478bd9Sstevel@tonic-gate      * @param val Contains a number representing the maximum lifetime, in
3827c478bd9Sstevel@tonic-gate      * seconds, of a ticket for this principal.
3837c478bd9Sstevel@tonic-gate      */
setMaxlife(String val)3847c478bd9Sstevel@tonic-gate     public boolean setMaxlife(String val) {
3857c478bd9Sstevel@tonic-gate 	try {
3867c478bd9Sstevel@tonic-gate 	    String noSpace = val.trim();
3877c478bd9Sstevel@tonic-gate 	    if (noSpace.length() == 0)
3887c478bd9Sstevel@tonic-gate 	        return true;
3897c478bd9Sstevel@tonic-gate 	    MaxLife = new Integer(nf.parse(noSpace).intValue());
3907c478bd9Sstevel@tonic-gate 	}catch (ParseException e) {
3917c478bd9Sstevel@tonic-gate 	    return false;
3927c478bd9Sstevel@tonic-gate 	}
3937c478bd9Sstevel@tonic-gate 	return true;
3947c478bd9Sstevel@tonic-gate     }
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate     /**
3977c478bd9Sstevel@tonic-gate      * @param val Contains a number representing the maximum renewable lifetime,
3987c478bd9Sstevel@tonic-gate      * in seconds, of a ticket for this principal.
3997c478bd9Sstevel@tonic-gate      */
setMaxrenew(String val)4007c478bd9Sstevel@tonic-gate     public boolean setMaxrenew(String val) {
4017c478bd9Sstevel@tonic-gate 	try {
4027c478bd9Sstevel@tonic-gate 	    String noSpace = val.trim();
4037c478bd9Sstevel@tonic-gate 	    if (noSpace.length() == 0)
4047c478bd9Sstevel@tonic-gate 	        return true;
4057c478bd9Sstevel@tonic-gate 	    MaxRenew = new Integer(nf.parse(noSpace).intValue());
4067c478bd9Sstevel@tonic-gate 	}catch (ParseException e) {
4077c478bd9Sstevel@tonic-gate 	    return false;
4087c478bd9Sstevel@tonic-gate 	}
4097c478bd9Sstevel@tonic-gate 	return true;
4107c478bd9Sstevel@tonic-gate     }
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate     /**
4137c478bd9Sstevel@tonic-gate      * Toggles a particular flag.
4147c478bd9Sstevel@tonic-gate      * @param mask one of the statically defined masks indicating which flag to
4157c478bd9Sstevel@tonic-gate      * toggle.
4167c478bd9Sstevel@tonic-gate      */
setFlag(int mask)4177c478bd9Sstevel@tonic-gate     public boolean setFlag(int mask) {
4187c478bd9Sstevel@tonic-gate         flags.toggleFlags(mask);
4197c478bd9Sstevel@tonic-gate         return true;
4207c478bd9Sstevel@tonic-gate     }
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate     /**
4237c478bd9Sstevel@tonic-gate      * Obtain a string representation of this principal.
4247c478bd9Sstevel@tonic-gate      * @return a String containing the following information about this
4257c478bd9Sstevel@tonic-gate      * principal:<br>
4267c478bd9Sstevel@tonic-gate      * <ul>
4277c478bd9Sstevel@tonic-gate      * <li>principal name
4287c478bd9Sstevel@tonic-gate      *<li>policy being applied
4297c478bd9Sstevel@tonic-gate      *<li>expiry date
4307c478bd9Sstevel@tonic-gate      *<li>comments
4317c478bd9Sstevel@tonic-gate      *<li>key version number
4327c478bd9Sstevel@tonic-gate      *<li>password expire time
4337c478bd9Sstevel@tonic-gate      *<li>maximum lifetime
4347c478bd9Sstevel@tonic-gate      *<li>maximum renewable lifetime
4357c478bd9Sstevel@tonic-gate      * <li> flags
4367c478bd9Sstevel@tonic-gate      *</ul>
4377c478bd9Sstevel@tonic-gate      */
toString()4387c478bd9Sstevel@tonic-gate     public String toString() {
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate         StringBuffer sb = new StringBuffer();
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate         sb.append(getString("Principal Name:") + "  " + PrName).append('\n');
4437c478bd9Sstevel@tonic-gate         sb.append(getString("Account Expires:") + "  "
4447c478bd9Sstevel@tonic-gate               + getExpiry()).append('\n');
4457c478bd9Sstevel@tonic-gate         sb.append(getString("Policy:") + "  " + Policy).append('\n');
446*45526e97Ssemery         sb.append(getString("Enc Types:") + "  " + EncTypes).append('\n');
4477c478bd9Sstevel@tonic-gate         sb.append(getString("Comments:") + "  " + Comments).append('\n');
4487c478bd9Sstevel@tonic-gate         sb.append(getString("Key Version:") + "	" + Kvno).append('\t');
4497c478bd9Sstevel@tonic-gate         sb.append(getString("Password Expires:") + "  "
4507c478bd9Sstevel@tonic-gate               + getPwExpireTime()).append('\n');
4517c478bd9Sstevel@tonic-gate         sb.append(getString("Maximum Lifetime (seconds):")
4527c478bd9Sstevel@tonic-gate 	      + "	 " + getMaxLife()).append('\t');
4537c478bd9Sstevel@tonic-gate         sb.append(getString("Maximum Renewal (seconds):")
4547c478bd9Sstevel@tonic-gate 	      + "	 " + getMaxRenew()).append('\n');
4557c478bd9Sstevel@tonic-gate         sb.append(getString("Flags:")).append('\n').append(flags.toString());
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate         return sb.toString();
4587c478bd9Sstevel@tonic-gate     }
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate     /**
4617c478bd9Sstevel@tonic-gate      * Call rb.getString(), but catch exception and return English
4627c478bd9Sstevel@tonic-gate      * key so that small spelling errors don't cripple the GUI
4637c478bd9Sstevel@tonic-gate      *
4647c478bd9Sstevel@tonic-gate      */
getString(String key)4657c478bd9Sstevel@tonic-gate     private static final String getString(String key) {
4667c478bd9Sstevel@tonic-gate         try {
4677c478bd9Sstevel@tonic-gate     	    String res = rb.getString(key);
4687c478bd9Sstevel@tonic-gate 	    return res;
4697c478bd9Sstevel@tonic-gate         } catch (MissingResourceException e) {
4707c478bd9Sstevel@tonic-gate 	    System.out.println("Missing resource "+key+", using English.");
4717c478bd9Sstevel@tonic-gate 	    return key;
4727c478bd9Sstevel@tonic-gate         }
4737c478bd9Sstevel@tonic-gate     }
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate     static {
4767c478bd9Sstevel@tonic-gate         rb = ResourceBundle.getBundle("GuiResource" /* NOI18N */);
4777c478bd9Sstevel@tonic-gate         df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
4787c478bd9Sstevel@tonic-gate                                             DateFormat.MEDIUM);
4797c478bd9Sstevel@tonic-gate         nf = NumberFormat.getInstance();
4807c478bd9Sstevel@tonic-gate         neverString = getString("Never");
4817c478bd9Sstevel@tonic-gate     }
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate }
484