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