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.util.ResourceBundle; 30*7c478bd9Sstevel@tonic-gate import java.text.NumberFormat; 31*7c478bd9Sstevel@tonic-gate import java.text.ParseException; 32*7c478bd9Sstevel@tonic-gate import java.util.MissingResourceException; 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate /** 35*7c478bd9Sstevel@tonic-gate * Class representing a Kerberos V5 policy 36*7c478bd9Sstevel@tonic-gate * Class data items correspond to fields in struct _kadm5_policy_ent_t 37*7c478bd9Sstevel@tonic-gate */ 38*7c478bd9Sstevel@tonic-gate class Policy { 39*7c478bd9Sstevel@tonic-gate String PolicyName; // char *policy; 40*7c478bd9Sstevel@tonic-gate Integer PwMinLife; // long pw_min_life; 41*7c478bd9Sstevel@tonic-gate Integer PwMaxLife; // long pw_max_life; 42*7c478bd9Sstevel@tonic-gate Integer PwMinLength; // long pw_min_length; 43*7c478bd9Sstevel@tonic-gate Integer PwMinClasses; // long pw_min_classes; 44*7c478bd9Sstevel@tonic-gate Integer PwSaveCount; // long pw_history_num; 45*7c478bd9Sstevel@tonic-gate Integer RefCount; // long policy_refcnt; 46*7c478bd9Sstevel@tonic-gate Kadmin Kadmin; 47*7c478bd9Sstevel@tonic-gate boolean isNew; 48*7c478bd9Sstevel@tonic-gate boolean dummy; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate // For I18N 51*7c478bd9Sstevel@tonic-gate private static ResourceBundle rb = 52*7c478bd9Sstevel@tonic-gate ResourceBundle.getBundle("GuiResource" /* NOI18N */); 53*7c478bd9Sstevel@tonic-gate private static NumberFormat nf = NumberFormat.getInstance(); 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /** 56*7c478bd9Sstevel@tonic-gate * Initialize new policy to defaults - this one is for new creations 57*7c478bd9Sstevel@tonic-gate */ Policy()58*7c478bd9Sstevel@tonic-gate public Policy() { 59*7c478bd9Sstevel@tonic-gate dummy = true; 60*7c478bd9Sstevel@tonic-gate isNew = true; 61*7c478bd9Sstevel@tonic-gate PolicyName = new String(""); 62*7c478bd9Sstevel@tonic-gate PwMinLife = new Integer(0); 63*7c478bd9Sstevel@tonic-gate PwMaxLife = new Integer(30 * 24 * 60 * 60); /* 30 days */ 64*7c478bd9Sstevel@tonic-gate PwMinLength = new Integer(4); 65*7c478bd9Sstevel@tonic-gate PwMinClasses = new Integer(2); 66*7c478bd9Sstevel@tonic-gate PwSaveCount = new Integer(3); 67*7c478bd9Sstevel@tonic-gate RefCount = new Integer(0); 68*7c478bd9Sstevel@tonic-gate } 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * This is used for loading an existing principal 72*7c478bd9Sstevel@tonic-gate */ Policy(String Pname)73*7c478bd9Sstevel@tonic-gate public Policy(String Pname) { 74*7c478bd9Sstevel@tonic-gate /* Get some specific data from somewhere */ 75*7c478bd9Sstevel@tonic-gate this(); 76*7c478bd9Sstevel@tonic-gate dummy = true; 77*7c478bd9Sstevel@tonic-gate isNew = false; 78*7c478bd9Sstevel@tonic-gate PolicyName = Pname; 79*7c478bd9Sstevel@tonic-gate loadPolicy(Pname); 80*7c478bd9Sstevel@tonic-gate } 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * This is used for duplicating a new principal from an old one 84*7c478bd9Sstevel@tonic-gate */ Policy(Policy old)85*7c478bd9Sstevel@tonic-gate public Policy(Policy old) { 86*7c478bd9Sstevel@tonic-gate /* Copy old principal to new one */ 87*7c478bd9Sstevel@tonic-gate this(); 88*7c478bd9Sstevel@tonic-gate dummy = true; 89*7c478bd9Sstevel@tonic-gate copyPolicy(old, this); 90*7c478bd9Sstevel@tonic-gate } 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate /* 93*7c478bd9Sstevel@tonic-gate * For real data, use Kadmin as a first argument 94*7c478bd9Sstevel@tonic-gate */ Policy(Kadmin session)95*7c478bd9Sstevel@tonic-gate public Policy(Kadmin session) { 96*7c478bd9Sstevel@tonic-gate this(); 97*7c478bd9Sstevel@tonic-gate dummy = false; 98*7c478bd9Sstevel@tonic-gate Kadmin = session; 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate Policy(Kadmin session, String Pname)101*7c478bd9Sstevel@tonic-gate public Policy(Kadmin session, String Pname) { 102*7c478bd9Sstevel@tonic-gate this(); 103*7c478bd9Sstevel@tonic-gate isNew = false; 104*7c478bd9Sstevel@tonic-gate dummy = false; 105*7c478bd9Sstevel@tonic-gate Kadmin = session; 106*7c478bd9Sstevel@tonic-gate PolicyName = Pname; 107*7c478bd9Sstevel@tonic-gate loadPolicy(Pname); 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate Policy(Kadmin session, Policy old)110*7c478bd9Sstevel@tonic-gate public Policy(Kadmin session, Policy old) { 111*7c478bd9Sstevel@tonic-gate this(old); 112*7c478bd9Sstevel@tonic-gate dummy = false; 113*7c478bd9Sstevel@tonic-gate Kadmin = session; 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /** 117*7c478bd9Sstevel@tonic-gate * Copy relevant fields from old policy, overriding as necessary 118*7c478bd9Sstevel@tonic-gate */ copyPolicy(Policy old, Policy curr)119*7c478bd9Sstevel@tonic-gate public void copyPolicy(Policy old, Policy curr) { 120*7c478bd9Sstevel@tonic-gate curr.PolicyName = new String(""); /* override */ 121*7c478bd9Sstevel@tonic-gate curr.PwMinLife = new Integer(old.PwMinLife.intValue()); 122*7c478bd9Sstevel@tonic-gate curr.PwMaxLife = new Integer(old.PwMaxLife.intValue()); 123*7c478bd9Sstevel@tonic-gate curr.PwMinLength = new Integer(old.PwMinLength.intValue()); 124*7c478bd9Sstevel@tonic-gate curr.PwMinClasses = new Integer(old.PwMinClasses.intValue()); 125*7c478bd9Sstevel@tonic-gate curr.PwSaveCount = new Integer(old.PwSaveCount.intValue()); 126*7c478bd9Sstevel@tonic-gate curr.RefCount = new Integer(0); /* override */ 127*7c478bd9Sstevel@tonic-gate } 128*7c478bd9Sstevel@tonic-gate loadPolicy(String name)129*7c478bd9Sstevel@tonic-gate public boolean loadPolicy(String name) { 130*7c478bd9Sstevel@tonic-gate if (dummy) 131*7c478bd9Sstevel@tonic-gate return true; 132*7c478bd9Sstevel@tonic-gate boolean b = Kadmin.loadPolicy(name, this); 133*7c478bd9Sstevel@tonic-gate // System.out.println(this.toString()); 134*7c478bd9Sstevel@tonic-gate return b; 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate savePolicy()137*7c478bd9Sstevel@tonic-gate public boolean savePolicy() { 138*7c478bd9Sstevel@tonic-gate // System.out.println(this.toString()); 139*7c478bd9Sstevel@tonic-gate if (dummy) 140*7c478bd9Sstevel@tonic-gate return true; 141*7c478bd9Sstevel@tonic-gate if (this.isNew) 142*7c478bd9Sstevel@tonic-gate return Kadmin.createPolicy(this); 143*7c478bd9Sstevel@tonic-gate else 144*7c478bd9Sstevel@tonic-gate return Kadmin.savePolicy(this); 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate setName(String name)147*7c478bd9Sstevel@tonic-gate public boolean setName(String name) { 148*7c478bd9Sstevel@tonic-gate // xxx: see where this gets called from to determine if a new Policy 149*7c478bd9Sstevel@tonic-gate // just added can have a duplicate name or whether that would have 150*7c478bd9Sstevel@tonic-gate // been screened out earlier. 151*7c478bd9Sstevel@tonic-gate PolicyName = name; 152*7c478bd9Sstevel@tonic-gate return true; 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate /** 156*7c478bd9Sstevel@tonic-gate * @param val Contains one number representing the length. 157*7c478bd9Sstevel@tonic-gate */ setPolPwLength(String val)158*7c478bd9Sstevel@tonic-gate public boolean setPolPwLength(String val) { 159*7c478bd9Sstevel@tonic-gate try { 160*7c478bd9Sstevel@tonic-gate PwMinLength = new Integer(nf.parse(val).intValue()); 161*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 162*7c478bd9Sstevel@tonic-gate return false; 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate return true; 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate /** 168*7c478bd9Sstevel@tonic-gate * @param val Contains one number representing the number of classes 169*7c478bd9Sstevel@tonic-gate */ setPolPwClasses(String val)170*7c478bd9Sstevel@tonic-gate public boolean setPolPwClasses(String val) { 171*7c478bd9Sstevel@tonic-gate try { 172*7c478bd9Sstevel@tonic-gate PwMinClasses = new Integer(nf.parse(val).intValue()); 173*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 174*7c478bd9Sstevel@tonic-gate return false; 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate return true; 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate /** 180*7c478bd9Sstevel@tonic-gate * @param val Contains one number representing the save count. 181*7c478bd9Sstevel@tonic-gate */ setPolPwHistory(String val)182*7c478bd9Sstevel@tonic-gate public boolean setPolPwHistory(String val) { 183*7c478bd9Sstevel@tonic-gate // xxx: Is pwHistory the same as pwSaveCount? 184*7c478bd9Sstevel@tonic-gate try { 185*7c478bd9Sstevel@tonic-gate PwSaveCount = new Integer(nf.parse(val).intValue()); 186*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 187*7c478bd9Sstevel@tonic-gate return false; 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate return true; 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate /** 193*7c478bd9Sstevel@tonic-gate * @param val Contains one number representing the lifetime in seconds. 194*7c478bd9Sstevel@tonic-gate */ setPolMinlife(String val)195*7c478bd9Sstevel@tonic-gate public boolean setPolMinlife(String val) { 196*7c478bd9Sstevel@tonic-gate try { 197*7c478bd9Sstevel@tonic-gate PwMinLife = new Integer(nf.parse(val.trim()).intValue()); 198*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 199*7c478bd9Sstevel@tonic-gate return false; 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate return true; 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /** 205*7c478bd9Sstevel@tonic-gate * @param val Contains one number representing the lifetime in seconds. 206*7c478bd9Sstevel@tonic-gate */ setPolMaxlife(String val)207*7c478bd9Sstevel@tonic-gate public boolean setPolMaxlife(String val) { 208*7c478bd9Sstevel@tonic-gate try { 209*7c478bd9Sstevel@tonic-gate PwMaxLife = new Integer(nf.parse(val.trim()).intValue()); 210*7c478bd9Sstevel@tonic-gate } catch (ParseException e) { 211*7c478bd9Sstevel@tonic-gate return false; 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate return true; 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate /* 217*7c478bd9Sstevel@tonic-gate * Obtain a string representation of this policy. 218*7c478bd9Sstevel@tonic-gate * @return a String containing the following information about this policy: 219*7c478bd9Sstevel@tonic-gate * <br><ul> 220*7c478bd9Sstevel@tonic-gate * <li>policy name 221*7c478bd9Sstevel@tonic-gate * <li>password minimum life 222*7c478bd9Sstevel@tonic-gate * <li>password maximum life 223*7c478bd9Sstevel@tonic-gate * <li>password minimum length 224*7c478bd9Sstevel@tonic-gate * <li>password minimum classes 225*7c478bd9Sstevel@tonic-gate * <li>password save count 226*7c478bd9Sstevel@tonic-gate * <li>reference count 227*7c478bd9Sstevel@tonic-gate *</ul> 228*7c478bd9Sstevel@tonic-gate */ toString()229*7c478bd9Sstevel@tonic-gate public String toString() { 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate StringBuffer sb = new StringBuffer(); 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate sb.append(getString("Policy Name:") + " " + PolicyName).append('\n'); 234*7c478bd9Sstevel@tonic-gate sb.append(getString("Reference Count:") + " " 235*7c478bd9Sstevel@tonic-gate + RefCount).append("\n"); 236*7c478bd9Sstevel@tonic-gate sb.append(getString("Minimum Password Lifetime (seconds):") 237*7c478bd9Sstevel@tonic-gate + " " + PwMinLife).append("\t"); 238*7c478bd9Sstevel@tonic-gate sb.append(getString("Maximum Password Lifetime (seconds):") 239*7c478bd9Sstevel@tonic-gate + " " + PwMaxLife).append("\n"); 240*7c478bd9Sstevel@tonic-gate sb.append(getString("Minimum Password Length:") + " " 241*7c478bd9Sstevel@tonic-gate + PwMinLength).append("\t"); 242*7c478bd9Sstevel@tonic-gate sb.append(getString("Minimum Password Classes:") + " " 243*7c478bd9Sstevel@tonic-gate + PwMinClasses).append("\n"); 244*7c478bd9Sstevel@tonic-gate sb.append(getString("Password Save Count:") + " " 245*7c478bd9Sstevel@tonic-gate + PwSaveCount).append("\n"); 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate return sb.toString(); 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate /** 251*7c478bd9Sstevel@tonic-gate * Call rb.getString(), but catch exception and return English 252*7c478bd9Sstevel@tonic-gate * key so that small spelling errors don't cripple the GUI 253*7c478bd9Sstevel@tonic-gate * 254*7c478bd9Sstevel@tonic-gate */ getString(String key)255*7c478bd9Sstevel@tonic-gate private static final String getString(String key) { 256*7c478bd9Sstevel@tonic-gate try { 257*7c478bd9Sstevel@tonic-gate String res = rb.getString(key); 258*7c478bd9Sstevel@tonic-gate return res; 259*7c478bd9Sstevel@tonic-gate } catch (MissingResourceException e) { 260*7c478bd9Sstevel@tonic-gate System.out.println("Missing resource "+key+", using English."); 261*7c478bd9Sstevel@tonic-gate return key; 262*7c478bd9Sstevel@tonic-gate } 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate } 266