Skip to content

Commit

Permalink
Merge branch '5.9.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
hplahar committed Apr 15, 2022
2 parents 28150f7 + 4204175 commit 5e1e8b0
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ Thumbs.db
/ice.iml
/src/main/ngapp/package-lock.json
/src/main/ngapp/.angular/
/data/
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.5.Final</version>
<version>5.6.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand All @@ -76,7 +76,7 @@
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.1.Final</version>
<version>7.0.4.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
Expand All @@ -86,7 +86,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.6.5.Final</version>
<version>5.6.7.Final</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand All @@ -101,12 +101,12 @@
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.5.2</version>
<version>5.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.10</version>
<version>1.2.11</version>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
Expand Down Expand Up @@ -150,7 +150,7 @@
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>2.2.15.Final</version>
<version>2.2.16.Final</version>
</dependency>
</dependencies>
<build>
Expand Down
80 changes: 56 additions & 24 deletions src/main/java/org/jbei/ice/lib/account/AccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import org.apache.commons.lang3.StringUtils;
import org.jbei.ice.lib.access.PermissionException;
import org.jbei.ice.lib.account.authentication.AuthenticationException;
import org.jbei.ice.lib.account.authentication.IAuthentication;
import org.jbei.ice.lib.account.authentication.LocalAuthentication;
import org.jbei.ice.lib.account.authentication.*;
import org.jbei.ice.lib.common.logging.Logger;
import org.jbei.ice.lib.dto.ConfigurationKey;
import org.jbei.ice.lib.dto.group.GroupType;
Expand Down Expand Up @@ -33,7 +31,6 @@
public class AccountController {

private static final String ADMIN_ACCOUNT_EMAIL = "Administrator";
private static final String ADMIN_ACCOUNT_PASSWORD = "Administrator";
private final AccountDAO dao;
private final GroupDAO groupDAO;

Expand Down Expand Up @@ -254,29 +251,40 @@ public AccountTransfer createNewAccount(final AccountTransfer info, final boolea
/**
* @return new admin account
*/
public Account createAdminAccount() {
public void createAdminAccount() {
Account adminAccount = getByEmail(ADMIN_ACCOUNT_EMAIL);
String newPassword = AccountUtils.generateRandomToken(48);

if (adminAccount != null) {
return adminAccount;
Logger.info("Resetting Administrator account password");
adminAccount.setPassword(AccountUtils.encryptNewUserPassword(newPassword, adminAccount.getSalt()));
adminAccount.setModificationTime(new Date());
dao.update(adminAccount);
} else {
adminAccount = new Account();
adminAccount.setEmail(ADMIN_ACCOUNT_EMAIL);
adminAccount.setLastName("Administrator");
adminAccount.setFirstName("");
adminAccount.setInitials("");
adminAccount.setInstitution("");
adminAccount.setSalt(Utils.generateSaltForUserAccount());
adminAccount.setPassword(AccountUtils.encryptNewUserPassword(newPassword, adminAccount.getSalt()));
adminAccount.setDescription("Administrator Account");

adminAccount.setIp("");
final Date currentTime = Calendar.getInstance().getTime();
adminAccount.setCreationTime(currentTime);
adminAccount.setModificationTime(currentTime);
adminAccount.setLastLoginTime(currentTime);
adminAccount.setType(AccountType.ADMIN);
save(adminAccount);
}

adminAccount = new Account();
adminAccount.setEmail(ADMIN_ACCOUNT_EMAIL);
adminAccount.setLastName("Administrator");
adminAccount.setFirstName("");
adminAccount.setInitials("");
adminAccount.setInstitution("");
adminAccount.setSalt(Utils.generateSaltForUserAccount());
adminAccount.setPassword(AccountUtils.encryptNewUserPassword(ADMIN_ACCOUNT_PASSWORD, adminAccount.getSalt()));
adminAccount.setDescription("Administrator Account");

adminAccount.setIp("");
final Date currentTime = Calendar.getInstance().getTime();
adminAccount.setCreationTime(currentTime);
adminAccount.setModificationTime(currentTime);
adminAccount.setLastLoginTime(currentTime);
adminAccount.setType(AccountType.ADMIN);
return save(adminAccount);
// add log information for admin password
Logger.info("NEW ADMIN PASSWORD");
Logger.info("************************");
Logger.info(newPassword);
Logger.info("************************");
}

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

private IAuthentication getAuthentication() {
try {
String clazz = Utils.getConfigValue(ConfigurationKey.AUTHENTICATION_METHOD);
if (StringUtils.isEmpty(clazz))
return new LocalAuthentication();

switch (AuthType.valueOf(clazz.toUpperCase())) {
case LDAP:
return new LblLdapAuthentication();

case OPEN:
return new UserIdAuthentication();

case DEFAULT:
default:
return new LocalAuthentication();
}
} catch (Exception e) {
Logger.error("Exception loading authentication class: ", e);
Logger.error("Using default authentication");
return new LocalAuthentication();
}
}

/**
* Authenticate a user in the database.
* <p>
Expand All @@ -363,7 +395,7 @@ public boolean isAdministrator(final String userId) {
* @return the account identifier (email) on a successful login, otherwise {@code null}
*/
protected Account authenticate(final String login, final String password, final String ip) {
final IAuthentication authentication = new LocalAuthentication();
final IAuthentication authentication = getAuthentication();
String email;

try {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jbei/ice/lib/account/AccountUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;

Expand All @@ -18,6 +20,13 @@
*/
public class AccountUtils {

public static String generateRandomToken(int byteSize) {
SecureRandom random = new SecureRandom();
byte[] token = new byte[byteSize];
random.nextBytes(token);
return DatatypeConverter.printBase64Binary(token);
}

/**
* Return the encrypted version of the given password, using the salt from the settings file.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jbei.ice.lib.account.authentication;

public enum AuthType {
LDAP,
OPEN,
DEFAULT
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ public Setting autoUpdateSetting(String userId, Setting setting) {
public void initPropertyValues() {
for (ConfigurationKey key : ConfigurationKey.values()) {
Configuration config = dao.get(key);
if (config != null || key.getDefaultValue().isEmpty())
continue;

Logger.info("Setting value for " + key.name() + " to " + key.getDefaultValue());
setPropertyValue(key, key.getDefaultValue());
if (config == null || (config.getValue().isBlank() && !key.getDefaultValue().isEmpty())) {
Logger.info("Setting value for " + key.name() + " to " + key.getDefaultValue());
setPropertyValue(key, key.getDefaultValue());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jbei/ice/lib/config/SiteSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class SiteSettings implements IDataTransferModel {

private String version = "5.9.4";
private String version = "5.9.5";
private String assetName;
private boolean hasLogo;
private boolean hasLoginMessage;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jbei/ice/lib/dto/ConfigurationKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public enum ConfigurationKey implements IDataTransferModel {

APPLICATION_VERSION("5.9.4"),
APPLICATION_VERSION("5.9.5"),
TEMPORARY_DIRECTORY("/tmp"),
DATA_DIRECTORY("data"),

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

// sample request config
SAMPLE_CREATE_APPROVAL_MESSAGE("");
SAMPLE_CREATE_APPROVAL_MESSAGE(""),
AUTHENTICATION_METHOD("DEFAULT");

private String defaultValue;

Expand Down
13 changes: 12 additions & 1 deletion src/main/webapp/scripts/admin/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ angular.module('ice.admin.controller', [])
$scope.emailConfig.type = type;
};

$scope.submitAuthSetting = function (val) {
$scope.submitSetting({key: 'AUTHENTICATION_METHOD', value: val});
$scope.authentication.value = val;
};

$scope.saveEmailConfig = function () {
$scope.submitSetting({key: "EMAILER", value: $scope.emailConfig.type});

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

Expand Down Expand Up @@ -107,6 +113,11 @@ angular.module('ice.admin.controller', [])
break;
}
}

if (AdminSettings.getAuthenticationOption().indexOf(setting.key) !== -1) {
console.log(setting);
$scope.authentication = setting;
}
});
});
};
Expand Down Expand Up @@ -723,4 +734,4 @@ angular.module('ice.admin.controller', [])

return false;
}
});
});
6 changes: 6 additions & 0 deletions src/main/webapp/scripts/admin/adminService.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ adminService.factory('AdminSettings', function () {
//'ADD_TO_CART_DEFAULT_SET_TO_LOCAL'
];

const authenticationKey = 'AUTHENTICATION_METHOD';

const menuOptions = [
{
url: 'scripts/admin/settings.html',
Expand Down Expand Up @@ -142,6 +144,10 @@ adminService.factory('AdminSettings', function () {

getMenuOptions: function () {
return menuOptions;
},

getAuthenticationOption: function () {
return authenticationKey;
}
}
});
39 changes: 33 additions & 6 deletions src/main/webapp/scripts/admin/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<!--for non boolean fields-->
<div class="col-md-9" ng-if="!setting.isBoolean" ng-mouseover="partIdEdit=true"
ng-mouseout="partIdEdit=false">
<div data-ng-if="!setting.editMode">
<div ng-if="!setting.editMode">
<span ng-if="setting.value.trim() !==''">{{setting.value.trim()}}</span>
<i class='opacity_4' ng-if="!setting.value">
<span ng-if="!setting.canAutoInstall || !autoInstalling">No value entered</span>
Expand All @@ -66,12 +66,12 @@
</span>
</div>

<div class="input-group" data-ng-if="setting.editMode">
<div class="input-group" ng-if="setting.editMode">
<form ng-submit="submitSetting(setting)">
<input type="text" ng-model="setting.value" class="input_box_group" maxlength="125"
style="width: 205px;">
</form>
<span class="input-group-addon" data-ng-click="setting.editMode=false" style="padding:3px; background-color:
<span class="input-group-addon" ng-click="setting.editMode=false" style="padding:3px; background-color:
#f1f1f1;width: 19px"><i class="fa fa-times delete_icon"></i></span>
</div>
</div>
Expand Down Expand Up @@ -141,25 +141,52 @@
<!--for non boolean fields-->
<div class="col-md-9" ng-if="!setting.isBoolean" ng-mouseover="partIdEdit=true"
ng-mouseout="partIdEdit=false">
<div data-ng-if="!setting.editMode"><span ng-if="setting.value&&setting.value.trim()!=''">{{setting.value}}</span>
<div ng-if="!setting.editMode"><span
ng-if="setting.value&&setting.value.trim()!=''">{{setting.value}}</span>
<i class='opacity_4' ng-if="!setting.value">No value entered</i><span
ng-click="setting.editMode=true">
<i ng-show="partIdEdit" class="fa fa-pencil edit_icon"
style="margin-left: 5px; font-size: 14px;"></i></span>
</div>

<div class="input-group" data-ng-if="setting.editMode">
<div class="input-group" ng-if="setting.editMode">
<form ng-submit="submitSetting(setting)">
<input type="text" ng-model="setting.value" class="input_box_group" maxlength="125"
style="width: 205px;">
</form>
<span class="input-group-addon" data-ng-click="setting.editMode=false" style="padding:3px; background-color:
<span class="input-group-addon" ng-click="setting.editMode=false" style="padding:3px; background-color:
#f1f1f1;width: 19px"><i class="fa fa-times delete_icon"></i></span>
</div>
</div>
</div>
</uib-tab>

<uib-tab>
<uib-tab-heading><i class="fa fa-key"></i> Authentication</uib-tab-heading>
<div class="pad_top">
<div class="col-md-4 entryLabel text-right">
Authentication Method
</div>

<div class="col-md-8">
<div class="btn-group" uib-dropdown>
<button type="button" class="btn btn-sm btn-default" uib-dropdown-toggle>
{{authentication.value}} <i class="fa fa-fw fa-fw fa-caret-down"></i>
</button>

<ul class="dropdown-menu" uib-dropdown-menu role="menu">
<li role="menuitem" ng-click="submitAuthSetting('DEFAULT')"
ng-if="authentication.value !== 'DEFAULT'"><a href="#">DEFAULT</a></li>
<li role="menuitem" ng-click="submitAuthSetting('OPEN')"
ng-if="authentication.value !== 'OPEN'"><a href="#">OPEN</a></li>
<li role="menuitem" ng-click="submitAuthSetting('LDAP')"
ng-if="authentication.value !== 'LDAP'"><a href="#">LDAP</a></li>
</ul>
</div>
</div>
</div>
</uib-tab>

</uib-tabset>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/views/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<div class="text-right" style="white-space: nowrap;">
&copy;&nbsp;<a href="https://github.com/JBEI/ice">JBEI ICE Registry</a> <span
class="label label-primary">5.9.4</span><br>
class="label label-primary">5.9.5</span><br>
All rights reserved. <br>
<a href="https://github.com/JBEI/ice/issues/new">Submit an Issue</a>&nbsp; <span class="text-muted">|</span>
&nbsp;<a href="http://ice.jbei.org/">Help</a>
Expand Down

0 comments on commit 5e1e8b0

Please sign in to comment.