List of usage examples for org.springframework.http HttpHeaders AUTHORIZATION
String AUTHORIZATION
To view the source code for org.springframework.http HttpHeaders AUTHORIZATION.
Click Source Link
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldReturnAvailableRequestingFacilities() { given(orderRepository.getRequestingFacilities(null)) .willReturn(Lists.newArrayList(facilityId, facility2Id)); UUID[] response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).when().get(REQUESTING_FACILITIES_URL).then().extract() .as(UUID[].class); assertThat(response.length, is(equalTo(2))); assertThat(response[0], equalTo(facilityId)); assertThat(response[1], equalTo(facility2Id)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void deleteDeployment() throws Exception { String deploymentId = "mmd34483-d937-4578-bfdb-ebe196bf82dd"; Mockito.doNothing().when(deploymentService).deleteDeployment(deploymentId); mockMvc.perform(delete("/deployments/" + deploymentId).header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isNoContent()) .andDo(document("delete-deployment", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()))); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldReturnAvailableRequestingFacilitiesForGivenSupplyingFacility() { given(orderRepository.getRequestingFacilities(singletonList(facilityId))) .willReturn(Lists.newArrayList(singletonList(facilityId))); given(orderRepository.getRequestingFacilities(singletonList(facility1Id))) .willReturn(Lists.newArrayList(facility2Id)); UUID[] response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).queryParam(SUPPLYING_FACILITY, facility1Id).when() .get(REQUESTING_FACILITIES_URL).then().extract().as(UUID[].class); assertThat(response.length, is(equalTo(1))); assertThat(response[0], equalTo(facility2Id)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldReturnAvailableRequestingFacilitiesForMultipleSupplyingFacilities() { given(orderRepository.getRequestingFacilities(asList(facilityId, facility1Id))) .willReturn(Lists.newArrayList(facilityId)); UUID[] response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).queryParam(SUPPLYING_FACILITY, facilityId) .queryParam(SUPPLYING_FACILITY, facility1Id).when().get(REQUESTING_FACILITIES_URL).then().extract() .as(UUID[].class); assertThat(response.length, is(equalTo(1))); assertThat(response[0], equalTo(facilityId)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldRejectGetRequestWhenUserHasNoRights() { doThrow(new MissingPermissionException(ORDERS_VIEW)).when(permissionService).canViewOrder(any(Order.class)); String response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).pathParam("id", firstOrder.getId()).when().get(ID_URL).then() .statusCode(403).extract().path(MESSAGE_KEY); assertThat(response, is(equalTo(PERMISSION_MISSING))); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldRejectPrintRequestWhenUserHasNoRights() { doThrow(new MissingPermissionException(ORDERS_VIEW)).when(permissionService).canViewOrder(any(Order.class)); String response = restAssured.given().queryParam(FORMAT, CSV) .header(HttpHeaders.AUTHORIZATION, getTokenHeader()).pathParam("id", secondOrder.getId()).when() .get(PRINT_URL).then().statusCode(403).extract().path(MESSAGE_KEY); assertThat(response, is(equalTo(PERMISSION_MISSING))); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldRejectExportRequestWhenUserHasNoRights() { doThrow(new MissingPermissionException(ORDERS_VIEW)).when(permissionService).canViewOrder(any(Order.class)); String response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .pathParam("id", secondOrder.getId()).when().get(EXPORT_URL).then().statusCode(403).extract() .path(MESSAGE_KEY);/*from www .j a v a 2 s . c om*/ assertThat(response, is(equalTo(PERMISSION_MISSING))); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java
@Test public void shouldRejectCreateRequestWhenUserHasNoRights() { doThrow(new MissingPermissionException(ORDERS_EDIT)).when(permissionService) .canEditOrder(any(OrderDto.class)); String response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE).body(firstOrderDto).when().post(RESOURCE_URL).then() .statusCode(403).extract().path(MESSAGE_KEY); assertThat(response, is(equalTo(PERMISSION_MISSING))); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:com.muk.services.api.impl.PayPalPaymentService.java
private String getTokenHeader() { final Cache cache = cacheManager.getCache(ServiceConstants.CacheNames.paymentApiTokenCache); final String token = "paypal"; ValueWrapper valueWrapper = cache.get(token); String cachedHeader = StringUtils.EMPTY; if (valueWrapper == null || valueWrapper.get() == null) { try {/*from w ww .j ava 2 s. com*/ final String value = securityCfgService.getPayPalClientId() + ":" + keystoreService.getPBEKey(securityCfgService.getPayPalClientId()); final HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.add(HttpHeaders.AUTHORIZATION, "Basic " + nonceService.encode(value.getBytes(StandardCharsets.UTF_8))); final MultiValueMap<String, String> body = new LinkedMultiValueMap<String, String>(); body.add("grant_type", "client_credentials"); final HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>( body, headers); final ResponseEntity<JsonNode> response = restTemplate.postForEntity( securityCfgService.getPayPalUri() + "/oauth2/token", request, JsonNode.class); cache.put(token, response.getBody().get("access_token").asText()); valueWrapper = cache.get(token); cachedHeader = (String) valueWrapper.get(); } catch (final IOException ioEx) { LOG.error("Failed read keystore", ioEx); cachedHeader = StringUtils.EMPTY; } catch (final GeneralSecurityException secEx) { LOG.error("Failed to get key", secEx); cachedHeader = StringUtils.EMPTY; } } else { cachedHeader = (String) valueWrapper.get(); } return "Bearer " + cachedHeader; }
From source file:com.muk.services.api.impl.PayPalPaymentService.java
private ResponseEntity<JsonNode> send(String path, JsonNode payload) { final HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); headers.add(HttpHeaders.AUTHORIZATION, getTokenHeader()); return restTemplate.postForEntity(securityCfgService.getPayPalUri() + path, new HttpEntity<JsonNode>(payload, headers), JsonNode.class); }