1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * ident	"%Z%%M%	%I%	%E% SMI"
24  *
25  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28 
29 //
30 // Class to hold a principal list
31 //
32 
33 import java.util.Vector;
34 import java.util.StringTokenizer;
35 import java.util.Date;
36 
37 public class PrincipalList {
38     Kadmin Kadmin = null;
39     boolean dummy;
40     /*
41      * Dummy data for testing
42      */
43     String [] dummyPL = { "first", "eisler", "hooshang", "lin", "msaltz",
44 			"rammarti", "thurlow", "traj", "seemam",
45 			"eisler/admin", "lin/admin", "msaltz/admin",
46 			"thurlow/admin", "george", "scott", "steve",
47 			"carrie", "jennifer", "penny", "lisa",
48 			"lobby1", "lobby2", "janitor", "rentacop1",
49 			"rentacop2" };
50 
PrincipalList()51     public PrincipalList() {
52 	dummy = true;
53     }
54 
PrincipalList(Kadmin session)55     public PrincipalList(Kadmin session) {
56         dummy = false;
57         Kadmin = session;
58     }
59 
getPrincipalList()60     public String[] getPrincipalList() {
61 	String[] in;
62 
63 	// Date pdateBefore = new Date();
64 	if (dummy) {
65 	    in = new String[dummyPL.length];
66 	    System.arraycopy(dummyPL, 0, in, 0, dummyPL.length);
67 	} else {
68 	    // in = Kadmin.getPrincipalList();
69 	    String prs = Kadmin.getPrincipalList2();
70 	    StringTokenizer t = new StringTokenizer(prs);
71 	    in = new String[t.countTokens()];
72 	    for (int i = 0; t.hasMoreTokens(); i++)
73 		in[i] = t.nextToken();
74 	}
75 	// Date pdateAfter = new Date();
76 	// long diff = pdateAfter.getTime() - pdateBefore.getTime();
77 	// String s = (new Long(diff)).toString();
78 	// System.out.println("  Fetched list from server in "+s+" ms");
79 	return in;
80     }
81 
getPrincipalList(String realm)82     public String[] getPrincipalList(String realm) {
83 	String[] in = getPrincipalList();
84 	for (int i = 0; i < in.length; i++) {
85 	    String s = in[i];
86 	    int x = s.lastIndexOf("@"+realm);
87 	    if (x > 0)
88 		in[i] = new String(s.substring(0, x));
89 	}
90 	return in;
91     }
92 
93 
main(String[] args)94     public static void main(String[] args) {
95 	PrincipalList p = new PrincipalList();
96 	String[] pl = p.getPrincipalList("");
97 	System.out.println("Principal List:");
98 	for (int i = 0; i < pl.length; i++)
99 	    System.out.println("  "+pl[i]);
100     }
101 }
102