KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ra > UsernameGeneratorParams


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.core.model.ra;
15
16 import java.util.Arrays JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.ejbca.util.passgen.PasswordGeneratorFactory;
20
21 /** Parameters used in UsernameGenerator
22  *
23  * @author tomas
24  * @version $Id: UsernameGeneratorParams.java,v 1.2 2006/09/25 12:54:59 anatom Exp $
25  * @see UsernameGenerator
26  */

27 public class UsernameGeneratorParams {
28
29     /** Create a completely random username */
30     protected static final int MODE_RANDOM = 0;
31     /** Use the input as the base username */
32     protected static final int MODE_USERNAME = 1;
33     /** Use a part of the DN as pase username */
34     protected static final int MODE_DN = 2;
35
36     public static final String JavaDoc RANDOM = "RANDOM";
37     public static final String JavaDoc USERNAME = "USERNAME";
38     public static final String JavaDoc DN = "DN";
39     
40     private String JavaDoc[] modes = {"RANDOM", "USERNAME", "DN"};
41     private List JavaDoc modeList = null;
42
43     // Generator configuration parameters, with good default values
44
private int mode = MODE_RANDOM;
45     private int randomNameLength = 12;
46     private int randomGeneratorType = PasswordGeneratorFactory.PASSWORDTYPE_LETTERSANDDIGITS;
47     private String JavaDoc dNGeneratorComponent = "CN"; // Can be CN or UID
48
private String JavaDoc prefix = null;
49     private String JavaDoc postfix = null;
50     private int randomPrefixLength = 12;
51     
52     public UsernameGeneratorParams() {
53         // all defautl values
54
}
55     
56     public String JavaDoc getDNGeneratorComponent() {
57         return dNGeneratorComponent;
58     }
59     public void setDNGeneratorComponent(String JavaDoc generatorComponent) {
60         dNGeneratorComponent = generatorComponent;
61     }
62     public String JavaDoc getPostfix() {
63         return postfix;
64     }
65     public void setPostfix(String JavaDoc postfix) {
66         this.postfix = postfix;
67     }
68     public String JavaDoc getPrefix() {
69         return prefix;
70     }
71     public void setPrefix(String JavaDoc prefix) {
72         this.prefix = prefix;
73     }
74     public int getRandomGeneratorType() {
75         return randomGeneratorType;
76     }
77     public void setRandomGeneratorType(int randomGeneratorType) {
78         this.randomGeneratorType = randomGeneratorType;
79     }
80     public int getRandomNameLength() {
81         return randomNameLength;
82     }
83     public void setRandomNameLength(int randomNameLength) {
84         this.randomNameLength = randomNameLength;
85     }
86     public int getRandomPrefixLength() {
87         return randomPrefixLength;
88     }
89     public void setRandomPrefixLength(int randomPrefixLength) {
90         this.randomPrefixLength = randomPrefixLength;
91     }
92
93     public int getMode() {
94         return mode;
95     }
96
97     public void setMode(int mode) {
98         this.mode = mode;
99     }
100
101     public void setMode(String JavaDoc mode) {
102         modeList = Arrays.asList(modes);
103         if (!modeList.contains(mode)) {
104             throw new IllegalArgumentException JavaDoc("Mode " + mode + " is not supported");
105         }
106         this.mode = modeList.indexOf(mode);
107     }
108     
109
110 }
111
Popular Tags