Skip to content

Commit 21529a8

Browse files
Merge pull request Silverpeas#2 from mmoqui/feature-4148
Encryption of the admin passwords with the new cryptographic function and increase the size of the password field type in database
2 parents 970d87a + 77fcdfc commit 21529a8

File tree

19 files changed

+1321
-661
lines changed

19 files changed

+1321
-661
lines changed

src/main/java/org/silverpeas/dbbuilder/dbbuilder_dl/DbBuilderDynamicPart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
package org.silverpeas.dbbuilder.dbbuilder_dl;
2626

27-
import org.silverpeas.dbbuilder.Console;
2827
import java.sql.Connection;
28+
import org.silverpeas.dbbuilder.Console;
2929

3030
/**
3131
* Titre : Description : Copyright : Copyright (c) 2002 Société :

src/main/java/org/silverpeas/dbbuilder/util/Configuration.java

Lines changed: 88 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
/**
22
* Copyright (C) 2000 - 2012 Silverpeas
33
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU Affero General Public License as
6-
* published by the Free Software Foundation, either version 3 of the
7-
* License, or (at your option) any later version.
4+
* This program is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU Affero General Public License as published by the Free Software Foundation, either version 3
6+
* of the License, or (at your option) any later version.
87
*
9-
* As a special exception to the terms and conditions of version 3.0 of
10-
* the GPL, you may redistribute this Program in connection with Free/Libre
11-
* Open Source Software ("FLOSS") applications as described in Silverpeas's
12-
* FLOSS exception. You should have received a copy of the text describing
13-
* the FLOSS exception, and it is also available here:
8+
* As a special exception to the terms and conditions of version 3.0 of the GPL, you may
9+
* redistribute this Program in connection with Free/Libre Open Source Software ("FLOSS")
10+
* applications as described in Silverpeas's FLOSS exception. You should have received a copy of the
11+
* text describing the FLOSS exception, and it is also available here:
1412
* "http://www.silverpeas.org/docs/core/legal/floss_exception.html"
1513
*
16-
* This program is distributed in the hope that it will be useful,
17-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19-
* GNU Affero General Public License for more details.
14+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Affero General Public License for more details.
2017
*
21-
* You should have received a copy of the GNU Affero General Public License
22-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
* You should have received a copy of the GNU Affero General Public License along with this program.
19+
* If not, see <http://www.gnu.org/licenses/>.
2320
*/
24-
2521
package org.silverpeas.dbbuilder.util;
2622

