Skip to content

Commit

Permalink
Merge branch 'hotfix-4.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
hplahar committed Nov 20, 2014
2 parents 8ca3b59 + ba543a2 commit 2b1268d
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 155 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.jbei</groupId>
<artifactId>ice</artifactId>
<packaging>war</packaging>
<version>4.1.1</version>
<version>4.1.2</version>
<name>ice</name>
<description>Inventory of Composable Elements (ICE) for Synthetic Biology</description>
<repositories>
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/jbei/ice/lib/account/AccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,6 @@ public boolean isAdministrator(String userId) {
return account != null && account.getType() == AccountType.ADMIN;
}

/**
* Check if the given password is valid for the account.
*
* @param account
* @param password
* @return True if correct password.
* @throws ControllerException
*/
public boolean isValidPassword(Account account, String password) throws ControllerException {
if (account == null) {
throw new ControllerException("Failed to verify password for null Account!");
}

return account.getPassword().equals(AccountUtils.encryptNewUserPassword(password, account.getSalt()));
}

/**
* Authenticate a user in the database.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.jbei.ice.lib.account.authentication;

import org.jbei.ice.ControllerException;
import org.jbei.ice.lib.account.AccountController;
import org.jbei.ice.lib.account.AccountUtils;
import org.jbei.ice.lib.account.model.Account;
import org.jbei.ice.lib.common.logging.Logger;
import org.jbei.ice.lib.dao.DAOFactory;
import org.jbei.ice.lib.dto.ConfigurationKey;

/**
* Backend for authentication using the database. This is the default backend.
* Default ICE authentication scheme
*
* @author Hector Plahar
*/
Expand All @@ -22,46 +22,49 @@ public String authenticates(String userId, String password) throws Authenticatio
if (userId == null || password == null)
throw new AuthenticationException("Invalid username and password");

Account account;
AccountController controller = new AccountController();

try {
account = controller.getByEmail(userId);
if (account == null || !isValidPassword(account, password))
return null;
return account.getEmail();
} catch (ControllerException e) {
throw new AuthenticationException("Exception validating credentials", e);
}
Account account = controller.getByEmail(userId);
if (account == null || !isValidPassword(account, password))
return null;
return account.getEmail();
}

