Search in sources :

Example 6 with AccessKey

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);
}
Also used : UserApiKeys(org.jbei.ice.lib.account.UserApiKeys) AccessKey(org.jbei.ice.lib.dto.access.AccessKey)

Example 7 with AccessKey

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));
}
Also used : Account(org.jbei.ice.storage.model.Account) UserApiKeys(org.jbei.ice.lib.account.UserApiKeys) AccessKey(org.jbei.ice.lib.dto.access.AccessKey)

Example 8 with AccessKey

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);
}
Also used : Account(org.jbei.ice.storage.model.Account) AccessKey(org.jbei.ice.lib.dto.access.AccessKey) Test(org.junit.Test)

Aggregations

AccessKey (org.jbei.ice.lib.dto.access.AccessKey)8 Account (org.jbei.ice.storage.model.Account)5 Test (org.junit.Test)3 UserApiKeys (org.jbei.ice.lib.account.UserApiKeys)2 ApiKey (org.jbei.ice.storage.model.ApiKey)2 Date (java.util.Date)1 PermissionException (org.jbei.ice.lib.access.PermissionException)1 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)1 Results (org.jbei.ice.lib.dto.common.Results)1 DAOException (org.jbei.ice.storage.DAOException)1