%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.administration.AdminUtil |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.administration; |
|
18 | ||
19 | import java.util.ArrayList; |
|
20 | ||
21 | import javax.servlet.jsp.JspException; |
|
22 | ||
23 | import org.apache.jetspeed.om.folder.Folder; |
|
24 | import org.apache.taglibs.random.RandomStrg; |
|
25 | ||
26 | /** |
|
27 | * Helper for admininstration |
|
28 | * |
|
29 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> |
|
30 | * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a> |
|
31 | * @version $Id: $ |
|
32 | */ |
|
33 | 0 | public class AdminUtil |
34 | { |
|
35 | /** the list of characters from which a password can be generatored. */ |
|
36 | 0 | protected static final char[] PASS_CHARS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
37 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
|
38 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', |
|
39 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
|
40 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; |
|
41 | // removed these for aesthetic purposes |
|
42 | //'!', '&', '-', '_', '=', |
|
43 | // '*','@', '#', '$', '%', '^', |
|
44 | //'+', |
|
45 | ||
46 | public String generatePassword() |
|
47 | { |
|
48 | 0 | RandomStrg rs = new RandomStrg(); |
49 | ||
50 | //TODO put in a more secure random number provider |
|
51 | //rs.setAlgorithm(); -- ideally call this for super security. need rnd provider |
|
52 | ||
53 | try |
|
54 | { |
|
55 | 0 | rs.generateRandomObject(); |
56 | 0 | } catch (JspException e) |
57 | { |
|
58 | // this would only get thrown if we tried a secure random and the provider |
|
59 | // was not available. |
|
60 | 0 | e.printStackTrace(); |
61 | 0 | } |
62 | 0 | rs.setLength(new Integer(12)); |
63 | 0 | rs.setSingle(PASS_CHARS,PASS_CHARS.length); |
64 | 0 | ArrayList upper = new ArrayList(); |
65 | 0 | ArrayList lower = new ArrayList(); |
66 | //upper.add(new Character('A')); |
|
67 | //lower.add(new Character('B')); |
|
68 | 0 | rs.setRanges(upper,lower); |
69 | 0 | String retval = rs.getRandom(); |
70 | ||
71 | 0 | return retval; |
72 | } |
|
73 | ||
74 | protected String concatenatePaths(String base, String path) |
|
75 | { |
|
76 | 0 | String result = ""; |
77 | 0 | if (base == null) |
78 | { |
|
79 | 0 | if (path == null) |
80 | { |
|
81 | 0 | return result; |
82 | } |
|
83 | 0 | return path; |
84 | } |
|
85 | else |
|
86 | { |
|
87 | 0 | if (path == null) |
88 | { |
|
89 | 0 | return base; |
90 | } |
|
91 | } |
|
92 | 0 | if (base.endsWith(Folder.PATH_SEPARATOR)) |
93 | { |
|
94 | 0 | if (path.startsWith(Folder.PATH_SEPARATOR)) |
95 | { |
|
96 | 0 | result = base.concat(path.substring(1)); |
97 | 0 | return result; |
98 | } |
|
99 | ||
100 | } |
|
101 | else |
|
102 | { |
|
103 | 0 | if (!path.startsWith(Folder.PATH_SEPARATOR)) |
104 | { |
|
105 | 0 | result = base.concat(Folder.PATH_SEPARATOR).concat(path); |
106 | 0 | return result; |
107 | } |
|
108 | } |
|
109 | 0 | return base.concat(path); |
110 | } |
|
111 | ||
112 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |