Search in sources :

Example 16 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class TokenVerificationTest method testVerifyPartnerToken.

@Test
public void testVerifyPartnerToken() throws Exception {
    RemotePartner remotePartner = new RemotePartner();
    remotePartner.setName("jbei-test");
    remotePartner.setUrl("test.jbei.org");
    remotePartner.setPartnerStatus(RemotePartnerStatus.APPROVED);
    TokenHash tokenHash = new TokenHash();
    remotePartner.setSalt(tokenHash.generateSalt());
    String token = tokenHash.generateRandomToken();
    String hash = tokenHash.encrypt(token + remotePartner.getUrl(), remotePartner.getSalt());
    remotePartner.setAuthenticationToken(hash);
    remotePartner.setApiKey("foo");
    remotePartner.setAdded(new Date());
    Assert.assertNotNull(DAOFactory.getRemotePartnerDAO().create(remotePartner));
    Assert.assertNotNull(verification.verifyPartnerToken(remotePartner.getUrl(), token));
}
Also used : RemotePartner(org.jbei.ice.storage.model.RemotePartner) TokenHash(org.jbei.ice.lib.account.TokenHash) Date(java.util.Date) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest) Test(org.junit.Test)

Example 17 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class RemoteUsers method get.

public RemoteUser get(long partnerId, String email) {
    RemotePartnerDAO remotePartnerDAO = DAOFactory.getRemotePartnerDAO();
    RemotePartner remotePartner = remotePartnerDAO.get(partnerId);
    if (remotePartner == null)
        return null;
    RemoteContact remoteContact = new RemoteContact();
    AccountTransfer accountTransfer = remoteContact.getUser(remotePartner.getUrl(), email, remotePartner.getApiKey());
    if (accountTransfer == null)
        return null;
    RemoteUser remoteUser = new RemoteUser();
    remoteUser.setPartner(remotePartner.toDataTransferObject());
    remoteUser.setUser(accountTransfer);
    return remoteUser;
}
Also used : RemotePartnerDAO(org.jbei.ice.storage.hibernate.dao.RemotePartnerDAO) RemoteContact(org.jbei.ice.lib.net.RemoteContact) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 18 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class WebEntries method getPart.

/**
 * Checks the local database for the entry with id <code>recordId</code>
 * If it exists locally and is public, it returns it. Otherwise it checks the
 * other ICE instances that it partners with, in turn, to see if it exists on there
 *
 * @param recordId unique record identifier for the desired entry
 * @return entry details if found, else null
 * @throws PermissionException if the entry exists locally but is not a public entry
 */
public PartData getPart(String recordId) {
    // check local first
    Entry entry = this.entryDAO.getByRecordId(recordId);
    if (entry != null && entry.getVisibility() != Visibility.REMOTE.getValue()) {
        PermissionsController permissionsController = new PermissionsController();
        if (permissionsController.isPubliclyVisible(entry))
            return ModelToInfoFactory.getInfo(entry);
    }
    List<RemotePartner> partners = this.remotePartnerDAO.getRegistryPartners();
    for (RemotePartner partner : partners) {
        if (partner.getPartnerStatus() != RemotePartnerStatus.APPROVED)
            continue;
        PartData partData = this.remoteContact.getPublicEntry(partner.getUrl(), recordId, partner.getApiKey());
        // if the part is just a remote then the main one is on some other ICE instance
        if (partData == null || partData.getVisibility() == Visibility.REMOTE)
            continue;
        return partData;
    }
    return null;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemotePartner(org.jbei.ice.storage.model.RemotePartner) PartData(org.jbei.ice.lib.dto.entry.PartData) PermissionsController(org.jbei.ice.lib.access.PermissionsController)

Example 19 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class RemotePartnerDAO method getByUrl.

/**
 * Retrieves remote partners by url. the url is also a unique identifier
 * for a partner
 *
 * @param url partner url to retrieve by
 * @return partner is found, null otherwise
 */
public RemotePartner getByUrl(String url) {
    try {
        CriteriaQuery<RemotePartner> query = getBuilder().createQuery(RemotePartner.class);
        Root<RemotePartner> from = query.from(RemotePartner.class);
        query.where(getBuilder().equal(from.get("url"), url));
        Optional<RemotePartner> result = currentSession().createQuery(query).uniqueResultOptional();
        if (result.isPresent())
            return result.get();
        return null;
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) RemotePartner(org.jbei.ice.storage.model.RemotePartner)

Example 20 with RemotePartner

use of org.jbei.ice.storage.model.RemotePartner in project ice by JBEI.

the class RemotePartnerDAO method getRegistryPartners.

public List<RemotePartner> getRegistryPartners() {
    try {
        CriteriaQuery<RemotePartner> query = getBuilder().createQuery(RemotePartner.class);
        query.from(RemotePartner.class);
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) RemotePartner(org.jbei.ice.storage.model.RemotePartner)

Aggregations

RemotePartner (org.jbei.ice.storage.model.RemotePartner)34 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)10 Account (org.jbei.ice.storage.model.Account)8 PermissionException (org.jbei.ice.lib.access.PermissionException)7 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)6 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteAccessModel (org.jbei.ice.storage.model.RemoteAccessModel)4 Test (org.junit.Test)4 PartData (org.jbei.ice.lib.dto.entry.PartData)3 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)3 Entry (org.jbei.ice.storage.model.Entry)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HibernateException (org.hibernate.HibernateException)2 AccountController (org.jbei.ice.lib.account.AccountController)2 IceRestClient (org.jbei.ice.services.rest.IceRestClient)2 DAOException (org.jbei.ice.storage.DAOException)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2