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