| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | * Portions Copyright 2011-2013 ForgeRock AS |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.FileReader; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.io.*; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | import java.net.Socket; |
| | |
| | | import java.security.cert.CertificateEncodingException; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.Random; |
| | | import java.util.Set; |
| | | |
| | | import java.util.Random; |
| | | |
| | | import org.opends.server.types.OperatingSystem; |
| | | |
| | | |
| | | /** |
| | | * This class provides a number of utility methods that may be used during the |
| | | * graphical or command-line setup process. |
| | |
| | | */ |
| | | public static boolean isWindows() |
| | | { |
| | | return OperatingSystem.WINDOWS == getOperatingSystem(); |
| | | return OperatingSystem.WINDOWS == getOperatingSystem(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isVista() |
| | | { |
| | | boolean isVista; |
| | | String os = System.getProperty("os.name"); |
| | | if (os != null) |
| | | { |
| | | isVista = isWindows() && (os.toLowerCase().indexOf("vista") != -1); |
| | | return isWindows() && (os.toLowerCase().indexOf("vista") != -1); |
| | | } |
| | | else |
| | | { |
| | | isVista = false; |
| | | } |
| | | return isVista; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isWindows2008() |
| | | { |
| | | boolean isWindows2008; |
| | | String os = System.getProperty("os.name"); |
| | | if (os != null) |
| | | { |
| | | isWindows2008 = isWindows() && |
| | | (os.toLowerCase().indexOf("server 2008") != -1); |
| | | return isWindows() && (os.toLowerCase().indexOf("server 2008") != -1); |
| | | } |
| | | else |
| | | { |
| | | isWindows2008 = false; |
| | | } |
| | | return isWindows2008; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isWindows7() |
| | | { |
| | | boolean isWindows7; |
| | | String os = System.getProperty("os.name"); |
| | | if (os != null) |
| | | { |
| | | isWindows7 = (os.toLowerCase().indexOf("windows 7") != -1); |
| | | return os.toLowerCase().indexOf("windows 7") != -1; |
| | | } |
| | | else |
| | | { |
| | | isWindows7 = false; |
| | | } |
| | | return isWindows7; |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | s = new Socket(); |
| | | s.connect(socketAddress, 1000); |
| | | canUseAsPort = false; |
| | | |
| | | } catch (Throwable t) |
| | | { |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } catch (IOException ex) |
| | | { |
| | | canUseAsPort = false; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns {@code true} if the provided port is a priviledged port, |
| | | * Returns {@code true} if the provided port is a privileged port, |
| | | * {@code false} otherwise. |
| | | * @param port the port we are analyzing. |
| | | * @return {@code true} if the provided port is a priviledged port, |
| | | * @return {@code true} if the provided port is a privileged port, |
| | | * {@code false} otherwise. |
| | | */ |
| | | public static boolean isPriviledgedPort(int port) |
| | |
| | | byte[] certificateBytes = certificate.getEncoded(); |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(path, false); |
| | | outputStream.write(certificateBytes); |
| | | outputStream.close(); |
| | | try |
| | | { |
| | | outputStream.write(certificateBytes); |
| | | } |
| | | finally |
| | | { |
| | | close(outputStream); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | byte[] certificateBytes = certificate.getEncoded(); |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(path, false); |
| | | outputStream.write(certificateBytes); |
| | | outputStream.close(); |
| | | try |
| | | { |
| | | outputStream.write(certificateBytes); |
| | | } |
| | | finally |
| | | { |
| | | close(outputStream); |
| | | } |
| | | } |
| | | |
| | | /* The next two methods are used to generate the random password for the |
| | |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (br != null) |
| | | { |
| | | br.close(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | // ignore |
| | | } |
| | | close(br); |
| | | } |
| | | if (hostName == null) |
| | | { |
| | |
| | | } |
| | | return hostName; |
| | | } |
| | | } |
| | | |
| | | private static void close(Closeable toClose) |
| | | { |
| | | if (toClose != null) |
| | | { |
| | | try |
| | | { |
| | | toClose.close(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | // ignore |
| | | } |
| | | } |
| | | } |
| | | } |