Skip to content

Commit 5e1e8b0

Browse files
committed
Merge branch '5.9.5'
2 parents 28150f7 + 4204175 commit 5e1e8b0

File tree

12 files changed

+139
-46
lines changed

12 files changed

+139
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ Thumbs.db
4949
/ice.iml
5050
/src/main/ngapp/package-lock.json
5151
/src/main/ngapp/.angular/
52+
/data/

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>org.hibernate</groupId>
6363
<artifactId>hibernate-core</artifactId>
64-
<version>5.6.5.Final</version>
64+
<version>5.6.7.Final</version>
6565
</dependency>
6666
<dependency>
6767
<groupId>org.hibernate</groupId>
@@ -76,7 +76,7 @@
7676
<dependency>
7777
<groupId>org.hibernate.validator</groupId>
7878
<artifactId>hibernate-validator</artifactId>
79-
<version>7.0.1.Final</version>
79+
<version>7.0.4.Final</version>
8080
</dependency>
8181
<dependency>
8282
<groupId>javax.el</groupId>
@@ -86,7 +86,7 @@
8686
<dependency>
8787
<groupId>org.hibernate</groupId>
8888
<artifactId>hibernate-c3p0</artifactId>
89-
<version>5.6.5.Final</version>
89+
<version>5.6.7.Final</version>
9090
</dependency>
9191
<dependency>
9292
<groupId>commons-io</groupId>
@@ -101,12 +101,12 @@
101101
<dependency>
102102
<groupId>com.opencsv</groupId>
103103
<artifactId>opencsv</artifactId>
104-
<version>5.5.2</version>
104+
<version>5.6</version>
105105
</dependency>
106106
<dependency>
107107
<groupId>ch.qos.logback</groupId>
108108
<artifactId>logback-classic</artifactId>
109-
<version>1.2.10</version>
109+
<version>1.2.11</version>
110110
</dependency>
111111
<dependency>
112112
<groupId>org.biojava</groupId>
@@ -150,7 +150,7 @@
150150
<dependency>
151151
<groupId>io.undertow</groupId>
152152
<artifactId>undertow-servlet</artifactId>
153-
<version>2.2.15.Final</version>
153+
<version>2.2.16.Final</version>
154154
</dependency>
155155
</dependencies>
156156
<build>

