Search in sources :

Example 1 with ApiConsumer

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;
}
Also used : ApiConsumer(org.entando.entando.aps.system.services.oauth2.model.ApiConsumer)

Example 2 with ApiConsumer

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);
    }
}
Also used : ApiConsumer(org.entando.entando.aps.system.services.oauth2.model.ApiConsumer) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 3 with ApiConsumer

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")));
}
Also used : ApiConsumer(org.entando.entando.aps.system.services.oauth2.model.ApiConsumer) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 4 with ApiConsumer

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);
    }
}
Also used : ApiConsumer(org.entando.entando.aps.system.services.oauth2.model.ApiConsumer)

Example 5 with ApiConsumer

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));
}
Also used : ConsumerRecordVO(org.entando.entando.aps.system.services.oauth2.model.ConsumerRecordVO) ApiConsumer(org.entando.entando.aps.system.services.oauth2.model.ApiConsumer) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Aggregations

ApiConsumer (org.entando.entando.aps.system.services.oauth2.model.ApiConsumer)7 ResultActions (org.springframework.test.web.servlet.ResultActions)3 Test (org.junit.Test)2 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)1 ConsumerRecordVO (org.entando.entando.aps.system.services.oauth2.model.ConsumerRecordVO)1 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)1 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)1