Example usage for org.springframework.http HttpHeaders AUTHORIZATION

List of usage examples for org.springframework.http HttpHeaders AUTHORIZATION

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders AUTHORIZATION.

Prototype

String AUTHORIZATION

To view the source code for org.springframework.http HttpHeaders AUTHORIZATION.

Click Source Link

Document

The HTTP Authorization header field name.

Usage

From source file:it.reply.orchestrator.controller.ResourceControllerTest.java

@Test
public void getResources() throws Exception {
    Pageable pageable = ControllerTestUtils.createDefaultPageable();
    Deployment deployment = ControllerTestUtils.createDeployment();
    List<Resource> resources = ControllerTestUtils.createResources(deployment, 2, true);
    Mockito.when(resourceService.getResources(deployment.getId(), pageable))
            .thenReturn(new PageImpl<Resource>(resources));

    mockMvc.perform(get("/deployments/" + deployment.getId() + "/resources").accept(MediaType.APPLICATION_JSON)
            .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>"))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(2)))
            .andExpect(jsonPath("$.content", org.hamcrest.Matchers.hasSize(2)))
            .andExpect(jsonPath("$.page.totalElements", equalTo(2)))
            .andExpect(jsonPath("$.links[0].rel", is("self")))
            .andExpect(// www . ja v  a2s .co m
                    jsonPath("$.links[0].href", endsWith("/deployments/" + deployment.getId() + "/resources")))

            .andDo(document("resources", preprocessResponse(prettyPrint()), responseFields(
                    fieldWithPath("links[]").ignored(),
                    fieldWithPath("content[].uuid").description("The unique identifier of a resource"),
                    fieldWithPath("content[].creationTime").description(
                            "Creation date-time (http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)"),
                    fieldWithPath("content[].state").description(
                            "The status of the resource. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/NodeStates.html)"),
                    fieldWithPath("content[].toscaNodeType").optional()
                            .description("The type of the represented TOSCA node"),
                    fieldWithPath("content[].toscaNodeName").optional()
                            .description("The name of the represented TOSCA node"),
                    fieldWithPath("content[].requiredBy")
                            .description("A list of nodes that require this resource"),
                    fieldWithPath("content[].links[]").ignored(), fieldWithPath("page").ignored())));

}

From source file:com.devicehive.auth.rest.HttpAuthenticationFilter.java

private HiveAuthentication.HiveAuthDetails createUserDetails(HttpServletRequest request)
        throws UnknownHostException {
    return new HiveAuthentication.HiveAuthDetails(InetAddress.getByName(request.getRemoteAddr()),
            request.getHeader(HttpHeaders.ORIGIN), request.getHeader(HttpHeaders.AUTHORIZATION));
}

From source file:org.openlmis.fulfillment.web.LocalTransferPropertiesControllerIntegrationTest.java

@Test
public void shouldReturnBadRequestWhenCreateWithBlankPath() {
    // given//  w  w  w . j ava2 s  .  c  o m
    localTransferProperties.setPath("");

    // when
    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).body(newInstance(localTransferProperties, exporter))
            .when().post(RESOURCE_URL).then().statusCode(400);

    // then
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.OrderNumberConfigurationControllerIntegrationTest.java

@Test
public void shouldReturnNotFoundWHenThereIsNoOrderNumberConfiguration() {
    given(orderNumberConfigurationRepository.findAll()).willReturn(new ArrayList());

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).when().get(RESOURCE_URL).then().statusCode(404);

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java

@Test
public void shouldDeleteTemplate() {
    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", template.getId()).when()
            .delete(ID_URL).then().statusCode(204);

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.web.OrderFileTemplateControllerIntegrationTest.java

@Test
public void shouldNotUpdateOrderFileTemplateWhenOrderFileColumnContainsWrongFormat() {
    OrderFileColumn orderFileColumn = new OrderFileColumn();
    orderFileColumn.setDataFieldLabel("label");
    orderFileColumn.setColumnLabel("label");
    orderFileColumn.setNested("nested");
    orderFileColumn.setKeyPath("key");
    orderFileColumn.setRelated("yes");
    orderFileColumn.setRelatedKeyPath("yes");
    orderFileColumn.setId(UUID.randomUUID());
    orderFileColumn.setFormat("dddd-mmm-yy");
    orderFileColumn.setInclude(true);/*w  ww . jav  a 2 s.co  m*/
    orderFileColumn.setPosition(1);
    orderFileColumn.setOpenLmisField(true);
    orderFileTemplate.getOrderFileColumns().add(orderFileColumn);

    orderFileTemplateDto = OrderFileTemplateDto.newInstance(orderFileTemplate);

    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader())
            .contentType(MediaType.APPLICATION_JSON_VALUE).body(orderFileTemplateDto).when().put(RESOURCE_URL)
            .then().statusCode(400);

    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:fi.hsl.parkandride.itest.AbstractReportingITest.java

protected static com.jayway.restassured.response.Header authorization(String authToken) {
    return new com.jayway.restassured.response.Header(HttpHeaders.AUTHORIZATION, "Bearer " + authToken);
}

From source file:org.openlmis.fulfillment.web.OrderNumberConfigurationControllerIntegrationTest.java

@Test
public void shouldUpdateOrderNumberConfiguration() {
    OrderNumberConfiguration orderNumberConfiguration = generate("prefix", true, true, true);
    OrderNumberConfigurationDto orderNumberConfigurationDto = OrderNumberConfigurationDto
            .newInstance(orderNumberConfiguration);

    OrderNumberConfigurationDto response = restAssured.given()
            .header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(orderNumberConfigurationDto).when().post(RESOURCE_URL).then().statusCode(200).extract()
            .as(OrderNumberConfigurationDto.class);
    orderNumberConfigurationDto.setId(response.getId());

    assertEquals(response, orderNumberConfigurationDto);
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}

From source file:org.openlmis.fulfillment.service.BaseCommunicationServiceTest.java

protected void assertAuthHeader(HttpEntity entity) {
    assertThat(entity.getHeaders().get(HttpHeaders.AUTHORIZATION), is(singletonList("Bearer " + TOKEN)));
}

From source file:com.xyxy.platform.examples.showcase.functional.rest.UserRestFT.java

/**
 * ?ShiroHttpBasic?/*from  w w w. ja  v  a  2 s.co  m*/
 */
@Test
public void authWithHttpBasic() {
    // Http Basic?
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set(com.google.common.net.HttpHeaders.AUTHORIZATION,
            Servlets.encodeHttpBasic("admin", "wrongpassword"));
    HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);

    try {
        jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, UserDTO.class, 1L);
        fail("Get should fail with error username/password");
    } catch (HttpStatusCodeException e) {
        assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
    }
}