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.zalando.stups.oauth2.spring.server.TokenInfoResourceServerTokenServicesTest.java
@Test public void buildRequest() { RequestEntity<Void> entity = DefaultTokenInfoRequestExecutor.buildRequestEntity(URI.create(TOKENINFO_URL), "0123456789"); Assertions.assertThat(entity).isNotNull(); Assertions.assertThat(entity.getMethod()).isEqualTo(HttpMethod.GET); Assertions.assertThat(entity.getUrl()).isEqualTo(URI.create(TOKENINFO_URL)); Assertions.assertThat(entity.getHeaders()).containsKey(HttpHeaders.AUTHORIZATION); List<String> authorizationHeader = entity.getHeaders().get(HttpHeaders.AUTHORIZATION); Assertions.assertThat(authorizationHeader).containsExactly("Bearer 0123456789"); Assertions.assertThat(entity.getHeaders()).containsKey(HttpHeaders.ACCEPT); Assertions.assertThat(entity.getHeaders().getAccept()).contains(MediaType.APPLICATION_JSON); }
From source file:am.ik.categolj2.app.authentication.AuthenticationHelper.java
public HttpEntity<MultiValueMap<String, Object>> createRopRequest(String username, String password) { MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); params.add("username", username); params.add("password", password); params.add("grant_type", "password"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); byte[] clientInfo = (adminClientProperties.getClientId() + ":" + adminClientProperties.getClientSecret()) .getBytes(StandardCharsets.UTF_8); String basic = new String(Base64.getEncoder().encode(clientInfo), StandardCharsets.UTF_8); headers.set(com.google.common.net.HttpHeaders.AUTHORIZATION, "Basic " + basic); return new HttpEntity<>(params, headers); }
From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java
@Test public void shouldCreateEntityWithNoBody() { String token = "token"; HttpEntity<String> entity = RequestHelper.createEntity(null, RequestHeaders.init().setAuth(token)); assertThat(entity.getHeaders().get(HttpHeaders.AUTHORIZATION), is(singletonList(BEARER + token))); }
From source file:org.openlmis.fulfillment.service.notification.NotificationServiceTest.java
@Test public void shouldNotifyUser() throws Exception { UserDto user = mock(UserDto.class); when(user.getEmail()).thenReturn(USER_EMAIL); notificationService.notify(user, MAIL_SUBJECT, MAIL_CONTENT); verify(restTemplate).postForObject(eq(new URI(NOTIFICATION_URL)), captor.capture(), eq(Object.class)); assertEquals(singletonList("Bearer " + ACCESS_TOKEN), captor.getValue().getHeaders().get(HttpHeaders.AUTHORIZATION)); assertTrue(reflectionEquals(getNotificationRequest(user), captor.getValue().getBody())); }
From source file:org.openlmis.fulfillment.web.LocalTransferPropertiesControllerIntegrationTest.java
@Test public void shouldUpdateWithDifferentType() { // given//from w ww . j a va2 s .c o m FtpTransferProperties newProperties = new FtpTransferProperties(); newProperties.setId(localTransferProperties.getId()); newProperties.setFacilityId(localTransferProperties.getFacilityId()); newProperties.setProtocol(FTP); newProperties.setServerHost("host"); newProperties.setServerPort(21); newProperties.setRemoteDirectory("remote/dir"); newProperties.setLocalDirectory(LOCAL_DIR); newProperties.setUsername("username"); newProperties.setPassword("password"); newProperties.setPassiveMode(true); // when FtpTransferPropertiesDto propertiesDto = (FtpTransferPropertiesDto) newInstance(newProperties, exporter); propertiesDto.setPassword(newProperties.getPassword()); TransferPropertiesDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", localTransferProperties.getId()) .body(propertiesDto).when().put(ID_URL).then().statusCode(200).extract() .as(TransferPropertiesDto.class); // then assertThat(newInstance(response), instanceOf(FtpTransferProperties.class)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.web.BaseTransferPropertiesControllerIntegrationTest.java
@Test public void shouldUpdateProperties() { // given// ww w. ja v a 2s .co m T oldProperties = generateProperties(); T newProperties = generateProperties(); newProperties.setId(oldProperties.getId()); newProperties.setFacilityId(oldProperties.getFacilityId()); given(transferPropertiesRepository.findOne(newProperties.getId())).willReturn(oldProperties); given(transferPropertiesRepository.save(any(TransferProperties.class))) .willAnswer(new SaveAnswer<TransferProperties>()); // when TransferPropertiesDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", oldProperties.getId()) .body(toDto(newProperties)).when().put(ID_URL).then().statusCode(200).extract() .as(TransferPropertiesDto.class); // then assertTransferProperties((T) TransferPropertiesFactory.newInstance(response)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:com.xyxy.platform.examples.showcase.functional.rest.UserRestFT.java
/** * exchange()?Headers.// w ww .j av a 2 s . co m * xml??. * jdk connection. */ @Test public void getUserAsXML() { // Http Basic? HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(com.google.common.net.HttpHeaders.AUTHORIZATION, Servlets.encodeHttpBasic("admin", "admin")); System.out.println("Http header is" + requestHeaders); HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); try { HttpEntity<UserDTO> response = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, UserDTO.class, 1L); assertThat(response.getBody().getLoginName()).isEqualTo("admin"); assertThat(response.getBody().getName()).isEqualTo("?"); assertThat(response.getBody().getTeamId()).isEqualTo(1); // ?XML HttpEntity<String> xml = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, String.class, 1L); System.out.println("xml output is " + xml.getBody()); } catch (HttpStatusCodeException e) { fail(e.getMessage()); } }
From source file:example.company.UrlLevelSecurityTests.java
@Test public void allowsGetRequestsButRejectsPostForUser() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON.toString()); headers.add(HttpHeaders.AUTHORIZATION, "Basic " + new String(Base64.encode(("greg:turnquist").getBytes()))); mvc.perform(get("/employees").// headers(headers)).// andExpect(content().contentType(MediaTypes.HAL_JSON)).// andExpect(status().isOk()).// andDo(print());//from w w w.ja va 2 s. c o m mvc.perform(post("/employees").// headers(headers)).// andExpect(status().isForbidden()).// andDo(print()); }
From source file:org.openlmis.fulfillment.web.TemplateControllerIntegrationTest.java
@Test public void shouldAddReportTemplate() throws IOException { ClassPathResource podReport = new ClassPathResource("jasperTemplates/proofOfDelivery.jrxml"); try (InputStream podStream = podReport.getInputStream()) { restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.MULTIPART_FORM_DATA_VALUE) .multiPart("file", podReport.getFilename(), podStream) .formParam("name", TEMPLATE_CONTROLLER_TEST).formParam("description", TEMPLATE_CONTROLLER_TEST) .when().post(RESOURCE_URL).then().statusCode(200); }/*from w w w . j a v a2 s.co m*/ assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }