use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class LblLdapAuthentication method checkCreateAccount.
/**
* Intended to be called when the credentials successfully authenticate with ldap.
* Ensures an account exists with the login specified in the parameter which also belongs to the
* LBL/JBEI group.
* <p/>
* Since LBL's LDAP mechanism handles authentication, no password information is
* managed
*
* @param loginId unique login identifier
*/
private Account checkCreateAccount(String loginId) throws AuthenticationException {
AccountController retriever = new AccountController();
Account account = retriever.getByEmail(loginId);
if (account == null) {
account = new Account();
Date currentTime = Calendar.getInstance().getTime();
account.setCreationTime(currentTime);
account.setEmail(getEmail().toLowerCase());
account.setFirstName(getGivenName());
account.setLastName(getSirName());
account.setDescription(getDescription());
account.setPassword("");
account.setInitials("");
account.setIp("");
account.setInstitution("Lawrence Berkeley Laboratory");
account.setModificationTime(currentTime);
account = DAOFactory.getAccountDAO().create(account);
}
return account;
}
use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class UserApiKeys method getKeys.
/**
* Retrieves either list of available keys for current user or all keys.
* If requesting all keys then user must be an administrator
*
* @param limit maximum number of keys to retrieve
* @param offset paging parameter start
* @param sortField field to sort on
* @param asc whether the retrieve order is in ascending order
* @param getAvailable whether to retrieve all available keys or restrict by current user
* @return wrapper around list of retrieved keys including number available
* @throws PermissionException if <code>getAvailable</code> is true but user making the request does not have
* administrative privileges
*/
public Results<AccessKey> getKeys(int limit, int offset, String sortField, boolean asc, boolean getAvailable) {
Results<AccessKey> accessKeyResults = new Results<>();
List<ApiKey> results;
AccountController accountController = new AccountController();
boolean isAdmin = accountController.isAdministrator(this.userId);
if (getAvailable) {
if (!isAdmin)
throw new PermissionException("Cannot retrieve all api keys without admin privileges");
results = apiKeyDAO.getAllApiKeys(sortField, limit, offset, asc);
} else {
results = apiKeyDAO.getApiKeysForUser(userId, sortField, limit, offset, asc);
}
for (ApiKey key : results) {
AccessKey accessKey = key.toDataTransferObject();
Account account = accountController.getByEmail(key.getOwnerEmail());
accessKey.setAccount(account.toDataTransferObject());
accessKeyResults.getData().add(accessKey);
}
// get count
String user = getAvailable ? null : this.userId;
long count = apiKeyDAO.getApiKeysCount(user);
accessKeyResults.setResultCount(count);
return accessKeyResults;
}
use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class LblLdapAuthentication method authenticates.
@Override
public String authenticates(String loginId, String password) throws AuthenticationException {
if (loginId == null || password == null || loginId.isEmpty() || password.isEmpty()) {
throw new AuthenticationException("Username and Password are mandatory!");
}
loginId = loginId.toLowerCase().trim();
String authenticatedEmail;
if (isWikiUser(loginId)) {
try {
authenticatedEmail = authenticateWithLDAP(loginId, password);
if (authenticatedEmail == null) {
return null;
}
} catch (AuthenticationException ae) {
return null;
}
Account account = checkCreateAccount(authenticatedEmail);
if (account == null)
return null;
return account.getEmail();
} else {
LocalAuthentication localBackend = new LocalAuthentication();
return localBackend.authenticates(loginId, password);
}
}
use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class FolderController method getSharedUserFolders.
/**
* Retrieves folders that have been shared with specified user as an individual or as part of a group.
*
* @param userId User whose shared folders are being retrieved
* @return list of folders meeting the shared criteria
*/
public ArrayList<FolderDetails> getSharedUserFolders(String userId) {
Account account = getAccount(userId);
ArrayList<FolderDetails> folderDetails = new ArrayList<>();
Set<Group> groups = account.getGroups();
groups.remove(groupController.createOrRetrievePublicGroup());
List<Folder> sharedFolders = DAOFactory.getPermissionDAO().retrieveFolderPermissions(account, groups);
if (sharedFolders == null)
return null;
for (Folder folder : sharedFolders) {
FolderDetails details = folder.toDataTransferObject();
details.setType(folder.getType());
long folderSize = dao.getFolderSize(folder.getId(), null, true);
details.setCount(folderSize);
if (folder.getCreationTime() != null)
details.setCreationTime(folder.getCreationTime().getTime());
folderDetails.add(details);
}
return folderDetails;
}
use of org.jbei.ice.storage.model.Account in project ice by JBEI.
the class FolderController method getUserFolders.
public ArrayList<FolderDetails> getUserFolders(String userId) {
Account account = getAccount(userId);
List<Folder> folders = dao.getFoldersByOwner(account);
ArrayList<FolderDetails> folderDetails = new ArrayList<>();
for (Folder folder : folders) {
if (!folder.getOwnerEmail().equalsIgnoreCase(userId))
continue;
FolderDetails details = new FolderDetails(folder.getId(), folder.getName());
long folderSize = dao.getFolderSize(folder.getId(), null, true);
details.setCount(folderSize);
details.setType(folder.getType());
if (folder.getCreationTime() != null)
details.setCreationTime(folder.getCreationTime().getTime());
details.setCanEdit(true);
folderDetails.add(details);
}
return folderDetails;
}
Aggregations