本文整理匯總了Java中org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails類的典型用法代碼示例。如果您正苦於以下問題:Java OAuth2ProtectedResourceDetails類的具體用法?Java OAuth2ProtectedResourceDetails怎麽用?Java OAuth2ProtectedResourceDetails使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OAuth2ProtectedResourceDetails類屬於org.springframework.security.oauth2.client.resource包,在下文中一共展示了OAuth2ProtectedResourceDetails類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: obtainNewAccessTokenInternal
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
protected OAuth2AccessToken obtainNewAccessTokenInternal(OAuth2ProtectedResourceDetails details,
AccessTokenRequest request) throws UserRedirectRequiredException, AccessDeniedException {
if (request.isError()) {
// there was an oauth error...
throw OAuth2Exception.valueOf(request.toSingleValueMap());
}
for (AccessTokenProvider tokenProvider : chain) {
if (tokenProvider.supportsResource(details)) {
return tokenProvider.obtainAccessToken(details, request);
}
}
throw new OAuth2AccessDeniedException("Unable to obtain a new access token for resource '" + details.getId()
+ "'. The provider manager is not configured to support it.", details);
}
示例2: acquireAccessToken
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
protected OAuth2AccessToken acquireAccessToken(OAuth2ProtectedResourceDetails resource)
throws UserRedirectRequiredException {
AccessTokenRequest tokenRequest = oAuth2ClientContext.getAccessTokenRequest();
if (tokenRequest == null) {
throw new AccessTokenRequiredException(
"Cannot find valid context on request for resource '" + resource.getId() + "'.", resource);
}
String stateKey = tokenRequest.getStateKey();
if (stateKey != null) {
tokenRequest.setPreservedState(oAuth2ClientContext.removePreservedState(stateKey));
}
OAuth2AccessToken existingToken = oAuth2ClientContext.getAccessToken();
if (existingToken != null) {
oAuth2ClientContext.setAccessToken(existingToken);
}
OAuth2AccessToken obtainableAccessToken;
obtainableAccessToken = accessTokenProvider.obtainAccessToken(resource, tokenRequest);
if (obtainableAccessToken == null || obtainableAccessToken.getValue() == null) {
throw new IllegalStateException(
" Access token provider returned a null token, which is illegal according to the contract.");
}
oAuth2ClientContext.setAccessToken(obtainableAccessToken);
return obtainableAccessToken;
}
示例3: retrieveToken
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
protected OAuth2AccessToken retrieveToken(AccessTokenRequest request, OAuth2ProtectedResourceDetails resource,
MultiValueMap<String, String> form, HttpHeaders headers) throws OAuth2AccessDeniedException {
try {
// Prepare headers and form before going into rest template call in case the URI is affected by the result
authenticationHandler.authenticateTokenRequest(resource, form, headers);
// Opportunity to customize form and headers
tokenRequestEnhancer.enhance(request, resource, form, headers);
return getRestTemplate().execute(getAccessTokenUri(resource, form), getHttpMethod(),
getRequestCallback(resource, form, headers), getResponseExtractor(), form.toSingleValueMap());
}
catch (OAuth2Exception oe) {
throw new OAuth2AccessDeniedException("Access token denied.", resource, oe);
}
catch (RestClientException rce) {
throw new OAuth2AccessDeniedException("Error requesting access token.", resource, rce);
}
}
示例4: passwordResourceDetails
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Bean
public OAuth2ProtectedResourceDetails passwordResourceDetails() {
//@formatter:off
ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setId("oauth2server");
details.setTokenName("oauth_token");
details.setClientId("clientadmin");
details.setClientSecret("123");
details.setAccessTokenUri("http://localhost:8080/oauth/token");
details.setScope(Arrays.asList("admin"));
details.setClientAuthenticationScheme(AuthenticationScheme.header);
//@formatter:on
return details;
}
示例5: passwordResourceDetails
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Bean
public OAuth2ProtectedResourceDetails passwordResourceDetails() {
//@formatter:off
ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();
resourceDetails.setId("oauth2server");
resourceDetails.setTokenName("oauth_token");
resourceDetails.setClientId("clientapp");
resourceDetails.setClientSecret("123456");
resourceDetails.setAccessTokenUri("http://localhost:8080/oauth/token");
resourceDetails.setScope(Arrays.asList("read_profile"));
resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.header);
//@formatter:on
return resourceDetails;
}
示例6: implicitResourceDetails
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Bean
public OAuth2ProtectedResourceDetails implicitResourceDetails() {
ImplicitResourceDetails resourceDetails = new ImplicitResourceDetails();
//@formatter:off
resourceDetails.setId("oauth2server");
resourceDetails.setTokenName("oauth_token");
resourceDetails.setClientId("clientapp");
resourceDetails.setUserAuthorizationUri("http://localhost:8080/oauth/authorize");
resourceDetails.setScope(Arrays.asList("read_profile"));
resourceDetails.setPreEstablishedRedirectUri("http://localhost:9000/callback");
resourceDetails.setUseCurrentUri(false);
resourceDetails.setClientAuthenticationScheme(AuthenticationScheme.query);
//@formatter:on
return resourceDetails;
}
示例7: MyOAuth2RestTemplate
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
public MyOAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context) {
super(resource, context);
this.accessTokenProvider = new MyAccessTokenProviderChain(Arrays.asList(new AccessTokenProvider[]{new MyAuthorizationCodeAccessTokenProvider(),
new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(),
new ClientCredentialsAccessTokenProvider()}));
this.retryBadAccessTokens = true;
this.authenticator = new DefaultOAuth2RequestAuthenticator();
if(resource == null) {
throw new IllegalArgumentException("An OAuth2 resource must be supplied.");
} else {
this.resource = resource;
this.context = context;
this.setErrorHandler(new OAuth2ErrorHandler(resource));
}
}
示例8: getAccessTokenUri
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
protected String getAccessTokenUri(OAuth2ProtectedResourceDetails resource, MultiValueMap<String, String> form) {
String accessTokenUri = resource.getAccessTokenUri();
if (form.containsKey("refresh_token"))
accessTokenUri = "https://api.weixin.qq.com/sns/oauth2/refresh_token";
if(this.logger.isDebugEnabled()) {
this.logger.debug("Retrieving token from " + accessTokenUri);
}
StringBuilder builder = new StringBuilder(accessTokenUri);
if(this.getHttpMethod() == HttpMethod.GET) {
String separator = "?";
if(accessTokenUri.contains("?")) {
separator = "&";
}
for(Iterator var6 = form.keySet().iterator(); var6.hasNext(); separator = "&") {
String key = (String)var6.next();
builder.append(separator);
builder.append(key + "={" + key + "}");
}
}
if (form.containsKey("refresh_token"))
return builder.toString();
return builder.toString() + "#wechat_redirect";
}
開發者ID:luotuo,項目名稱:springboot-security-wechat,代碼行數:27,代碼來源:MyAuthorizationCodeAccessTokenProvider.java
示例9: obtainAccessToken
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Override
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest request)
throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException,
OAuth2AccessDeniedException {
AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) details;
if (request.getAuthorizationCode() == null) {
if (request.getStateKey() == null) {
throw getRedirectForAuthorization(resource, request);
}
obtainAuthorizationCode(resource, request);
}
return retrieveToken(request, resource, getParametersForTokenRequest(resource, request),
getHeadersForTokenRequest(request));
}
示例10: enhance
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Override
public void enhance(
AccessTokenRequest request,
OAuth2ProtectedResourceDetails resource,
MultiValueMap<String, String> form,
HttpHeaders headers) {
form.set("client_id", resource.getClientId());
/*
Fitbit requires the redirect_uri to be specified if it was specified in the authorization request.
It doesn't require the state parameter, even though the documentation says otherwise.
*/
// TODO this won't work if a redirect URL is specified in the authorization initiation request because
// Fitbit will reject the authorization code exchange if the redirect_uri parameters of the authorization request
// and access token request don't match. This needs to be loaded from request scope instead.
form.set("redirect_uri", deploymentSettings.getRedirectUrl(FitbitShim.SHIM_KEY));
}
示例11: authenticate
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@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.equalsIgnoreCase(OAuth2AccessToken.BEARER_TYPE)) {
tokenType = OAuth2AccessToken.BEARER_TYPE; // we'll assume basic bearer token type if none is specified.
}
request.getHeaders().set("Authorization", String.format("%s %s", tokenType, accessToken.getValue()));
}
示例12: getAccessToken
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Override
public OAuth2AccessToken getAccessToken(
OAuth2ProtectedResourceDetails resource,
Authentication authentication) {
String username = authentication.getPrincipal().toString();
String shimKey = authentication.getDetails().toString();
AccessParameters accessParameters = accessParametersRepo.findByUsernameAndShimKey(
username, shimKey, new Sort(Sort.Direction.DESC, "dateCreated"));
if (accessParameters == null || accessParameters.getSerializedToken() == null) {
return null; //No token was found!
}
return SerializationUtils.deserialize(accessParameters.getSerializedToken());
}
示例13: saveAccessToken
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Override
public void saveAccessToken(
OAuth2ProtectedResourceDetails resource,
Authentication authentication, OAuth2AccessToken accessToken) {
String username = authentication.getPrincipal().toString();
String shimKey = authentication.getDetails().toString();
AccessParameters accessParameters =
accessParametersRepo.findByUsernameAndShimKey(
username,
shimKey,
new Sort(Sort.Direction.DESC, "dateCreated"));
if (accessParameters == null) {
accessParameters = new AccessParameters();
accessParameters.setUsername(username);
accessParameters.setShimKey(shimKey);
}
accessParameters.setSerializedToken(SerializationUtils.serialize(accessToken));
accessParametersRepo.save(accessParameters);
}
示例14: getAuthorizationUrl
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
@Override
protected String getAuthorizationUrl(UserRedirectRequiredException exception, Map<String, String> addlParameters) {
final OAuth2ProtectedResourceDetails resource = getResource();
UriComponentsBuilder callBackUriBuilder = UriComponentsBuilder.fromUriString(getDefaultRedirectUrl())
.queryParam("state", exception.getStateKey());
UriComponentsBuilder authorizationUriBuilder = UriComponentsBuilder.fromUriString(exception.getRedirectUri())
.queryParam("client_id", resource.getClientId())
.queryParam("response_type", "code")
.queryParam("APIName", Joiner.on(' ').join(resource.getScope()))
.queryParam("RequiredAPIName", Joiner.on(' ').join(resource.getScope()))
.queryParam("redirect_uri", callBackUriBuilder.build().toString());
return authorizationUriBuilder.build().encode().toString();
}
示例15: IHealthAuthorizationCodeAccessTokenProvider
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; //導入依賴的package包/類
public IHealthAuthorizationCodeAccessTokenProvider() {
this.setTokenRequestEnhancer(new RequestEnhancer() {
@Override
public void enhance(AccessTokenRequest request,
OAuth2ProtectedResourceDetails resource,
MultiValueMap<String, String> form, HttpHeaders headers) {
form.set("client_id", resource.getClientId());
form.set("client_secret", resource.getClientSecret());
form.set("redirect_uri", getDefaultRedirectUrl());
form.set("state", request.getStateKey());
}
});
}