List of usage examples for org.springframework.security.oauth2.common OAuth2AccessToken BEARER_TYPE
String BEARER_TYPE
To view the source code for org.springframework.security.oauth2.common OAuth2AccessToken BEARER_TYPE.
Click Source Link
From source file:com.example.oauth.AccessToken.java
@Override public String getTokenType() { return OAuth2AccessToken.BEARER_TYPE; }
From source file:org.joyrest.oauth2.handler.OAuthExceptionConfiguration.java
private void process(Request<?> req, Response<OAuth2Exception> resp, OAuth2Exception ex) { resp.entity(ex);/*from ww w . j a v a 2 s. co m*/ int status = ex.getHttpErrorCode(); resp.status(HttpStatus.of(status)); resp.header(CACHE_CONTROL, "no-store"); resp.header(PRAGMA, "no-cache"); if (status == HttpStatus.UNAUTHORIZED.code() || (ex instanceof InsufficientScopeException)) { resp.header(WWW_AUTHENTICATE, String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, ex.getSummary())); } }
From source file:org.zalando.stups.oauth2.spring.client.StupsTokensAccessTokenProvider.java
@Override public OAuth2AccessToken obtainAccessToken(final OAuth2ProtectedResourceDetails details, final AccessTokenRequest parameters) { final AccessToken accessToken; try {/*ww w.j av a 2 s.co m*/ accessToken = tokens.getAccessToken(tokenId); } catch (final AccessTokenUnavailableException e) { throw new OAuth2Exception("Could not obtain access token.", e); } final Map<String, String> tokenParams = new HashMap<>(); tokenParams.put(ACCESS_TOKEN, accessToken.getToken()); tokenParams.put(TOKEN_TYPE, OAuth2AccessToken.BEARER_TYPE); tokenParams.put(EXPIRES_IN, secondsTo(accessToken.getValidUntil())); return DefaultOAuth2AccessToken.valueOf(tokenParams); }
From source file:org.joyrest.oauth2.interceptor.AuthenticationInterceptor.java
private Optional<String> extractHeaderToken(InternalRequest<Object> req) { return req.getHeader("Authorization") .filter(value -> value.toLowerCase().startsWith(OAuth2AccessToken.BEARER_TYPE.toLowerCase())) .map(value -> value.substring(OAuth2AccessToken.BEARER_TYPE.length()).trim()).map(value -> { int commaIndex = value.indexOf(','); if (commaIndex > 0) { return value.substring(0, commaIndex); }/* ww w .j a v a 2s .co m*/ return null; }); }
From source file:org.appverse.web.framework.backend.security.oauth2.resourceserver.handlers.OAuth2LogoutHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { // We get the token and then we remove it from the tokenStore // We have to take into account that the OAuth2 spec allows the access token to be passed // in the authorization header or as a parameter String authorizationHeader = request.getHeader("authorization"); String accessToken = null;// w w w . j a va2 s . c o m if (authorizationHeader != null) { String authorizationType = authorizationHeader.substring(0, OAuth2AccessToken.BEARER_TYPE.length()); if (authorizationType.equalsIgnoreCase(OAuth2AccessToken.BEARER_TYPE)) { accessToken = authorizationHeader.substring(OAuth2AccessToken.BEARER_TYPE.length()).trim(); } } else { accessToken = request.getParameter("access_token"); } if (accessToken != null) { final OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(accessToken); if (oAuth2AccessToken != null) { tokenStore.removeAccessToken(oAuth2AccessToken); } } response.setStatus(HttpServletResponse.SC_OK); }
From source file:it.reply.orchestrator.controller.TemplateControllerTest.java
@Test public void getTemplate() throws Exception { Deployment deployment = ControllerTestUtils.createDeployment(); String template = new NoNullOrEmptyFile(new Utf8File(Paths.get(templatePath))).read(); deployment.setTemplate(template);/*from ww w . j a va2s. c om*/ Mockito.when(templateService.getTemplate(deployment.getId())).thenReturn(deployment.getTemplate()); MvcResult result = mockMvc .perform(get("/deployments/" + deployment.getId() + "/template") .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")) .andExpect(status().isOk()) .andExpect(content().contentType(new MediaType(MediaType.TEXT_PLAIN.getType(), MediaType.TEXT_PLAIN.getSubtype(), Charset.forName("ISO-8859-1")))) .andDo(document("get-template")).andReturn(); String content = result.getResponse().getContentAsString(); assertEquals(content, template); }
From source file:it.smartcommunitylab.aac.controller.TokenIntrospectionController.java
@ApiOperation(value = "Get token metadata") @RequestMapping(method = RequestMethod.POST, value = "/token_introspection") public ResponseEntity<AACTokenIntrospection> getTokenInfo(@RequestParam String token) { AACTokenIntrospection result = new AACTokenIntrospection(); try {/* w w w .j ava2 s .c o m*/ OAuth2Authentication auth = resourceServerTokenServices.loadAuthentication(token); OAuth2AccessToken storedToken = tokenStore.getAccessToken(auth); String clientId = auth.getOAuth2Request().getClientId(); String userName = null; String userId = null; boolean applicationToken = false; if (auth.getPrincipal() instanceof User) { User principal = (User) auth.getPrincipal(); userId = principal.getUsername(); } else { ClientDetailsEntity client = clientDetailsRepository.findByClientId(clientId); applicationToken = true; userId = "" + client.getDeveloperId(); } userName = userManager.getUserInternalName(Long.parseLong(userId)); String localName = userName.substring(0, userName.lastIndexOf('@')); String tenant = userName.substring(userName.lastIndexOf('@') + 1); result.setUsername(localName); result.setClient_id(clientId); result.setScope(StringUtils.collectionToDelimitedString(auth.getOAuth2Request().getScope(), " ")); result.setExp((int) (storedToken.getExpiration().getTime() / 1000)); result.setIat(result.getExp() - storedToken.getExpiresIn()); result.setIss(issuer); result.setNbf(result.getIat()); result.setSub(userId); result.setAud(clientId); // jti is not supported in this form // only bearer tokens supported result.setToken_type(OAuth2AccessToken.BEARER_TYPE); result.setActive(true); result.setAac_user_id(userId); result.setAac_grantType(auth.getOAuth2Request().getGrantType()); result.setAac_applicationToken(applicationToken); result.setAac_am_tenant(tenant); } catch (Exception e) { logger.error("Error getting info for token: " + e.getMessage()); result = new AACTokenIntrospection(); result.setActive(false); } return ResponseEntity.ok(result); }
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(//from w w w . j a v a 2 s . c om 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:org.openinfinity.sso.common.ss.sp.filters.OAuthAuthenticationFilter.java
private String parseAccessTokenFromHeaderValue(final String authHeader) { if ((authHeader.toLowerCase().startsWith(OAuth2AccessToken.BEARER_TYPE.toLowerCase()))) { String authHeaderValue = authHeader.substring(OAuth2AccessToken.BEARER_TYPE.length()).trim(); int commaIndex = authHeaderValue.indexOf(','); if (commaIndex > 0) { authHeaderValue = authHeaderValue.substring(0, commaIndex); }//www . j a va 2 s . c om LOG.debug("OAuth token {} found", authHeaderValue); return authHeaderValue; } else { // todo: support additional authorization schemes for // different token types, e.g. "MAC" specified by // http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token } LOG.warn("No OAuth token found in Mule event!"); return null; }
From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java
@Test public void getDeployments() throws Exception { List<Deployment> deployments = ControllerTestUtils.createDeployments(2, true); deployments.get(0).setStatus(Status.CREATE_FAILED); deployments.get(0).setStatusReason("Some reason"); deployments.get(1).setStatus(Status.CREATE_COMPLETE); Pageable pageable = ControllerTestUtils.createDefaultPageable(); Mockito.when(deploymentService.getDeployments(pageable)).thenReturn(new PageImpl<Deployment>(deployments)); mockMvc.perform(get("/deployments").accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andDo(document("authentication", requestHeaders(/*from www . j ava 2 s. co m*/ headerWithName(HttpHeaders.AUTHORIZATION).description("OAuth2 bearer token")))) .andDo(document("deployments", 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[].updateTime").description("Update date-time"), fieldWithPath("content[].status").description( "The status of the deployment. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Status.html)"), fieldWithPath("content[].statusReason").description( "Verbose explanation of reason that lead to the deployment status (Present only if the deploy is in some error status)"), fieldWithPath("content[].task").description( "The current step of the deployment process. (http://indigo-dc.github.io/orchestrator/apidocs/it/reply/orchestrator/enums/Task.html)"), fieldWithPath("content[].callback").description( "The endpoint used by the orchestrator to notify the progress of the deployment process."), fieldWithPath("content[].outputs").description("The outputs of the TOSCA document"), fieldWithPath("content[].links[]").ignored(), fieldWithPath("page").ignored()))); }