From 0e4c10e29fe82611d007f1b6a389b5a2f5588e37 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 12 Jan 2013 14:09:58 -0800 Subject: [PATCH] PasswordGenerator only used in scriptbuilder --- .../org/jclouds/util/PasswordGenerator.java | 60 ------------------- .../login/DefaultConfiguration.java | 44 ++++++++++++-- 2 files changed, 40 insertions(+), 64 deletions(-) delete mode 100644 core/src/main/java/org/jclouds/util/PasswordGenerator.java diff --git a/core/src/main/java/org/jclouds/util/PasswordGenerator.java b/core/src/main/java/org/jclouds/util/PasswordGenerator.java deleted file mode 100644 index aa0c88508e..0000000000 --- a/core/src/main/java/org/jclouds/util/PasswordGenerator.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import java.security.SecureRandom; - -import com.google.common.base.Supplier; - -/** - * Cheap, lightweight, low-security password generator. - * - * @see - */ -public enum PasswordGenerator implements Supplier { - - INSTANCE; - - /** Minimum length for a decent password */ - public static final int MIN_LENGTH = 10; - - /** The random number generator. */ - protected static final SecureRandom r = new SecureRandom(); - - /* - * Set of characters that is valid. Must be printable, memorable, and - * "won't break HTML" (i.e., not ' <', '>', '&', '=', ...). or break shell - * commands (i.e., not ' <', '>', '$', '!', ...). I, L and O are good to - * leave out, as are numeric zero and one. - */ - public static final char[] goodChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', - 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', - 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '@', }; - - @Override - public String get() { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < MIN_LENGTH; i++) { - sb.append(goodChar[r.nextInt(goodChar.length)]); - } - return sb.toString(); - } -} diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/DefaultConfiguration.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/DefaultConfiguration.java index d394d0bacf..c8ccb9ed3a 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/DefaultConfiguration.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/DefaultConfiguration.java @@ -22,6 +22,7 @@ import static com.google.common.base.Charsets.UTF_8; import java.io.File; import java.io.IOException; +import java.security.SecureRandom; import java.util.Map; import javax.inject.Singleton; @@ -29,7 +30,6 @@ import javax.inject.Singleton; import org.jclouds.crypto.Sha512Crypt; import org.jclouds.crypto.SshKeys; import org.jclouds.scriptbuilder.statements.login.AdminAccess.Configuration; -import org.jclouds.util.PasswordGenerator; import com.google.common.base.Function; import com.google.common.base.Supplier; @@ -59,9 +59,45 @@ public class DefaultConfiguration implements Configuration { } } }; - private final Supplier passwordGenerator = PasswordGenerator.INSTANCE; - private final Function cryptFunction = Sha512Crypt.function(); + /** + * Cheap, lightweight, low-security password generator. + * + * @see + */ + public enum PasswordGenerator implements Supplier { + + INSTANCE; + + /** Minimum length for a decent password */ + public static final int MIN_LENGTH = 10; + + /** The random number generator. */ + protected static final SecureRandom r = new SecureRandom(); + + /* + * Set of characters that is valid. Must be printable, memorable, and "won't break HTML" (i.e., not ' <', '>', + * '&', '=', ...). or break shell commands (i.e., not ' <', '>', '$', '!', ...). I, L and O are good to leave out, + * as are numeric zero and one. + */ + public static final char[] goodChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', + 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', + '@', }; + + @Override + public String get() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < MIN_LENGTH; i++) { + sb.append(goodChar[r.nextInt(goodChar.length)]); + } + return sb.toString(); + } + } + + private final Function cryptFunction = Sha512Crypt.function(); + @Override public Supplier defaultAdminUsername() { return defaultAdminUsername; @@ -74,7 +110,7 @@ public class DefaultConfiguration implements Configuration { @Override public Supplier passwordGenerator() { - return passwordGenerator; + return PasswordGenerator.INSTANCE; } @Override