2723
import java.io.File;
24+
import java.io.FileFilter;
2825
import java.io.FileInputStream;
2926
import java.io.IOException;
3027
import java.io.InputStream;
@@ -39,7 +36,6 @@ public class Configuration {
3936

4037
private static String dbbuilderHome = null;
4138
private static String dbbuilderData = null;
42-
4339
private static final String DATA_KEY = "dbbuilder.data";
4440
private static final String HOME_KEY = "dbbuilder.home";
4541
private static final String DBREPOSITORY_SUBDIR = "dbRepository";
@@ -48,29 +44,26 @@ public class Configuration {
4844
private static final String TEMP_FILES_SUBDIR = "temp";
4945
private static final String DIR_CONTRIBUTIONFILESROOT = Configuration.getHome()
5046
+ File.separator + DBREPOSITORY_SUBDIR + File.separator + CONTRIB_FILES_SUBDIR;
51-
// Répertoire racine des DB Pieces Contribution File
47+
// Répertoire racine des DB Pieces Contribution File
5248
private static final String DIR_DBPIECESFILESROOT =
5349
getHome() + File.separator + DBREPOSITORY_SUBDIR;
54-
// Répertoire temp
50+
// Répertoire temp
5551
private static final String DIR_TEMP = getHome() + File.separator + TEMP_FILES_SUBDIR;
5652

5753
/**
5854
* Load a properties file from the classpath then from $SILVERPEAS_HOME/properties
59-
* @param propertyName
60-
* @return a java.util.Properties
61-
* @throws IOException
55+
* @param propertyName the path of the resource in the classpath or relative to the
56+
* $SILVERPEAS_HOME/properties folder.
57+
* @return the resource properties
58+
* @throws IOException if an error occurs while loading the resource content.
6259
*/
6360
public static Properties loadResource(String propertyName) throws IOException {
6461
Properties properties = new Properties();
6562
InputStream in = Configuration.class.getClassLoader().getResourceAsStream(propertyName);
6663
try {
6764
if (in == null) {
68-
String path = propertyName.replace('/', File.separatorChar);
69-
path = path.replace('\\', File.separatorChar);
70-
if (!path.startsWith(File.separator)) {
71-
path = File.separatorChar + path;
72-
}
73-
File configurationFile = new File(getHome() + File.separatorChar + "properties" + path);
65+
String path = getPropertyPath(propertyName);
66+
File configurationFile = new File(path);
7467
if (configurationFile.exists()) {
7568
in = new FileInputStream(configurationFile);
7669
}
@@ -84,7 +77,63 @@ public static Properties loadResource(String propertyName) throws IOException {
8477
return properties;
8578
}
8679

87-
// Récupère le répertoire racine d'installation
80+
/**
81+
* Loads the properties from specified resource.
82+
* @param resource a resource.
83+
* @return the resource properties.
84+
* @throws IOException if an error occurs while loading the resource content.
85+
*/
86+
public static Properties loadResource(File resource) throws IOException {
87+
Properties properties = new Properties();
88+
InputStream stream = null;
89+
if (resource.exists()) {
90+
try {
91+
stream = new FileInputStream(resource);
92+
properties.load(stream);
93+
} finally {
94+
IOUtils.closeQuietly(stream);
95+
}
96+
}
97+
return properties;
98+
}
99+
100+
/**
101+
* Lists the resources in the specified directory and whose the name matches the specified filter.
102+
* The path of the directory should be relative to the properties folder in the Silverpeas home
103+
* directory.
104+
* @param directoryPath the relative path of the directory containing the resources to list.
105+
* @param filter a filter on the resources to list. If the filter is null or empty, then no
106+
* filtering is applied on the resources listing in the specified directory.
107+
* @return an array of File instances, each of them representing a resource in the specified
108+
* directory and matching the specified filter if any.
109+
* @throws IOException if the path doesn't refer a directory
110+
*/
111+
public static File[] listResources(final String directoryPath, final FileFilter filter) throws
112+
IOException {
113+
String path = getPropertyPath(directoryPath);
114+
File dir = new File(path);
115+
if (!dir.exists() || !dir.isDirectory()) {
116+
throw new IOException("The path '" + path + "' doesn't refer a directory!");
117+
}
118+
return dir.listFiles(new FileFilter() {
119+
@Override
120+
public boolean accept(File file) {
121+
boolean match = (filter != null ? filter.accept(file) : true);
122+
return file.isFile() && match;
123+
}
124+
});
125+
}
126+
127+
public static boolean isExist(final String resourcePath) {
128+
String path = Configuration.class.getClassLoader().getResource(resourcePath).getPath();
129+
if (!new File(path).exists()) {
130+
path = getPropertyPath(resourcePath);
131+
return new File(path).exists();
132+
}
133+
return true;
134+
}
135+
136+
// Récupère le répertoire racine d'installation
88137
public static String getHome() {
89138
if (dbbuilderHome == null) {
90139
if (!System.getProperties().containsKey(HOME_KEY)) {
@@ -106,7 +155,7 @@ public static String getPiecesFilesDir() {
106155
return DIR_DBPIECESFILESROOT;
107156
}
108157

109-
// Récupère le répertoire data d'installation
158+
// Récupère le répertoire data d'installation
110159
public static String getData() {
111160
if (dbbuilderData == null) {
112161
if (System.getProperties().containsKey(DATA_KEY)) {
@@ -128,6 +177,15 @@ public static String getLogDir() {
128177
return getHome() + File.separator + LOG_FILES_SUBDIR;
129178
}
130179

180+
private static String getPropertyPath(String propertyPath) {
181+
String path = propertyPath.replace('/', File.separatorChar);
182+
path = path.replace('\\', File.separatorChar);
183+
if (!path.startsWith(File.separator)) {
184+
path = File.separatorChar + path;
185+
}
186+
return getHome() + File.separatorChar + "properties" + path;
187+
}
188+
131189
private Configuration() {
132190
}
133191
}

0 commit comments

Comments
 (0)