@Override public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest request) { OAuth2AccessToken accessToken = clientContext.getAccessToken(); if (accessToken == null) { throw new AccessTokenRequiredException(resource); } String tokenType = accessToken.getTokenType(); if (!StringUtils.hasText(tokenType)) { tokenType = OAuth2AccessToken.BEARER_TYPE; // we'll assume basic bearer token type if none is specified. } else if (tokenType.equalsIgnoreCase(OAuth2AccessToken.BEARER_TYPE)) { // gh-1346 tokenType = OAuth2AccessToken.BEARER_TYPE; // Ensure we use the correct syntax for the "Bearer" authentication scheme } request.getHeaders().set("Authorization", String.format("%s %s", tokenType, accessToken.getValue())); }
jgen.writeStartObject(); jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) {
vars.put("token_type", accessToken.getTokenType()); String state = authorizationRequest.getState();
jgen.writeStartObject(); jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) {
url.append("token_type=").append(encode(accessToken.getTokenType()));
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { OAuth2AccessToken accessToken; try { accessToken = restTemplate.getAccessToken(); } catch (OAuth2Exception e) { BadCredentialsException bad = new BadCredentialsException("Could not obtain access token", e); publish(new OAuth2AuthenticationFailureEvent(bad)); throw bad; } try { OAuth2Authentication result = tokenServices.loadAuthentication(accessToken.getValue()); if (authenticationDetailsSource!=null) { request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, accessToken.getValue()); request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_TYPE, accessToken.getTokenType()); result.setDetails(authenticationDetailsSource.buildDetails(request)); } publish(new AuthenticationSuccessEvent(result)); return result; } catch (InvalidTokenException e) { BadCredentialsException bad = new BadCredentialsException("Could not obtain user details from token", e); publish(new OAuth2AuthenticationFailureEvent(bad)); throw bad; } }
/** * Copy constructor for access token. * * @param accessToken */ public DefaultOAuth2AccessToken(OAuth2AccessToken accessToken) { this(accessToken.getValue()); setAdditionalInformation(accessToken.getAdditionalInformation()); setRefreshToken(accessToken.getRefreshToken()); setExpiration(accessToken.getExpiration()); setScope(accessToken.getScope()); setTokenType(accessToken.getTokenType()); }
@Override public String getTokenType() { return oAuth2AccessToken.getTokenType(); }
@Override public String getTokenType() { return oAuth2AccessToken.getTokenType(); }
public void putToken(HashMap<String, String> target, OAuth2AccessToken token) { target.put(ACCESS_TOKEN_KEY, String.format("%s %s", token.getTokenType() .toLowerCase(), token.getValue())); }
public void putToken(HashMap<String, String> target, OAuth2AccessToken token) { target.put(ACCESS_TOKEN_KEY, String.format("%s %s", token.getTokenType().toLowerCase(), token.getValue())); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public void changePassword(String oldPassword, String newPassword) { HttpHeaders headers = new HttpHeaders(); headers.add(AUTHORIZATION_HEADER_KEY, token.getTokenType() + " " + token.getValue()); HttpEntity info = new HttpEntity(headers); ResponseEntity<String> response = restTemplate.exchange(authorizationUrl + "/userinfo", HttpMethod.GET, info, String.class); Map<String, Object> responseMap = JsonUtil.convertJsonToMap(response.getBody()); String userId = (String) responseMap.get("user_id"); Map<String, Object> body = new HashMap<String, Object>(); body.put("schemas", new String[] {"urn:scim:schemas:core:1.0"}); body.put("password", newPassword); body.put("oldPassword", oldPassword); HttpEntity<Map> httpEntity = new HttpEntity<Map>(body, headers); restTemplate.put(authorizationUrl + "/User/{id}/password", httpEntity, userId); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public void changePassword(String oldPassword, String newPassword) { HttpHeaders headers = new HttpHeaders(); headers.add(AUTHORIZATION_HEADER_KEY, token.getTokenType() + " " + token.getValue()); HttpEntity info = new HttpEntity(headers); ResponseEntity<String> response = restTemplate.exchange(authorizationUrl + "/userinfo", HttpMethod.GET, info, String.class); Map<String, Object> responseMap = JsonUtil.convertJsonToMap(response.getBody()); String userId = (String) responseMap.get("user_id"); Map<String, Object> body = new HashMap<String, Object>(); body.put("schemas", new String[] { "urn:scim:schemas:core:1.0" }); body.put("password", newPassword); body.put("oldPassword", oldPassword); HttpEntity<Map> httpEntity = new HttpEntity<Map>(body, headers); restTemplate.put(authorizationUrl + "/User/{id}/password", httpEntity, userId); }
public String getAuthorizationHeader() { OAuth2AccessToken accessToken = getToken(); if (accessToken != null) { return accessToken.getTokenType() + " " + accessToken.getValue(); } return null; }
public String getAuthorizationHeader() { OAuth2AccessToken accessToken = getToken(); if (accessToken != null) { return accessToken.getTokenType() + " " + accessToken.getValue(); } return null; }
@Override public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest request) { OAuth2AccessToken accessToken = clientContext.getAccessToken(); if (accessToken == null) { throw new AccessTokenRequiredException(resource); } String tokenType = accessToken.getTokenType(); if (!StringUtils.hasText(tokenType)) { tokenType = OAuth2AccessToken.BEARER_TYPE; // we'll assume basic bearer token type if none is specified. } else if (tokenType.equalsIgnoreCase(OAuth2AccessToken.BEARER_TYPE)) { // gh-1346 tokenType = OAuth2AccessToken.BEARER_TYPE; // Ensure we use the correct syntax for the "Bearer" authentication scheme } request.getHeaders().set("Authorization", String.format("%s %s", tokenType, accessToken.getValue())); }
@Override public void authenticate( OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest req) { req.getHeaders() .set( "X-Authorization", clientContext.getAccessToken().getTokenType() + " " + "Nah-nah-na-nah-nah"); } };
@Override public void authenticate( OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest req) { req.getHeaders() .set( "X-Authorization", clientContext.getAccessToken().getTokenType() + " " + "Nah-nah-na-nah-nah"); } };
@Override public void authenticate( OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest req) { req.getHeaders() .set( "X-Authorization", clientContext.getAccessToken().getTokenType() + " " + "Nah-nah-na-nah-nah"); } };
/** * Copy constructor for access token. * * @param accessToken */ public DefaultOAuth2AccessToken(OAuth2AccessToken accessToken) { this(accessToken.getValue()); setAdditionalInformation(accessToken.getAdditionalInformation()); setRefreshToken(accessToken.getRefreshToken()); setExpiration(accessToken.getExpiration()); setScope(accessToken.getScope()); setTokenType(accessToken.getTokenType()); }