use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.
the class WoRController method removeWebPartner.
/**
* Removes the web partner uniquely identified by the url
*
* @param partnerUrl url identifier for partner
*/
public boolean removeWebPartner(String userId, String partnerUrl) {
if (!new AccountController().isAdministrator(userId))
return false;
RemotePartner partner = dao.getByUrl(partnerUrl);
if (partner == null)
return true;
dao.delete(partner);
return true;
}
use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.
the class WoRController method updateWebPartner.
public boolean updateWebPartner(String userId, String url, RegistryPartner partner) {
if (!new AccountController().isAdministrator(userId))
return false;
Logger.info(userId + ": updating partner (" + url + ") to " + partner.toString());
RemotePartner existing = dao.getByUrl(url);
if (existing == null)
return false;
if (partner.getStatus() == existing.getPartnerStatus())
return true;
// contact remote with new api key that allows them to contact this instance
String apiKey = Utils.generateToken();
String myURL = Utils.getConfigValue(ConfigurationKey.URI_PREFIX);
String myName = Utils.getConfigValue(ConfigurationKey.PROJECT_NAME);
RegistryPartner thisPartner = new RegistryPartner();
thisPartner.setUrl(myURL);
thisPartner.setName(myName);
// key to use in contacting this instance
thisPartner.setApiKey(apiKey);
IceRestClient client = IceRestClient.getInstance();
try {
client.post(partner.getUrl(), "/rest/web/partner/remote", thisPartner, RegistryPartner.class, null);
existing.setPartnerStatus(partner.getStatus());
existing.setAuthenticationToken(apiKey);
dao.update(existing);
return true;
} catch (Exception e) {
Logger.error(e);
return false;
}
}
use of org.jbei.ice.lib.account.AccountController 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.lib.account.AccountController in project ice by JBEI.
the class AccountCreator method createTestAccount.
public static Account createTestAccount(String testName, boolean admin) throws Exception {
String email = testName + "@TESTER";
AccountDAO dao = DAOFactory.getAccountDAO();
Account account = dao.getByEmail(email);
if (account != null)
throw new Exception("duplicate account");
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setFirstName("TEST_FNAME");
accountTransfer.setLastName("TEST");
accountTransfer.setEmail(email);
accountTransfer = new AccountController().createNewAccount(accountTransfer, false);
Assert.assertNotNull(accountTransfer.getPassword());
account = dao.getByEmail(email);
Assert.assertNotNull(account);
if (admin) {
account.setType(AccountType.ADMIN);
dao.update(account);
}
return account;
}
use of org.jbei.ice.lib.account.AccountController in project ice by JBEI.
the class ConfigurationController method updateSetting.
public Setting updateSetting(String userId, Setting setting, String url) {
AccountController accountController = new AccountController();
if (!accountController.isAdministrator(userId))
throw new PermissionException("Cannot update system setting without admin privileges");
ConfigurationKey key = ConfigurationKey.valueOf(setting.getKey());
if (key == null)
throw new IllegalArgumentException("Invalid system key " + setting.getKey());
Configuration configuration = setPropertyValue(key, setting.getValue());
// check if the setting being updated is related to the web of registries
if (key == ConfigurationKey.JOIN_WEB_OF_REGISTRIES) {
WoRController woRController = new WoRController();
boolean enable = "yes".equalsIgnoreCase(setting.getValue()) || "true".equalsIgnoreCase(setting.getValue());
woRController.setEnable(userId, enable, url);
}
return configuration.toDataTransferObject();
}
Aggregations