Search in sources :

Example 6 with AccountController

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;
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountController(org.jbei.ice.lib.account.AccountController)

Example 7 with AccountController

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;
    }
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) IceRestClient(org.jbei.ice.services.rest.IceRestClient) AccountController(org.jbei.ice.lib.account.AccountController)

Example 8 with AccountController

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;
}
Also used : Account(org.jbei.ice.storage.model.Account) Date(java.util.Date) AccountController(org.jbei.ice.lib.account.AccountController)

Example 9 with AccountController

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;
}
Also used : Account(org.jbei.ice.storage.model.Account) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) AccountController(org.jbei.ice.lib.account.AccountController)

Example 10 with AccountController

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) Configuration(org.jbei.ice.storage.model.Configuration) WoRController(org.jbei.ice.lib.net.WoRController) AccountController(org.jbei.ice.lib.account.AccountController)

Aggregations

AccountController (org.jbei.ice.lib.account.AccountController)15 Account (org.jbei.ice.storage.model.Account)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 GroupController (org.jbei.ice.lib.group.GroupController)3 Configuration (org.jbei.ice.storage.model.Configuration)3 ArrayList (java.util.ArrayList)2 ConfigurationKey (org.jbei.ice.lib.dto.ConfigurationKey)2 Group (org.jbei.ice.storage.model.Group)2 RemotePartner (org.jbei.ice.storage.model.RemotePartner)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)1 ConfigurationController (org.jbei.ice.lib.config.ConfigurationController)1 Setting (org.jbei.ice.lib.dto.Setting)1 Results (org.jbei.ice.lib.dto.common.Results)1 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1