10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * ident "%Z%%M% %I% %E% SMI" 240Sstevel@tonic-gate * 25*96Ssemery * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26*96Ssemery * Use is subject to license terms. 270Sstevel@tonic-gate */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate import java.util.Date; 300Sstevel@tonic-gate import java.text.DateFormat; 310Sstevel@tonic-gate import java.text.NumberFormat; 320Sstevel@tonic-gate import java.text.ParseException; 330Sstevel@tonic-gate import java.util.Calendar; 340Sstevel@tonic-gate import java.util.ResourceBundle; 350Sstevel@tonic-gate import java.util.MissingResourceException; 360Sstevel@tonic-gate 370Sstevel@tonic-gate /** 380Sstevel@tonic-gate * Class representing a Kerberos V5 principal 390Sstevel@tonic-gate * Class data items correspond to fields in struct _kadm5_principal_ent_t_v2 400Sstevel@tonic-gate */ 410Sstevel@tonic-gate class Principal { 420Sstevel@tonic-gate 430Sstevel@tonic-gate private static DateFormat df; 440Sstevel@tonic-gate private static NumberFormat nf; 450Sstevel@tonic-gate private static String neverString; 460Sstevel@tonic-gate 470Sstevel@tonic-gate private static Integer INFINITE_LIFE = new Integer(Integer.MAX_VALUE); 480Sstevel@tonic-gate 490Sstevel@tonic-gate Flags flags; 500Sstevel@tonic-gate 510Sstevel@tonic-gate // For I18N 520Sstevel@tonic-gate private static ResourceBundle rb; 530Sstevel@tonic-gate 540Sstevel@tonic-gate String PrName; // krb5_principal principal; 550Sstevel@tonic-gate Date PrExpireTime; // krb5_timestamp princ_expire_time; 560Sstevel@tonic-gate String Policy; // char *policy; 570Sstevel@tonic-gate Date LastPwChange; // krb5_timestamp last_pwd_change; 580Sstevel@tonic-gate Date PwExpireTime; // krb5_timestamp pw_expiration; 590Sstevel@tonic-gate Integer MaxLife; // krb5_deltat max_life; 600Sstevel@tonic-gate Integer MaxRenew; // krb5_deltat max_renewable_life; 610Sstevel@tonic-gate Date ModTime; // krb5_timestamp mod_date; 620Sstevel@tonic-gate String ModName; // krb5_principal mod_name; 630Sstevel@tonic-gate Date LastSuccess; // krb5_timestamp last_success; 640Sstevel@tonic-gate Date LastFailure; // krb5_timestamp last_failed; 650Sstevel@tonic-gate Integer NumFailures; // krb5_kvno fail_auth_count; 660Sstevel@tonic-gate String Comments; // ==> entry in tl_data array 670Sstevel@tonic-gate Integer Kvno; // krb5_kvno kvno; 680Sstevel@tonic-gate Integer Mkvno; // krb5_kvno mkvno; 690Sstevel@tonic-gate 700Sstevel@tonic-gate String PrPasswd; // standalone field in Kadmin API 710Sstevel@tonic-gate Kadmin Kadmin; 720Sstevel@tonic-gate boolean isNew; // newly created principal? 730Sstevel@tonic-gate boolean dummy; // use dummy data? 740Sstevel@tonic-gate boolean newComments; // are comments new or changed? 75*96Ssemery String EncTypes; // enc type list to be used for key gen 760Sstevel@tonic-gate 770Sstevel@tonic-gate /** 780Sstevel@tonic-gate * Initialize new principal to defaults - this one is for new creations 790Sstevel@tonic-gate */ Principal()800Sstevel@tonic-gate public Principal() { 810Sstevel@tonic-gate isNew = true; 820Sstevel@tonic-gate dummy = true; 830Sstevel@tonic-gate newComments = false; 840Sstevel@tonic-gate PrName = new String(""); 850Sstevel@tonic-gate PrPasswd = new String(""); 860Sstevel@tonic-gate Calendar cal = Calendar.getInstance(); 870Sstevel@tonic-gate cal.setTime(new Date()); /* start with now ... */ 880Sstevel@tonic-gate cal.add(Calendar.YEAR, 1); /* ... add a year ... XXX */ 890Sstevel@tonic-gate PrExpireTime = cal.getTime(); /* ... to get expiry */ 900Sstevel@tonic-gate Policy = new String(""); 910Sstevel@tonic-gate LastPwChange = new Date(0); /* never */ 920Sstevel@tonic-gate PwExpireTime = null; // may be server side default 930Sstevel@tonic-gate MaxLife = null; // may be server side default 940Sstevel@tonic-gate MaxRenew = null; // may be server side default 950Sstevel@tonic-gate ModTime = new Date(); /* now */ 960Sstevel@tonic-gate ModName = System.getProperty("user.name"); 970Sstevel@tonic-gate LastSuccess = new Date(0); /* never */ 980Sstevel@tonic-gate LastFailure = new Date(0); /* never */ 990Sstevel@tonic-gate NumFailures = new Integer(0); 1000Sstevel@tonic-gate Comments = new String(""); 1010Sstevel@tonic-gate Kvno = new Integer(0); 1020Sstevel@tonic-gate Mkvno = new Integer(0); 1030Sstevel@tonic-gate flags = new Flags(); 104*96Ssemery EncTypes = new String(""); 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * This is used for loading an existing principal 1090Sstevel@tonic-gate */ Principal(String Pname)1100Sstevel@tonic-gate public Principal(String Pname) { 1110Sstevel@tonic-gate /* Get some specific data from somewhere */ 1120Sstevel@tonic-gate this(); 1130Sstevel@tonic-gate isNew = false; 1140Sstevel@tonic-gate PrName = Pname; 1150Sstevel@tonic-gate PwExpireTime = new Date(0); 1160Sstevel@tonic-gate loadPrincipal(Pname); 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /* 1200Sstevel@tonic-gate * This is used for duplicating a new principal from an old one 1210Sstevel@tonic-gate */ Principal(Principal old)1220Sstevel@tonic-gate public Principal(Principal old) { 1230Sstevel@tonic-gate /* Copy old principal to new one */ 1240Sstevel@tonic-gate this(); 1250Sstevel@tonic-gate copyPrincipal(old, this); 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * For real data, use Kadmin as a first argument 1300Sstevel@tonic-gate */ Principal(Kadmin session, Defaults defaults)1310Sstevel@tonic-gate public Principal(Kadmin session, Defaults defaults) { 1320Sstevel@tonic-gate this(); 1330Sstevel@tonic-gate dummy = false; 1340Sstevel@tonic-gate Kadmin = session; 1350Sstevel@tonic-gate setDefaults(defaults); 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate Principal(Kadmin session, String Pname)1380Sstevel@tonic-gate public Principal(Kadmin session, String Pname) { 1390Sstevel@tonic-gate this(); 1400Sstevel@tonic-gate isNew = false; 1410Sstevel@tonic-gate dummy = false; 1420Sstevel@tonic-gate Kadmin = session; 1430Sstevel@tonic-gate PrName = Pname; 1440Sstevel@tonic-gate PwExpireTime = new Date(0); 1450Sstevel@tonic-gate loadPrincipal(Pname); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate Principal(Kadmin session, Principal old)1480Sstevel@tonic-gate public Principal(Kadmin session, Principal old) { 1490Sstevel@tonic-gate this(old); 1500Sstevel@tonic-gate dummy = false; 1510Sstevel@tonic-gate Kadmin = session; 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate setDefaults(Defaults defaults)1540Sstevel@tonic-gate public void setDefaults(Defaults defaults) { 1550Sstevel@tonic-gate flags = new Flags(defaults.getFlags().getBits()); 1560Sstevel@tonic-gate if (!defaults.getServerSide()) { 1570Sstevel@tonic-gate MaxLife = defaults.getMaxTicketLife(); 1580Sstevel@tonic-gate MaxRenew = defaults.getMaxTicketRenewableLife(); 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate PrExpireTime = defaults.getAccountExpiryDate(); 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /** 1640Sstevel@tonic-gate * Copy relevant fields from old principal, overriding as necessary 1650Sstevel@tonic-gate */ copyPrincipal(Principal old, Principal curr)1660Sstevel@tonic-gate public static void copyPrincipal(Principal old, Principal curr) { 1670Sstevel@tonic-gate curr.PrName = new String(""); /* override */ 1680Sstevel@tonic-gate curr.PrPasswd = new String(""); /* override */ 1690Sstevel@tonic-gate curr.PrExpireTime = new Date(old.PrExpireTime.getTime()); 1700Sstevel@tonic-gate curr.Policy = new String(old.Policy); 171*96Ssemery curr.EncTypes = new String(old.EncTypes); 1720Sstevel@tonic-gate curr.LastPwChange = new Date(0); /* override: never */ 1730Sstevel@tonic-gate if (old.PwExpireTime == null) 1740Sstevel@tonic-gate curr.PwExpireTime = null; 1750Sstevel@tonic-gate else 1760Sstevel@tonic-gate curr.PwExpireTime = new Date(old.PwExpireTime.getTime()); 1770Sstevel@tonic-gate curr.MaxLife = new Integer(old.MaxLife.intValue()); 1780Sstevel@tonic-gate curr.MaxRenew = new Integer(old.MaxRenew.intValue()); 1790Sstevel@tonic-gate curr.ModTime = new Date(); /* override: now */ 1800Sstevel@tonic-gate curr.ModName = System.getProperty("user.name"); /* override */ 1810Sstevel@tonic-gate curr.LastSuccess = new Date(0); /* override: never */ 1820Sstevel@tonic-gate curr.LastFailure = new Date(0); /* override: never */ 1830Sstevel@tonic-gate curr.NumFailures = new Integer(0); /* override: none */ 1840Sstevel@tonic-gate curr.Comments = new String(old.Comments); 1850Sstevel@tonic-gate curr.Kvno = new Integer(old.Kvno.intValue()); 1860Sstevel@tonic-gate curr.Mkvno = new Integer(old.Mkvno.intValue()); 1870Sstevel@tonic-gate curr.flags = new Flags(old.flags.getBits()); 1880Sstevel@tonic-gate } 1890Sstevel@tonic-gate loadPrincipal(String name)1900Sstevel@tonic-gate public boolean loadPrincipal(String name) { 1910Sstevel@tonic-gate if (dummy) 1920Sstevel@tonic-gate return true; 1930Sstevel@tonic-gate boolean b = Kadmin.loadPrincipal(name, this); 1940Sstevel@tonic-gate // System.out.println(this.toString()); 1950Sstevel@tonic-gate return b; 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate savePrincipal()1980Sstevel@tonic-gate public boolean savePrincipal() { 1990Sstevel@tonic-gate // System.out.println(this.toString()); 2000Sstevel@tonic-gate if (dummy) 2010Sstevel@tonic-gate return true; 2020Sstevel@tonic-gate if (MaxLife == null) 2030Sstevel@tonic-gate MaxLife = INFINITE_LIFE; 2040Sstevel@tonic-gate if (MaxRenew == null) 2050Sstevel@tonic-gate MaxRenew = INFINITE_LIFE; 2060Sstevel@tonic-gate if (this.isNew) 2070Sstevel@tonic-gate return Kadmin.createPrincipal(this); 2080Sstevel@tonic-gate else 2090Sstevel@tonic-gate return Kadmin.savePrincipal(this); 2100Sstevel@tonic-gate } 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate setName(String name)2130Sstevel@tonic-gate public boolean setName(String name) { 2140Sstevel@tonic-gate // xxx: see where this gets called from to determine if a new Principal 2150Sstevel@tonic-gate // just added can have a duplicate name or whether that would have been 2160Sstevel@tonic-gate // screened out earlier. 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate PrName = name; 2190Sstevel@tonic-gate return true; 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate setComments(String comments)2220Sstevel@tonic-gate public boolean setComments(String comments) { 2230Sstevel@tonic-gate // xxx: check to see if all characters are in the allowable list of 2240Sstevel@tonic-gate // characters. The list needs to be I18N. No length restrictions on 2250Sstevel@tonic-gate // Java side but what about the c side? 2260Sstevel@tonic-gate Comments = comments; 2270Sstevel@tonic-gate newComments = true; 2280Sstevel@tonic-gate return true; 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate setPolicy(String pol)2310Sstevel@tonic-gate public boolean setPolicy(String pol) { 2320Sstevel@tonic-gate // xxx: is this a valid policy name? Should we assume that error is 2330Sstevel@tonic-gate // already trapped before this point? 2340Sstevel@tonic-gate Policy = pol; 2350Sstevel@tonic-gate return true; 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate setPassword(String pw)2380Sstevel@tonic-gate public boolean setPassword(String pw) { 2390Sstevel@tonic-gate // xxx: check to see if the passwd follows the rules laid down by 2400Sstevel@tonic-gate // the policy 2410Sstevel@tonic-gate PrPasswd = pw; 2420Sstevel@tonic-gate return true; 2430Sstevel@tonic-gate } 244*96Ssemery setEncType(String enctype)245*96Ssemery public boolean setEncType(String enctype) { 246*96Ssemery EncTypes = enctype; 247*96Ssemery // Don't have to check enc type list provided given that list was 248*96Ssemery // populated from the checkbox list 249*96Ssemery return true; 250*96Ssemery } 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate /** 2530Sstevel@tonic-gate * @param exp Contains a date formatted by the default locale, 2540Sstevel@tonic-gate * representing the expiry time for the principal's expiration. 2550Sstevel@tonic-gate */ setExpiry(String exp)2560Sstevel@tonic-gate public boolean setExpiry(String exp) { 2570Sstevel@tonic-gate exp = exp.trim(); 2580Sstevel@tonic-gate if (exp.equalsIgnoreCase(neverString)) 2590Sstevel@tonic-gate PrExpireTime = new Date(0); 2600Sstevel@tonic-gate else { 2610Sstevel@tonic-gate try { 2620Sstevel@tonic-gate PrExpireTime = df.parse(exp); 2630Sstevel@tonic-gate } catch (ParseException e) { 2640Sstevel@tonic-gate return false; 2650Sstevel@tonic-gate } catch (NullPointerException e) { 2660Sstevel@tonic-gate // gets thrown when parse string begins with text 2670Sstevel@tonic-gate // probable JDK bug 2680Sstevel@tonic-gate return false; 2690Sstevel@tonic-gate } catch (StringIndexOutOfBoundsException e) { 2700Sstevel@tonic-gate // gets thrown when parse string contains only one number 2710Sstevel@tonic-gate // probable JDK bug 2720Sstevel@tonic-gate return false; 2730Sstevel@tonic-gate } 2740Sstevel@tonic-gate } 2750Sstevel@tonic-gate return true; 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /** 2790Sstevel@tonic-gate * @param exp Contains a date formatted by the default locale, 2800Sstevel@tonic-gate * representing the expiry time for the password expiration. 2810Sstevel@tonic-gate */ setPwExpiry(String exp)2820Sstevel@tonic-gate public boolean setPwExpiry(String exp) { 2830Sstevel@tonic-gate exp = exp.trim(); 2840Sstevel@tonic-gate if (exp.equals("")) 2850Sstevel@tonic-gate PwExpireTime = null; 2860Sstevel@tonic-gate else if (exp.equalsIgnoreCase(neverString)) 2870Sstevel@tonic-gate PwExpireTime = new Date(0); 2880Sstevel@tonic-gate else { 2890Sstevel@tonic-gate try { 2900Sstevel@tonic-gate PwExpireTime = df.parse(exp); 2910Sstevel@tonic-gate } catch (ParseException e) { 2920Sstevel@tonic-gate return false; 2930Sstevel@tonic-gate } catch (NullPointerException e) { 2940Sstevel@tonic-gate // gets thrown when parse string begins with text 2950Sstevel@tonic-gate // probable JDK bug 2960Sstevel@tonic-gate return false; 2970Sstevel@tonic-gate } catch (StringIndexOutOfBoundsException e) { 2980Sstevel@tonic-gate // gets thrown when parse string contains only one number 2990Sstevel@tonic-gate // probable JDK bug 3000Sstevel@tonic-gate return false; 3010Sstevel@tonic-gate } 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate return true; 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate getModTime()3060Sstevel@tonic-gate public String getModTime() { 3070Sstevel@tonic-gate if (ModTime.getTime() == 0) 3080Sstevel@tonic-gate return neverString; 3090Sstevel@tonic-gate else 3100Sstevel@tonic-gate return df.format(ModTime); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate getEncType()313*96Ssemery public String getEncType() { 314*96Ssemery return EncTypes; 315*96Ssemery } 316*96Ssemery getExpiry()3170Sstevel@tonic-gate public String getExpiry() { 3180Sstevel@tonic-gate if (PrExpireTime.getTime() == 0) 3190Sstevel@tonic-gate return neverString; 3200Sstevel@tonic-gate else 3210Sstevel@tonic-gate return df.format(PrExpireTime); 3220Sstevel@tonic-gate } 3230Sstevel@tonic-gate getLastSuccess()3240Sstevel@tonic-gate public String getLastSuccess() { 3250Sstevel@tonic-gate if (LastSuccess.getTime() == 0) 3260Sstevel@tonic-gate return neverString; 3270Sstevel@tonic-gate else 3280Sstevel@tonic-gate return df.format(LastSuccess); 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate getLastFailure()3310Sstevel@tonic-gate public String getLastFailure() { 3320Sstevel@tonic-gate if (LastFailure.getTime() == 0) 3330Sstevel@tonic-gate return neverString; 3340Sstevel@tonic-gate else 3350Sstevel@tonic-gate return df.format(LastFailure); 3360Sstevel@tonic-gate } 3370Sstevel@tonic-gate getLastPwChange()3380Sstevel@tonic-gate public String getLastPwChange() { 3390Sstevel@tonic-gate if (LastPwChange.getTime() == 0) 3400Sstevel@tonic-gate return neverString; 3410Sstevel@tonic-gate else 3420Sstevel@tonic-gate return df.format(LastPwChange); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate getPwExpireTime()3450Sstevel@tonic-gate public String getPwExpireTime() { 3460Sstevel@tonic-gate if (PwExpireTime == null) 3470Sstevel@tonic-gate return new String(""); 3480Sstevel@tonic-gate else if (PwExpireTime.getTime() == 0) 3490Sstevel@tonic-gate return neverString; 3500Sstevel@tonic-gate else 3510Sstevel@tonic-gate return df.format(PwExpireTime); 3520Sstevel@tonic-gate } 3530Sstevel@tonic-gate getMaxLife()3540Sstevel@tonic-gate public String getMaxLife() { 3550Sstevel@tonic-gate if (MaxLife != null) 3560Sstevel@tonic-gate return nf.format(MaxLife.longValue()); 3570Sstevel@tonic-gate else 3580Sstevel@tonic-gate return ""; 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate getMaxRenew()3610Sstevel@tonic-gate public String getMaxRenew() { 3620Sstevel@tonic-gate if (MaxRenew != null) 3630Sstevel@tonic-gate return nf.format(MaxRenew.longValue()); 3640Sstevel@tonic-gate else 3650Sstevel@tonic-gate return ""; 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /** 3690Sstevel@tonic-gate * @param vers Contains a number representing the key version. 3700Sstevel@tonic-gate */ setKvno(String vers)3710Sstevel@tonic-gate public boolean setKvno(String vers) { 3720Sstevel@tonic-gate try { 3730Sstevel@tonic-gate Kvno = new Integer(nf.parse(vers.trim()).intValue()); 3740Sstevel@tonic-gate }catch (ParseException e) { 3750Sstevel@tonic-gate return false; 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate return true; 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate /** 3810Sstevel@tonic-gate * @param val Contains a number representing the maximum lifetime, in 3820Sstevel@tonic-gate * seconds, of a ticket for this principal. 3830Sstevel@tonic-gate */ setMaxlife(String val)3840Sstevel@tonic-gate public boolean setMaxlife(String val) { 3850Sstevel@tonic-gate try { 3860Sstevel@tonic-gate String noSpace = val.trim(); 3870Sstevel@tonic-gate if (noSpace.length() == 0) 3880Sstevel@tonic-gate return true; 3890Sstevel@tonic-gate MaxLife = new Integer(nf.parse(noSpace).intValue()); 3900Sstevel@tonic-gate }catch (ParseException e) { 3910Sstevel@tonic-gate return false; 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate return true; 3940Sstevel@tonic-gate } 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /** 3970Sstevel@tonic-gate * @param val Contains a number representing the maximum renewable lifetime, 3980Sstevel@tonic-gate * in seconds, of a ticket for this principal. 3990Sstevel@tonic-gate */ setMaxrenew(String val)4000Sstevel@tonic-gate public boolean setMaxrenew(String val) { 4010Sstevel@tonic-gate try { 4020Sstevel@tonic-gate String noSpace = val.trim(); 4030Sstevel@tonic-gate if (noSpace.length() == 0) 4040Sstevel@tonic-gate return true; 4050Sstevel@tonic-gate MaxRenew = new Integer(nf.parse(noSpace).intValue()); 4060Sstevel@tonic-gate }catch (ParseException e) { 4070Sstevel@tonic-gate return false; 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate return true; 4100Sstevel@tonic-gate } 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate /** 4130Sstevel@tonic-gate * Toggles a particular flag. 4140Sstevel@tonic-gate * @param mask one of the statically defined masks indicating which flag to 4150Sstevel@tonic-gate * toggle. 4160Sstevel@tonic-gate */ setFlag(int mask)4170Sstevel@tonic-gate public boolean setFlag(int mask) { 4180Sstevel@tonic-gate flags.toggleFlags(mask); 4190Sstevel@tonic-gate return true; 4200Sstevel@tonic-gate } 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /** 4230Sstevel@tonic-gate * Obtain a string representation of this principal. 4240Sstevel@tonic-gate * @return a String containing the following information about this 4250Sstevel@tonic-gate * principal:<br> 4260Sstevel@tonic-gate * <ul> 4270Sstevel@tonic-gate * <li>principal name 4280Sstevel@tonic-gate *<li>policy being applied 4290Sstevel@tonic-gate *<li>expiry date 4300Sstevel@tonic-gate *<li>comments 4310Sstevel@tonic-gate *<li>key version number 4320Sstevel@tonic-gate *<li>password expire time 4330Sstevel@tonic-gate *<li>maximum lifetime 4340Sstevel@tonic-gate *<li>maximum renewable lifetime 4350Sstevel@tonic-gate * <li> flags 4360Sstevel@tonic-gate *</ul> 4370Sstevel@tonic-gate */ toString()4380Sstevel@tonic-gate public String toString() { 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate StringBuffer sb = new StringBuffer(); 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate sb.append(getString("Principal Name:") + " " + PrName).append('\n'); 4430Sstevel@tonic-gate sb.append(getString("Account Expires:") + " " 4440Sstevel@tonic-gate + getExpiry()).append('\n'); 4450Sstevel@tonic-gate sb.append(getString("Policy:") + " " + Policy).append('\n'); 446*96Ssemery sb.append(getString("Enc Types:") + " " + EncTypes).append('\n'); 4470Sstevel@tonic-gate sb.append(getString("Comments:") + " " + Comments).append('\n'); 4480Sstevel@tonic-gate sb.append(getString("Key Version:") + " " + Kvno).append('\t'); 4490Sstevel@tonic-gate sb.append(getString("Password Expires:") + " " 4500Sstevel@tonic-gate + getPwExpireTime()).append('\n'); 4510Sstevel@tonic-gate sb.append(getString("Maximum Lifetime (seconds):") 4520Sstevel@tonic-gate + " " + getMaxLife()).append('\t'); 4530Sstevel@tonic-gate sb.append(getString("Maximum Renewal (seconds):") 4540Sstevel@tonic-gate + " " + getMaxRenew()).append('\n'); 4550Sstevel@tonic-gate sb.append(getString("Flags:")).append('\n').append(flags.toString()); 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate return sb.toString(); 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate /** 4610Sstevel@tonic-gate * Call rb.getString(), but catch exception and return English 4620Sstevel@tonic-gate * key so that small spelling errors don't cripple the GUI 4630Sstevel@tonic-gate * 4640Sstevel@tonic-gate */ getString(String key)4650Sstevel@tonic-gate private static final String getString(String key) { 4660Sstevel@tonic-gate try { 4670Sstevel@tonic-gate String res = rb.getString(key); 4680Sstevel@tonic-gate return res; 4690Sstevel@tonic-gate } catch (MissingResourceException e) { 4700Sstevel@tonic-gate System.out.println("Missing resource "+key+", using English."); 4710Sstevel@tonic-gate return key; 4720Sstevel@tonic-gate } 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate static { 4760Sstevel@tonic-gate rb = ResourceBundle.getBundle("GuiResource" /* NOI18N */); 4770Sstevel@tonic-gate df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, 4780Sstevel@tonic-gate DateFormat.MEDIUM); 4790Sstevel@tonic-gate nf = NumberFormat.getInstance(); 4800Sstevel@tonic-gate neverString = getString("Never"); 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate } 484