src/main/java/org/jbei/ice/lib/account/AccountController.java

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import org.apache.commons.lang3.StringUtils;
44
import org.jbei.ice.lib.access.PermissionException;
5-
import org.jbei.ice.lib.account.authentication.AuthenticationException;
6-
import org.jbei.ice.lib.account.authentication.IAuthentication;
7-
import org.jbei.ice.lib.account.authentication.LocalAuthentication;
5+
import org.jbei.ice.lib.account.authentication.*;
86
import org.jbei.ice.lib.common.logging.Logger;
97
import org.jbei.ice.lib.dto.ConfigurationKey;
108
import org.jbei.ice.lib.dto.group.GroupType;
@@ -33,7 +31,6 @@
3331
public class AccountController {
3432

3533
private static final String ADMIN_ACCOUNT_EMAIL = "Administrator";
36-
private static final String ADMIN_ACCOUNT_PASSWORD = "Administrator";
3734
private final AccountDAO dao;
3835
private final GroupDAO groupDAO;
3936

@@ -254,29 +251,40 @@ public AccountTransfer createNewAccount(final AccountTransfer info, final boolea
254251
/**
255252
* @return new admin account
256253
*/
257-
public Account createAdminAccount() {
254+
public void createAdminAccount() {
258255
Account adminAccount = getByEmail(ADMIN_ACCOUNT_EMAIL);
256+
String newPassword = AccountUtils.generateRandomToken(48);
257+
259258
if (adminAccount != null) {
260-
return adminAccount;
259+
Logger.info("Resetting Administrator account password");
260+
adminAccount.setPassword(AccountUtils.encryptNewUserPassword(newPassword, adminAccount.getSalt()));
261+
adminAccount.setModificationTime(new Date());
262+
dao.update(adminAccount);
263+
} else {
264+
adminAccount = new Account();
265+
adminAccount.setEmail(ADMIN_ACCOUNT_EMAIL);
266+
adminAccount.setLastName("Administrator");
267+
adminAccount.setFirstName("");
268+
adminAccount.setInitials("");
269+
adminAccount.setInstitution("");
270+
adminAccount.setSalt(Utils.generateSaltForUserAccount());
271+
adminAccount.setPassword(AccountUtils.encryptNewUserPassword(newPassword, adminAccount.getSalt()));
272+
adminAccount.setDescription("Administrator Account");
273+
274+
adminAccount.setIp("");
275+
final Date currentTime = Calendar.getInstance().getTime();
276+
adminAccount.setCreationTime(currentTime);
277+
adminAccount.setModificationTime(currentTime);
278+
adminAccount.setLastLoginTime(currentTime);
279+
adminAccount.setType(AccountType.ADMIN);
280+
save(adminAccount);
261281
}
262282

263-
adminAccount = new Account();
264-
adminAccount.setEmail(ADMIN_ACCOUNT_EMAIL);
265-
adminAccount.setLastName("Administrator");
266-
adminAccount.setFirstName("");
267-
adminAccount.setInitials("");
268-
adminAccount.setInstitution("");
269-
adminAccount.setSalt(Utils.generateSaltForUserAccount());
270-
adminAccount.setPassword(AccountUtils.encryptNewUserPassword(ADMIN_ACCOUNT_PASSWORD, adminAccount.getSalt()));
271-
adminAccount.setDescription("Administrator Account");
272-
273-
adminAccount.setIp("");
274-
final Date currentTime = Calendar.getInstance().getTime();
275-
adminAccount.setCreationTime(currentTime);
276-
adminAccount.setModificationTime(currentTime);
277-
adminAccount.setLastLoginTime(currentTime);
278-
adminAccount.setType(AccountType.ADMIN);
279-
return save(adminAccount);
283+
// add log information for admin password
284+
Logger.info("NEW ADMIN PASSWORD");
285+
Logger.info("************************");
286+
Logger.info(newPassword);
287+
Logger.info("************************");
280288
}
281289

282290
/**
@@ -351,6 +359,30 @@ public boolean isAdministrator(final String userId) {
351359
return account != null && account.getType() == AccountType.ADMIN;
352360
}
353361

362+
private IAuthentication getAuthentication() {
363+
try {
364+
String clazz = Utils.getConfigValue(ConfigurationKey.AUTHENTICATION_METHOD);
365+
if (StringUtils.isEmpty(clazz))
366+
return new LocalAuthentication();
367+
368+
switch (AuthType.valueOf(clazz.toUpperCase())) {
369+
case LDAP:
370+
return new LblLdapAuthentication();
371+
372+
case OPEN:
373+
return new UserIdAuthentication();
374+
375+
case DEFAULT:
376+
default:
377+
return new LocalAuthentication();
378+
}
379+
} catch (Exception e) {
380+
Logger.error("Exception loading authentication class: ", e);
381+
Logger.error("Using default authentication");
382+
return new LocalAuthentication();
383+
}
384+
}
385+
354386
/**
355387
* Authenticate a user in the database.
356388
* <p>
@@ -363,7 +395,7 @@ public boolean isAdministrator(final String userId) {
363395
* @return the account identifier (email) on a successful login, otherwise {@code null}
364396
*/
365397
protected Account authenticate(final String login, final String password, final String ip) {
366-
final IAuthentication authentication = new LocalAuthentication();
398+
final IAuthentication authentication = getAuthentication();
367399
String email;
368400

369401
try {

src/main/java/org/jbei/ice/lib/account/AccountUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import javax.crypto.SecretKeyFactory;
99
import javax.crypto.spec.PBEKeySpec;
10+
import javax.xml.bind.DatatypeConverter;
1011
import java.security.NoSuchAlgorithmException;
12+
import java.security.SecureRandom;
1113
import java.security.spec.InvalidKeySpecException;
1214
import java.security.spec.KeySpec;
1315

@@ -18,6 +20,13 @@
1820
*/
1921
public class AccountUtils {
2022

23+
public static String generateRandomToken(int byteSize) {
24+
SecureRandom random = new SecureRandom();
25+
byte[] token = new byte[byteSize];
26+
random.nextBytes(token);
27+
return DatatypeConverter.printBase64Binary(token);
28+
}
29+
2130
/**
2231
* Return the encrypted version of the given password, using the salt from the settings file.
2332
*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.jbei.ice.lib.account.authentication;
2+
3+
public enum AuthType {
4+
LDAP,
5+
OPEN,
6+
DEFAULT
7+
}

src/main/java/org/jbei/ice/lib/config/ConfigurationSettings.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,10 @@ public Setting autoUpdateSetting(String userId, Setting setting) {
170170
public void initPropertyValues() {
171171
for (ConfigurationKey key : ConfigurationKey.values()) {
172172
Configuration config = dao.get(key);
173-
if (config != null || key.getDefaultValue().isEmpty())
174-
continue;
175-
176-
Logger.info("Setting value for " + key.name() + " to " + key.getDefaultValue());
177-
setPropertyValue(key, key.getDefaultValue());
173+
if (config == null || (config.getValue().isBlank() && !key.getDefaultValue().isEmpty())) {
174+
Logger.info("Setting value for " + key.name() + " to " + key.getDefaultValue());
175+
setPropertyValue(key, key.getDefaultValue());
176+
}
178177
}
179178
}
180179

src/main/java/org/jbei/ice/lib/config/SiteSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class SiteSettings implements IDataTransferModel {
1111

12-
private String version = "5.9.4";
12+
private String version = "5.9.5";
1313
private String assetName;
1414
private boolean hasLogo;
1515
private boolean hasLoginMessage;

src/main/java/org/jbei/ice/lib/dto/ConfigurationKey.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public enum ConfigurationKey implements IDataTransferModel {
1313

14-
APPLICATION_VERSION("5.9.4"),
14+
APPLICATION_VERSION("5.9.5"),
1515
TEMPORARY_DIRECTORY("/tmp"),
1616
DATA_DIRECTORY("data"),
1717

@@ -37,7 +37,8 @@ public enum ConfigurationKey implements IDataTransferModel {
3737
WEB_OF_REGISTRIES_MASTER("registry.jbei.org"),
3838

3939
// sample request config
40-
SAMPLE_CREATE_APPROVAL_MESSAGE("");
40+
SAMPLE_CREATE_APPROVAL_MESSAGE(""),
41+
AUTHENTICATION_METHOD("DEFAULT");
4142

4243
private String defaultValue;
4344

src/main/webapp/scripts/admin/adminController.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ angular.module('ice.admin.controller', [])
4949
$scope.emailConfig.type = type;
5050
};
5151

52+
$scope.submitAuthSetting = function (val) {
53+
$scope.submitSetting({key: 'AUTHENTICATION_METHOD', value: val});
54+
$scope.authentication.value = val;
55+
};
56+
5257
$scope.saveEmailConfig = function () {
5358
$scope.submitSetting({key: "EMAILER", value: $scope.emailConfig.type});
5459

@@ -66,6 +71,7 @@ angular.module('ice.admin.controller', [])
6671
$scope.getSetting = function () {
6772
$scope.generalSettings = [];
6873
$scope.emailSettings = [];
74+
$scope.authentication = undefined;
6975
$scope.sampleRequestSettings = [];
7076
$scope.emailConfig = {type: "", smtp: "", pass: "", edit: false, showEdit: false, showPass: false};
7177

@@ -107,6 +113,11 @@ angular.module('ice.admin.controller', [])
107113
break;
108114
}
109115
}
116+
117+
if (AdminSettings.getAuthenticationOption().indexOf(setting.key) !== -1) {
118+
console.log(setting);
119+
$scope.authentication = setting;
120+
}
110121
});
111122
});
112123
};
@@ -723,4 +734,4 @@ angular.module('ice.admin.controller', [])
723734

724735
return false;
725736
}
726-
});
737+
});

src/main/webapp/scripts/admin/adminService.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ adminService.factory('AdminSettings', function () {
4444
//'ADD_TO_CART_DEFAULT_SET_TO_LOCAL'
4545
];
4646

47+
const authenticationKey = 'AUTHENTICATION_METHOD';
48+
4749
const menuOptions = [
4850
{
4951
url: 'scripts/admin/settings.html',
@@ -142,6 +144,10 @@ adminService.factory('AdminSettings', function () {
142144

143145
getMenuOptions: function () {
144146
return menuOptions;
147+
},
148+
149+
getAuthenticationOption: function () {
150+
return authenticationKey;
145151
}
146152
}
147153
});

0 commit comments

Comments
 (0)