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));
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations