public TokenRequest createTokenRequest(AuthorizationRequest authorizationRequest, String grantType) { TokenRequest tokenRequest = new TokenRequest(authorizationRequest.getRequestParameters(), authorizationRequest.getClientId(), authorizationRequest.getScope(), grantType); return tokenRequest; }
/** * Convenience method to set resourceIds and authorities on this request by * inheriting from a ClientDetails object. * * @param clientDetails */ public void setResourceIdsAndAuthoritiesFromClientDetails(ClientDetails clientDetails) { setResourceIds(clientDetails.getResourceIds()); setAuthorities(clientDetails.getAuthorities()); }
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) { OAuth2Request storedOAuth2Request = requestFactory.createOAuth2Request(client, tokenRequest); return new OAuth2Authentication(storedOAuth2Request, null); }
public OAuth2Request createOAuth2Request() { return new OAuth2Request(getRequestParameters(), getClientId(), getAuthorities(), isApproved(), getScope(), getResourceIds(), getRedirectUri(), getResponseTypes(), getExtensions()); }
protected OAuth2Request(OAuth2Request other) { this(other.getRequestParameters(), other.getClientId(), other.getAuthorities(), other.isApproved(), other .getScope(), other.getResourceIds(), other.getRedirectUri(), other.getResponseTypes(), other .getExtensions()); }
public OAuth2Request refresh(TokenRequest tokenRequest) { OAuth2Request request = new OAuth2Request(getRequestParameters(), getClientId(), authorities, approved, getScope(), resourceIds, redirectUri, responseTypes, extensions); request.refresh = tokenRequest; return request; }
public OAuth2Request createOAuth2Request(ClientDetails client) { Map<String, String> requestParameters = getRequestParameters(); HashMap<String, String> modifiable = new HashMap<String, String>(requestParameters); // Remove password if present to prevent leaks modifiable.remove("password"); modifiable.remove("client_secret"); // Add grant type so it can be retrieved from OAuth2Request modifiable.put("grant_type", grantType); return new OAuth2Request(modifiable, client.getClientId(), client.getAuthorities(), true, this.getScope(), client.getResourceIds(), null, null, null); }
/** * Update the request parameters and return a new object with the same properties except the parameters. * @param parameters new parameters replacing the existing ones * @return a new OAuth2Request */ public OAuth2Request createOAuth2Request(Map<String, String> parameters) { return new OAuth2Request(parameters, getClientId(), authorities, approved, getScope(), resourceIds, redirectUri, responseTypes, extensions); }
/** * Update the scope and create a new request. All the other properties are the same (including the request * parameters). * * @param scope the new scope * @return a new request with the narrowed scope */ public OAuth2Request narrowScope(Set<String> scope) { OAuth2Request request = new OAuth2Request(getRequestParameters(), getClientId(), authorities, approved, scope, resourceIds, redirectUri, responseTypes, extensions); request.refresh = this.refresh; return request; }
/** * The access token validity period in seconds * * @param clientAuth the current authorization request * @return the access token validity period in seconds */ protected int getAccessTokenValiditySeconds(OAuth2Request clientAuth) { if (clientDetailsService != null) { ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId()); Integer validity = client.getAccessTokenValiditySeconds(); if (validity != null) { return validity; } } return accessTokenValiditySeconds; }
/** * Is a refresh token supported for this client (or the global setting if * {@link #setClientDetailsService(ClientDetailsService) clientDetailsService} is not set. * * @param clientAuth the current authorization request * @return boolean to indicate if refresh token is supported */ protected boolean isSupportRefreshToken(OAuth2Request clientAuth) { if (clientDetailsService != null) { ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId()); return client.getAuthorizedGrantTypes().contains("refresh_token"); } return this.supportRefreshToken; }
/** * The refresh token validity period in seconds * * @param clientAuth the current authorization request * @return the refresh token validity period in seconds */ protected int getRefreshTokenValiditySeconds(OAuth2Request clientAuth) { if (clientDetailsService != null) { ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId()); Integer validity = client.getRefreshTokenValiditySeconds(); if (validity != null) { return validity; } } return refreshTokenValiditySeconds; }
/** * Convenience constructor for unit tests, where client ID and scope are * often the only needed fields. * * @param clientId * @param scopes */ public AuthorizationRequest(String clientId, Collection<String> scopes) { setClientId(clientId); setScope(scopes); // in case we need to parse }
@Override public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) { if (delegate == null) { delegate = new CompositeTokenGranter(getDefaultTokenGranters()); } return delegate.grant(grantType, tokenRequest); } };
public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) { for (TokenGranter granter : tokenGranters) { OAuth2AccessToken grant = granter.grant(grantType, tokenRequest); if (grant!=null) { return grant; } } return null; }
/** * Set the Request Parameters on this authorization request, which represent * the original request parameters and should never be changed during * processing. The map passed in is wrapped in an unmodifiable map instance. * * @see TokenRequest#setRequestParameters * * @param requestParameters */ public void setRequestParameters(Map<String, String> requestParameters) { super.setRequestParameters(requestParameters); }
/** * Set the scope value. If the collection contains only a single scope * value, this method will parse that value into a collection using * {@link OAuth2Utils#parseParameterList}. * * @see TokenRequest#setScope * * @param scope */ public void setScope(Collection<String> scope) { super.setScope(scope); }
@Override public boolean isUser() { Authentication authentication = getUserAuthentication(); return authentication != null; }
/** * Set the Request Parameters on this authorization request, which represent the original request parameters and * should never be changed during processing. The map passed in is wrapped in an unmodifiable map instance. * * @see AuthorizationRequest#setRequestParameters * * @param requestParameters */ public void setRequestParameters(Map<String, String> requestParameters) { super.setRequestParameters(requestParameters); }
/** * Set the scope value. If the collection contains only a single scope value, this method will parse that value into * a collection using {@link OAuth2Utils#parseParameterList}. * * @see AuthorizationRequest#setScope * * @param scope */ public void setScope(Collection<String> scope) { super.setScope(scope); }