use of org.jbei.ice.lib.dto.access.AccessKey in project ice by JBEI.
the class ApiKeyResource method createApiKey.
/**
* creates an api-key for the specified client id
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createApiKey(@QueryParam("client_id") String clientId) {
String userId = requireUserId();
if (StringUtils.isEmpty(clientId))
throw new WebApplicationException(Response.Status.BAD_REQUEST);
log(userId, "creating api key for client: " + clientId);
UserApiKeys apiKeys = new UserApiKeys(userId);
AccessKey key = apiKeys.requestKey(clientId);
if (key == null)
throw new WebApplicationException("Could not create api key with client id " + clientId);
return super.respond(key);
}
use of org.jbei.ice.lib.dto.access.AccessKey in project ice by JBEI.
the class TokenVerificationTest method testVerifyAPIKey.
@Test
public void testVerifyAPIKey() throws Exception {
Account account = AccountCreator.createTestAccount("testVerifyAPIKey", true);
String userId = account.getEmail();
UserApiKeys keys = new UserApiKeys(userId);
AccessKey key = keys.requestKey("test.jbei.org");
String verified = verification.verifyAPIKey(key.getToken(), key.getClientId(), userId);
Assert.assertEquals(verified, userId);
// verify for another user (cannot use someone else's token)
Account account1 = AccountCreator.createTestAccount("testVerifyAPIKey2", false);
String userId1 = account1.getEmail();
Assert.assertEquals(userId1, verification.verifyAPIKey(key.getToken(), key.getClientId(), userId1));
}
use of org.jbei.ice.lib.dto.access.AccessKey in project ice by JBEI.
the class UserApiKeysTest method testGetKeys.
@Test
public void testGetKeys() throws Exception {
Account account = AccountCreator.createTestAccount("UserApiKeysTest.testGetKeys", false);
Account admin = AccountCreator.createTestAccount("UserApiKeysTest.testGetKeys.Admin", true);
UserApiKeys apiKeys = new UserApiKeys(account.getEmail());
AccessKey accessKey = apiKeys.requestKey("app.test.3");
Assert.assertNotNull(accessKey);
Assert.assertNotNull(accessKey.getToken());
AccessKey accessKey2 = apiKeys.requestKey("app.test.4");
Assert.assertNotNull(accessKey2);
Assert.assertNotNull(accessKey2.getToken());
UserApiKeys adminApiKeys = new UserApiKeys(admin.getEmail());
AccessKey adminKey = adminApiKeys.requestKey("admin.app.test");
Assert.assertNotNull(adminKey);
Results<AccessKey> keys = apiKeys.getKeys(15, 0, "creationTime", true, false);
Assert.assertEquals(2, keys.getResultCount());
Assert.assertTrue(adminApiKeys.getKeys(15, 0, "creationTime", true, true).getResultCount() >= 3);
}
Aggregations