001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.administration;
018:
019: import java.util.ArrayList;
020:
021: import javax.servlet.jsp.JspException;
022:
023: import org.apache.jetspeed.om.folder.Folder;
024: import org.apache.taglibs.random.RandomStrg;
025:
026: /**
027: * Helper for admininstration
028: *
029: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
030: * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
031: * @version $Id: $
032: */
033: public class AdminUtil {
034: /** the list of characters from which a password can be generatored. */
035: protected static final char[] PASS_CHARS = { 'a', 'b', 'c', 'd',
036: 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
037: 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
038: 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
039: 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
040: '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
041:
042: // removed these for aesthetic purposes
043: //'!', '&', '-', '_', '=',
044: // '*','@', '#', '$', '%', '^',
045: //'+',
046:
047: public String generatePassword() {
048: RandomStrg rs = new RandomStrg();
049:
050: //TODO put in a more secure random number provider
051: //rs.setAlgorithm(); -- ideally call this for super security. need rnd provider
052:
053: try {
054: rs.generateRandomObject();
055: } catch (JspException e) {
056: // this would only get thrown if we tried a secure random and the provider
057: // was not available.
058: e.printStackTrace();
059: }
060: rs.setLength(new Integer(12));
061: rs.setSingle(PASS_CHARS, PASS_CHARS.length);
062: ArrayList upper = new ArrayList();
063: ArrayList lower = new ArrayList();
064: //upper.add(new Character('A'));
065: //lower.add(new Character('B'));
066: rs.setRanges(upper, lower);
067: String retval = rs.getRandom();
068:
069: return retval;
070: }
071:
072: protected String concatenatePaths(String base, String path) {
073: String result = "";
074: if (base == null) {
075: if (path == null) {
076: return result;
077: }
078: return path;
079: } else {
080: if (path == null) {
081: return base;
082: }
083: }
084: if (base.endsWith(Folder.PATH_SEPARATOR)) {
085: if (path.startsWith(Folder.PATH_SEPARATOR)) {
086: result = base.concat(path.substring(1));
087: return result;
088: }
089:
090: } else {
091: if (!path.startsWith(Folder.PATH_SEPARATOR)) {
092: result = base.concat(Folder.PATH_SEPARATOR)
093: .concat(path);
094: return result;
095: }
096: }
097: return base.concat(path);
098: }
099:
100: }
|