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.jasig.portlet.notice.service.rest.UserAttributeParameterEvaluator.java
/** * Obtains information about the user from the Authorization header in the form of an OIDC Id * token. In the future, it would be better to provide a standard tool (bean) for this job in * the <code>uPortal-soffit-renderer</code> component. *//*w w w . j a v a2s . c o m*/ private Jws<Claims> parseOidcToken(HttpServletRequest req) { final String authHeader = req.getHeader(HttpHeaders.AUTHORIZATION); if (StringUtils.isBlank(authHeader) || !authHeader.startsWith(Headers.BEARER_TOKEN_PREFIX)) { /* * No OIDC token available */ return null; } final String bearerToken = authHeader.substring(Headers.BEARER_TOKEN_PREFIX.length()); try { // Validate & parse the JWT final Jws<Claims> rslt = Jwts.parser().setSigningKey(signatureKey).parseClaimsJws(bearerToken); logger.debug("Found the following OIDC Id token: {}", rslt.toString()); return rslt; } catch (Exception e) { logger.info("The following Bearer token is unusable: '{}'", bearerToken); logger.debug("Failed to validate and/or parse the specified Bearer token", e); } return null; }
From source file:org.rippleosi.common.service.proxies.C4HReportingRequestProxy.java
private HttpEntity<String> buildRequest(String body) { String credentials = openEhrUsername + ":" + openEhrPassword; byte[] base64 = Base64.encodeBase64(credentials.getBytes()); String encoded = new String(base64); HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.AUTHORIZATION, "Basic " + encoded); headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new HttpEntity<>(body, headers); }
From source file:org.rippleosi.common.service.proxies.DefaultRequestProxy.java
private HttpEntity<String> buildRequestWithoutSession(String body) { String credentials = openEhrUsername + ":" + openEhrPassword; byte[] base64 = Base64.encodeBase64(credentials.getBytes()); String encoded = new String(base64); HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.AUTHORIZATION, "Basic " + encoded); headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new HttpEntity<>(body, headers); }
From source file:org.springframework.boot.actuate.metrics.atsd.AtsdMetricWriter.java
protected HttpHeaders createHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(ACCEPTABLE_MEDIA_TYPES); headers.setContentType(CONTENT_TYPE); headers.set(HttpHeaders.AUTHORIZATION, this.basicAuthorizationHeader); return headers; }
From source file:org.springframework.cloud.dataflow.server.service.impl.validation.DockerRegistryValidator.java
/** * Verifies that the image is present./*from w w w .ja va 2 s .c om*/ *JobDependencies.java * @return true if image is present. */ public boolean isImagePresent() { boolean result = false; try { String resourceTag = this.appResourceCommon.getResourceVersion(this.dockerResource); HttpHeaders headers = new HttpHeaders(); if (this.dockerAuth != null) { headers.add(HttpHeaders.AUTHORIZATION, DOCKER_REGISTRY_AUTH_TYPE + " " + this.dockerAuth.getToken()); } HttpEntity<String> httpEntity = new HttpEntity<>(headers); String endpointUrl = getDockerTagsEndpointUrl(); do { ResponseEntity tags = this.restTemplate.exchange(endpointUrl, HttpMethod.GET, httpEntity, DockerResult.class); DockerResult dockerResult = (DockerResult) tags.getBody(); for (DockerTag dockerTag : dockerResult.getResults()) { if (dockerTag.getName().equals(resourceTag)) { result = true; break; } } endpointUrl = dockerResult.getNext(); } while (result == false && endpointUrl != null); } catch (HttpClientErrorException hcee) { //when attempting to access an invalid docker image or if you //don't have proper credentials docker returns a 404. logger.info("Unable to find image because of the following exception:", hcee); result = false; } return result; }
From source file:software.coolstuff.springframework.owncloud.service.impl.AbstractOwncloudServiceTest.java
private ResponseActions prepareRestRequest(RestRequest request) throws MalformedURLException { MockRestServiceServer server = this.server; if (request.getServer() != null) { server = request.getServer();// w w w . j av a 2s . c o m } ResponseActions responseActions = server.expect(requestToWithPrefix(request.getUrl())) .andExpect(method(request.getMethod())); if (StringUtils.isNotBlank(request.getBasicAuthentication())) { responseActions.andExpect(header(HttpHeaders.AUTHORIZATION, request.getBasicAuthentication())); } else { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); responseActions .andExpect(header(HttpHeaders.AUTHORIZATION, "Basic " + Base64.getEncoder().encodeToString( (authentication.getName() + ":" + authentication.getCredentials()).getBytes()))); } return responseActions; }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.AbstractOwncloudRestServiceImpl.java
protected String getAuthorizationUserFromHeaders(HttpHeaders headers) { Validate.notNull(headers);/*from w w w.j ava 2s. c o m*/ List<String> authorizations = headers.get(HttpHeaders.AUTHORIZATION); if (CollectionUtils.isEmpty(authorizations)) { return null; } String encodedCredentials = authorizations.get(0); if (StringUtils.startsWith(encodedCredentials, AUTHORIZATION_METHOD_PREFIX)) { encodedCredentials = StringUtils.substring(encodedCredentials, AUTHORIZATION_METHOD_PREFIX.length()); } final byte[] rawDecodedCredentials = Base64.getDecoder().decode(encodedCredentials.getBytes()); final String decodedCredentials = new String(rawDecodedCredentials); if (!StringUtils.contains(decodedCredentials, ':')) { return null; } return StringUtils.split(decodedCredentials, ':')[0]; }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getInputStream_OK(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andRespond(withSuccess( owncloudFileResource.getTestFileContent(), owncloudFileResource.getMediaType())); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getInputStream_NOK_FileNotFound(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")) .andRespond(withStatus(HttpStatus.NOT_FOUND)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getOutputStream_OK(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.PUT)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")) .andExpect(content().contentType(owncloudFileResource.getMediaType())) .andExpect(content().string(owncloudFileResource.getTestFileContent())).andRespond(withSuccess()); }