Search in sources :

Example 1 with UserApiKeys

use of org.jbei.ice.lib.account.UserApiKeys in project ice by JBEI.

the class ApiKeyResource method getApiKeys.

/**
     * retrieves list of api keys created by user
     */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getApiKeys(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("15") @QueryParam("limit") int limit, @DefaultValue("true") @QueryParam("asc") boolean asc, @DefaultValue("creationTime") @QueryParam("sort") String sort, @DefaultValue("false") @QueryParam("getAll") boolean getAll) {
    String userId = requireUserId();
    UserApiKeys apiKeys = new UserApiKeys(userId);
    try {
        return super.respond(apiKeys.getKeys(limit, offset, sort, asc, getAll));
    } catch (PermissionException pe) {
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) UserApiKeys(org.jbei.ice.lib.account.UserApiKeys)

Example 2 with UserApiKeys

use of org.jbei.ice.lib.account.UserApiKeys 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 3 with UserApiKeys

use of org.jbei.ice.lib.account.UserApiKeys in project ice by JBEI.

the class ApiKeyResource method deleteApiKey.

/**
     * Delete a specified API key
     *
     * @param secret
     * @param clientId
     * @param id
     * @return
     */
@DELETE
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteApiKey(@QueryParam("secret") String secret, @QueryParam("clientId") String clientId, @PathParam("id") long id) {
    String userId = requireUserId();
    UserApiKeys apiKeys = new UserApiKeys(userId);
    return super.respond(apiKeys.deleteKey(id, secret));
}
Also used : UserApiKeys(org.jbei.ice.lib.account.UserApiKeys)

Example 4 with UserApiKeys

use of org.jbei.ice.lib.account.UserApiKeys 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)

Aggregations

UserApiKeys (org.jbei.ice.lib.account.UserApiKeys)4 AccessKey (org.jbei.ice.lib.dto.access.AccessKey)2 PermissionException (org.jbei.ice.lib.access.PermissionException)1 Account (org.jbei.ice.storage.model.Account)1