use of org.entando.entando.aps.system.services.oauth2.model.ApiConsumer in project entando-core by entando.
the class ApiConsumerControllerIntegrationTest method getPayload.
private ApiConsumer getPayload() {
ApiConsumer consumer = new ApiConsumer();
consumer.setKey(CONSUMER_KEY_3);
consumer.setName("Consumer 1");
consumer.setDescription("descr");
consumer.setSecret("secret");
consumer.setExpirationDate(EXPIRATION_DATE);
consumer.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "implicit"));
consumer.setScope("scope");
consumer.setCallbackUrl("http://entando.org");
return consumer;
}
use of org.entando.entando.aps.system.services.oauth2.model.ApiConsumer in project entando-core by entando.
the class ApiConsumerControllerIntegrationTest method testCRUDConsumer.
@Test
public void testCRUDConsumer() throws Exception {
try {
ApiConsumer consumer = getPayload();
// Create
ResultActions result = authRequest(post(BASE_URL).content(jsonMapper.writeValueAsString(consumer)));
result.andExpect(status().isCreated()).andExpect(jsonPath("$.payload.key", is(CONSUMER_KEY_3))).andExpect(jsonPath("$.payload.name", is(consumer.getName()))).andExpect(jsonPath("$.payload.description", is(consumer.getDescription()))).andExpect(jsonPath("$.payload.secret").doesNotExist()).andExpect(jsonPath("$.payload.issuedDate").isNotEmpty()).andExpect(jsonPath("$.payload.expirationDate", is(EXPIRATION_DATE))).andExpect(jsonPath("$.payload.scope", is(consumer.getScope()))).andExpect(jsonPath("$.payload.callbackUrl", is(consumer.getCallbackUrl()))).andExpect(jsonPath("$.payload.authorizedGrantTypes", hasSize(2))).andExpect(jsonPath("$.payload.authorizedGrantTypes", contains("authorization_code", "implicit")));
// Secret must be serialized but not deserialized
assertThat(consumerManager.getConsumerRecord(CONSUMER_KEY_3).getSecret()).isNotNull();
// Read
result = authRequest(get(BASE_URL + "/" + CONSUMER_KEY_3));
result.andExpect(status().isOk()).andExpect(jsonPath("$.payload.key", is(CONSUMER_KEY_3))).andExpect(jsonPath("$.payload.name", is(consumer.getName()))).andExpect(jsonPath("$.payload.description", is(consumer.getDescription()))).andExpect(jsonPath("$.payload.secret").doesNotExist()).andExpect(jsonPath("$.payload.issuedDate").isNotEmpty()).andExpect(jsonPath("$.payload.expirationDate", is(EXPIRATION_DATE))).andExpect(jsonPath("$.payload.scope", is(consumer.getScope()))).andExpect(jsonPath("$.payload.callbackUrl", is(consumer.getCallbackUrl()))).andExpect(jsonPath("$.payload.authorizedGrantTypes", hasSize(2))).andExpect(jsonPath("$.payload.authorizedGrantTypes", contains("authorization_code", "implicit")));
// Update
String updatedName = "updated_name";
consumer.setName(updatedName);
result = authRequest(put(BASE_URL + "/" + CONSUMER_KEY_3).content(jsonMapper.writeValueAsString(consumer)));
result.andExpect(status().isOk()).andExpect(jsonPath("$.payload.key", is(CONSUMER_KEY_3))).andExpect(jsonPath("$.payload.issuedDate").isNotEmpty()).andExpect(jsonPath("$.payload.name", is(updatedName)));
assertThat(consumerManager.getConsumerRecord(CONSUMER_KEY_3).getName()).isEqualTo(updatedName);
// Delete
result = authRequest(delete(BASE_URL + "/" + CONSUMER_KEY_3));
result.andExpect(status().isOk()).andExpect(jsonPath("$.payload", is(CONSUMER_KEY_3)));
assertThat(consumerManager.getConsumerRecord(CONSUMER_KEY_3)).isNull();
} catch (Throwable t) {
throw t;
} finally {
consumerManager.deleteConsumer(CONSUMER_KEY_3);
}
}
use of org.entando.entando.aps.system.services.oauth2.model.ApiConsumer in project entando-core by entando.
the class ApiConsumerControllerTest method testKeyMismatch.
@Test
public void testKeyMismatch() throws Exception {
ApiConsumer apiConsumer = getValidPayload();
ResultActions result = authRequest(put(BASE_URL + "/different_key").content(jsonMapper.writeValueAsString(apiConsumer)));
result.andExpect(status().is4xxClientError()).andExpect(jsonPath("$.errors", hasSize(1))).andExpect(jsonPath("$.errors[0].code", is("3")));
}
use of org.entando.entando.aps.system.services.oauth2.model.ApiConsumer in project entando-core by entando.
the class ApiConsumerValidator method validate.
@Override
public void validate(Object target, Errors errors) {
if (target instanceof ApiConsumer) {
ApiConsumer consumer = (ApiConsumer) target;
validateGrantTypes(consumer.getAuthorizedGrantTypes(), errors);
validateDate(consumer.getIssuedDate(), "issuedDate", errors);
validateDate(consumer.getExpirationDate(), "expirationDate", errors);
}
}
use of org.entando.entando.aps.system.services.oauth2.model.ApiConsumer in project entando-core by entando.
the class ApiConsumerServiceImpl method update.
@Override
public ApiConsumer update(ApiConsumer consumer) throws ApsSystemException {
ConsumerRecordVO record = consumerManager.getConsumerRecord(consumer.getKey());
if (record == null) {
throw new ResourceNotFoundException(ApiConsumer.class.getName(), consumer.getKey());
}
ConsumerRecordVO updatedRecord = consumer.toConsumerRecordVO();
updatedRecord.setIssuedDate(record.getIssuedDate());
return new ApiConsumer(consumerManager.updateConsumer(updatedRecord));
}
Aggregations