/**
* Check if the given password is valid for the account.
* Check if the given password is valid for the account. There are multiple checks for backward compatibility
* reasons
*
* @param account
* @param password
* @return True if correct password.
* @throws ControllerException
* @param account user account whose password is being checked
* @param password user entered password being checked for validation
* @return True if entered password matches one of encrypted schemes, false otherwise.
*/
protected boolean isValidPassword(Account account, String password) throws ControllerException {
protected boolean isValidPassword(Account account, String password) {
if (account == null) {
throw new ControllerException("Failed to verify password for null Account!");
return false;
}

// first check using the stronger encryption scheme
boolean valid = account.getPassword().equals(AccountUtils.encryptNewUserPassword(password, account.getSalt()));
if (valid)
return valid;
String encrypted = AccountUtils.encryptPassword(password, account.getSalt());
valid = account.getPassword().equals(encrypted);
if (valid) {
// update
account.setPassword(encrypted);
try {
DAOFactory.getAccountDAO().update(account);
} catch (Exception e) {
Logger.error(e);
}
return true;

// invalid check for deprecated salt using older encryption scheme
String salt = ConfigurationKey.SECRET_KEY.getDefaultValue();
valid = account.getPassword().equals(AccountUtils.encryptPassword(password, salt));
if (!valid) {
// check old encryption scheme using user salt
valid = account.getPassword().equals(AccountUtils.encryptPassword(password, account.getSalt()));
if (!valid)
return false;
}

// at this stage then password is valid, upgrade to new version
String newEncrypted = AccountUtils.encryptNewUserPassword(password, account.getSalt());
account.setPassword(newEncrypted);
try {
DAOFactory.getAccountDAO().update(account);
} catch (Exception e) {
Logger.error(e);
}
return false;
return true;
}
}
12 changes: 11 additions & 1 deletion src/main/java/org/jbei/ice/lib/entry/EntryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@ public PartData retrieveEntryDetails(String userId, String id) {
return retrieveEntryDetails(userId, entry);
}

/**
* Retrieves and sets the default values for the entry. Some of these values (e.g. PI, and Funding Source)
* are set by individual users as part of their personal preferences
*
* @param userId Unique identifier for user requesting the values.
* @param type entry type
* @return PartData object with the retrieve part defaults
*/
public PartData getPartDefaults(String userId, EntryType type) {
PartData partData = new PartData(type);
PreferencesController preferencesController = new PreferencesController();
Expand All @@ -634,6 +642,7 @@ public PartData getPartDefaults(String userId, EntryType type) {
partData.setFundingSource(value);
}

// owner and creator details
Account account = accountController.getByEmail(userId);
if (account != null) {
partData.setOwner(account.getFullName());
Expand All @@ -642,7 +651,8 @@ public PartData getPartDefaults(String userId, EntryType type) {
partData.setCreatorEmail(partData.getOwnerEmail());
}

return partData;
// set the entry type defaults
return EntryUtil.setPartDefaults(partData);
}

protected PartData retrieveEntryDetails(String userId, Entry entry) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/jbei/ice/lib/entry/EntryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jbei.ice.lib.dto.bulkupload.EntryField;
import org.jbei.ice.lib.dto.entry.EntryType;
import org.jbei.ice.lib.dto.entry.PartData;
import org.jbei.ice.lib.dto.entry.PlasmidData;
import org.jbei.ice.lib.entry.model.ArabidopsisSeed;
import org.jbei.ice.lib.entry.model.Entry;
import org.jbei.ice.lib.entry.model.Part;
Expand Down Expand Up @@ -257,4 +258,19 @@ public static boolean validates(PartData partData) {

return true;
}

public static PartData setPartDefaults(PartData partData) {
switch (partData.getType()) {
case PLASMID:
if (partData.getPlasmidData() == null) {
PlasmidData plasmidData = new PlasmidData();
plasmidData.setCircular(true);
partData.setPlasmidData(plasmidData);
} else
partData.getPlasmidData().setCircular(true);
break;
}

return partData;
}
}
2 changes: 0 additions & 2 deletions src/main/java/org/jbei/ice/lib/entry/model/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ public class Entry implements IDataModel {
private Sequence sequence;

public Entry() {
// setStatus("Complete");
longDescriptionType = "text";
// setBioSafetyLevel(1);
}

public long getId() {
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/jbei/ice/lib/net/WoRController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@ public boolean isWebEnabled() {
* @return true if partner identified by the id is determined to be a valid
* web of registries partner for part transfer based on the status and authentication key
*/
public boolean isValidWebPartner(String partnerId, String apiKey) throws ControllerException {
try {
RemotePartner partner = dao.getByUrl(partnerId);
return partner != null && partner.getPartnerStatus() == RemotePartnerStatus.APPROVED
&& apiKey != null && apiKey.equalsIgnoreCase(partner.getAuthenticationToken());
} catch (DAOException de) {
throw new ControllerException(de);
}
public boolean isValidWebPartner(String partnerId, String apiKey) {
RemotePartner partner = dao.getByUrl(partnerId);
return partner != null && partner.getPartnerStatus() == RemotePartnerStatus.APPROVED
&& apiKey != null && apiKey.equalsIgnoreCase(partner.getAuthenticationToken());
}

public WebOfRegistries getRegistryPartners(boolean approvedOnly) {
String value = new ConfigurationController().getPropertyValue(
ConfigurationKey.JOIN_WEB_OF_REGISTRIES);
String value = new ConfigurationController().getPropertyValue(ConfigurationKey.JOIN_WEB_OF_REGISTRIES);
WebOfRegistries webOfRegistries = new WebOfRegistries();
webOfRegistries.setWebEnabled("yes".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value));

Expand Down Expand Up @@ -170,6 +165,14 @@ public RegistryPartner addWebPartner(String userId, RegistryPartner partner) {
}
}

/**
* Adds a web of registries partner using the specificd url and name in the parameter
* if another partner does not already exist with the same url
*
* @param url url for ICE instance
* @param name display name for remote ICE instance
* @return created partner
*/
private RegistryPartner addRegistryPartner(String url, String name) {
RemotePartner partner = dao.getByUrl(url);

Expand Down
8 changes: 8 additions & 0 deletions src/main/webapp/css/ice.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ html, body {
color: #CC3333;
}

.orange {
color: orange;
}

.dark_blue {
color: #285e8e;
}

.font-95em {
font-size: 0.95em;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<a href="http://public-registry.jbei.org/manual">Help</a>
</td>
<td align="left" style="vertical-align: top;">
<div ng-if="appVersion">&nbsp; | &nbsp; v{{appVersion}}</div>
<div ng-if="appVersion">&nbsp; | &nbsp; v4.1.2</div>
</td>
</tr>
</table>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/scripts/admin/admin.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="container-fluid">
<div class="container-fluid" ng-controller="AdminController">
<div class="row entry_general_header_td" style="height: 60px">

<div class="col-md-12">
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/scripts/admin/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ angular.module('ice.admin.controller', [])
// retrieve site wide settings
var settings = Settings(sessionId);
settings.get(function (result) {
$rootScope.settings = result;

angular.forEach($rootScope.settings, function (setting) {
angular.forEach(result, function (setting) {
if (generalSettingKeys.indexOf(setting.key) != -1) {
$scope.generalSettings.push({'key':(setting.key.replace(/_/g, ' ')).toLowerCase(), 'value':setting.value, 'editMode':false});
}
Expand Down
54 changes: 17 additions & 37 deletions src/main/webapp/scripts/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,20 +711,6 @@ iceControllers.controller('CollectionController', function ($scope, $state, $fil

// retrieve site wide settings
var settings = Settings(sessionId);
settings.get(function (result) {

for (var i = 0; i < result.length; i += 1) {
$rootScope.settings[result[i].key] = result[i].value;
}
});

$scope.appVersion = undefined;
settings.version({}, function (result) {
$rootScope.appVersion = result.value;
}, function (error) {
console.log(error);
});

$scope.pageCounts = function (currentPage, resultCount) {
var maxPageCount = 15;
var pageNum = ((currentPage - 1) * maxPageCount) + 1;
Expand All @@ -738,12 +724,12 @@ iceControllers.controller('CollectionController', function ($scope, $state, $fil

// default list of collections
$scope.collectionList = [
{ name:'available', display:'Available', icon:'fa-folder', iconOpen:'fa-folder-open', alwaysVisible:true},
{ name:'available', display:'Featured', icon:'fa-certificate', iconOpen:'fa-sun-o orange', alwaysVisible:true},
{ name:'personal', display:'Personal', icon:'fa-folder', iconOpen:'fa-folder-open', alwaysVisible:true},
{ name:'shared', display:'Shared', icon:'fa-share-alt', iconOpen:'fa-share-alt', alwaysVisible:false},
{ name:'drafts', display:'Drafts', icon:'fa-edit', iconOpen:'fa-edit', alwaysVisible:false},
{ name:'pending', display:'Pending Approval', icon:'fa-folder', iconOpen:'fa-folder-open', alwaysVisible:false},
{ name:'deleted', display:'Deleted', icon:'fa-trash-o', iconOpen:'fa-trash', alwaysVisible:false}
{ name:'shared', display:'Shared', icon:'fa-share-alt', iconOpen:'fa-share-alt green', alwaysVisible:false},
{ name:'drafts', display:'Drafts', icon:'fa-edit', iconOpen:'fa-edit blue', alwaysVisible:false},
{ name:'pending', display:'Pending Approval', icon:'fa-support', iconOpen:'fa-support orange', alwaysVisible:false},
{ name:'deleted', display:'Deleted', icon:'fa-trash-o', iconOpen:'fa-trash red', alwaysVisible:false}
];

// entry items that can be created
Expand Down Expand Up @@ -1480,24 +1466,13 @@ iceControllers.controller('CreateEntryController',
entry.query({partId:type}, function (result) {
if (isMain) { // or if !$scope.part
$scope.part = result;
$scope.part.bioSafetyLevel = '1';
$scope.part = EntryService.setNewEntryFields($scope.part);
$scope.part.linkedParts = [];
$scope.part.links = [
{value:''}
];
$scope.part.selectionMarkers = [
{value:''}
];
$scope.part.status = 'Complete';
$scope.activePart = $scope.part;
$scope.selectedFields = EntryService.getFieldsForType($scope.createType);
} else {
var newPart = result;
newPart.links = [];
newPart.selectionMarkers = [];
newPart.bioSafetyLevel = '1';
newPart.status = 'Complete';

newPart = EntryService.setNewEntryFields(newPart);
$scope.selectedFields = EntryService.getFieldsForType(type);
$scope.part.linkedParts.push(newPart);

Expand Down Expand Up @@ -1529,6 +1504,8 @@ iceControllers.controller('CreateEntryController',
entry.query({partId:$model.id}, function (result) {
$scope.activePart = result;
$scope.activePart.isExistingPart = true;
if (!$scope.activePart.parameters)
$scope.activePart.parameters = [];
$scope.addExisting = false;
$scope.part.linkedParts.push($scope.activePart);

Expand Down Expand Up @@ -1666,15 +1643,18 @@ iceControllers.controller('CreateEntryController',
};
$scope.today();

// $scope.showWeeks = true;
// $scope.toggleWeeks = function () {
// $scope.showWeeks = ! $scope.showWeeks;
// };

$scope.clear = function () {
$scope.dt = null;
};

$scope.addCustomParameter = function () {
$scope.activePart.parameters.push({key:'', value:''});
};

$scope.removeCustomParameter = function (index) {
$scope.activePart.parameters.splice(index, 1);
};

$scope.dateOptions = {
'year-format':"'yy'",
'starting-day':1
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/scripts/ice.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ iceApp.config(function ($locationProvider, $stateProvider, $urlRouterProvider) {
.state('main.admin', {
url:'admin',
templateUrl:'/scripts/admin/admin.html',
controller:'AdminController',
resolve:{
sessionValid:function (Authentication) {
return Authentication.isSessionValid() && Authentication.isAdmin();
Expand Down
Loading

0 comments on commit 2b1268d

Please sign in to comment.