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.service.request.RequestHeaders.java
public RequestHeaders setAuth(String token) { return isNotBlank(token) ? set(HttpHeaders.AUTHORIZATION, "Bearer " + token) : this; }
From source file:org.trustedanalytics.metadata.parser.RestOperationsFactory.java
public RestOperations oAuth(Authentication authentication) { final String token = tokenRetriever.getAuthToken(authentication); final RestTemplate restTemplate = new RestTemplate(); restTemplate.setInterceptors(Collections .singletonList(new HeaderAddingHttpInterceptor(HttpHeaders.AUTHORIZATION, "bearer " + token))); return restTemplate; }
From source file:org.openlmis.notification.web.NotificationControllerIntegrationTest.java
@Ignore @Test/*from w w w . j av a2 s . co m*/ public void testSendMessage() { NotificationRequest notificationRequest = new NotificationRequest(); notificationRequest.setFrom("from@example.com"); notificationRequest.setTo("to@example.com"); notificationRequest.setSubject("subject"); notificationRequest.setContent("content"); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).body(notificationRequest).when() .post(BASE_URL + "/notification").then().statusCode(200); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:com.angelmmg90.consumerservicespotify.configuration.SpringWebConfig.java
@Bean public static RestTemplate getTemplate() throws IOException { if (template == null) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT), new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD)); Header[] h = new Header[3]; h[0] = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"); h[1] = new BasicHeader(HttpHeaders.AUTHORIZATION, "Bearer " + ACCESS_TOKEN); List<Header> headers = new ArrayList<>(Arrays.asList(h)); HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.useSystemProperties(); clientBuilder.setProxy(new HttpHost(PROXY_HOST, PROXY_PORT)); clientBuilder.setDefaultCredentialsProvider(credentialsProvider); clientBuilder.setDefaultHeaders(headers).build(); String SAMPLE_URL = "https://api.spotify.com/v1/users/yourUserName/playlists/7HHFd1tNiIFIwYwva5MTNv"; HttpUriRequest request = RequestBuilder.get().setUri(SAMPLE_URL).build(); clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); CloseableHttpClient client = clientBuilder.build(); client.execute(request);/*from w ww .jav a 2 s . co m*/ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); factory.setHttpClient(client); template = new RestTemplate(); template.setRequestFactory(factory); } return template; }
From source file:org.openlmis.fulfillment.web.BaseTransferPropertiesControllerIntegrationTest.java
@Test public void shouldCreateProperties() { // given/*from w w w . ja v a 2 s.c o m*/ T properties = generateProperties(); given(transferPropertiesRepository.save(any(TransferProperties.class))) .willAnswer(new SaveAnswer<TransferProperties>()); // when restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).body(toDto(properties)).when().post(RESOURCE_URL) .then().statusCode(201); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:com.devicehive.auth.rest.HttpAuthenticationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Optional<String> authHeader = Optional.ofNullable(httpRequest.getHeader(HttpHeaders.AUTHORIZATION)); String resourcePath = new UrlPathHelper().getPathWithinApplication(httpRequest); logger.debug("Security intercepted request to {}", resourcePath); try {//from w w w. ja va2s . co m if (authHeader.isPresent()) { String header = authHeader.get(); if (header.startsWith(Constants.BASIC_AUTH_SCHEME)) { processBasicAuth(header); } else if (header.startsWith(Constants.TOKEN_SCHEME)) { processJwtAuth(authHeader.get().substring(6).trim()); } } else { processAnonymousAuth(); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication instanceof AbstractAuthenticationToken) { MDC.put("usrinf", authentication.getName()); HiveAuthentication.HiveAuthDetails details = createUserDetails(httpRequest); ((AbstractAuthenticationToken) authentication).setDetails(details); } chain.doFilter(request, response); } catch (InternalAuthenticationServiceException e) { SecurityContextHolder.clearContext(); logger.error("Internal authentication service exception", e); httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (AuthenticationException e) { SecurityContextHolder.clearContext(); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); } finally { MDC.remove("usrinf"); } }
From source file:org.openlmis.fulfillment.web.OrderFileTemplateControllerIntegrationTest.java
@Test public void shouldNotCreateNewOrderFileTemplate() { orderFileTemplateDto = OrderFileTemplateDto.newInstance(orderFileTemplate); restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).body(orderFileTemplateDto).when().post(RESOURCE_URL) .then().statusCode(405);// w w w .j a va 2s .c o m }
From source file:org.openlmis.fulfillment.web.FtpTransferPropertiesControllerIntegrationTest.java
@Test public void shouldUpdateWithDifferentType() { // given//from w ww .j a v a2 s . c om LocalTransferProperties newProperties = new LocalTransferProperties(); newProperties.setId(ftpTransferProperties.getId()); newProperties.setFacilityId(ftpTransferProperties.getFacilityId()); newProperties.setPath("local/path"); // when TransferPropertiesDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).pathParam("id", ftpTransferProperties.getId()) .body(newInstance(newProperties, exporter)).when().put(ID_URL).then().statusCode(200).extract() .as(TransferPropertiesDto.class); // then assertThat(newInstance(response), instanceOf(LocalTransferProperties.class)); assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java
@Test public void shouldCreateEntityWithAnAuthHeader() { String body = "test"; String token = "token"; HttpEntity<String> entity = RequestHelper.createEntity(body, RequestHeaders.init().setAuth(token)); assertThat(entity.getHeaders().get(HttpHeaders.AUTHORIZATION), is(singletonList(BEARER + token))); assertThat(entity.getBody(), is(body)); }
From source file:com.devicehive.websockets.WebSocketAuthenticationManager.java
public HiveAuthentication.HiveAuthDetails getDetails(WebSocketSession session) { List<String> originList = session.getHandshakeHeaders().get(HttpHeaders.ORIGIN); List<String> authList = session.getHandshakeHeaders().get(HttpHeaders.AUTHORIZATION); String origin = originList == null || originList.isEmpty() ? null : originList.get(0); String auth = authList == null || authList.isEmpty() ? null : authList.get(0); return new HiveAuthentication.HiveAuthDetails(session.getRemoteAddress().getAddress(), origin, auth); }