• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java OAuth2AccessDeniedException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException的典型用法代码示例。如果您正苦于以下问题:Java OAuth2AccessDeniedException类的具体用法?Java OAuth2AccessDeniedException怎么用?Java OAuth2AccessDeniedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OAuth2AccessDeniedException类属于org.springframework.security.oauth2.client.resource包,在下文中一共展示了OAuth2AccessDeniedException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: obtainNewAccessTokenInternal

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的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);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:18,代码来源:AccessTokenProviderChain.java


示例2: retrieveToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的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);
	}

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:22,代码来源:OAuth2AccessTokenSupport.java


示例3: obtainAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的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));

}
 
开发者ID:pivotal-cf,项目名称:identity-sample-apps,代码行数:18,代码来源:OpenIDTokenProvider.java


示例4: obtainAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest request)
		throws UserRedirectRequiredException, AccessDeniedException, OAuth2AccessDeniedException {

	ImplicitResourceDetails resource = (ImplicitResourceDetails) details;
	try {
		// We can assume here that the request contains all the parameters needed for authentication etc.
		OAuth2AccessToken token = retrieveToken(request,
				resource, getParametersForTokenRequest(resource, request), getHeadersForTokenRequest(request));
		if (token==null) {
			// Probably an authenticated request, but approval is required.  TODO: prompt somehow?
			throw new UserRedirectRequiredException(resource.getUserAuthorizationUri(), request.toSingleValueMap());				
		}
		return token;
	}
	catch (UserRedirectRequiredException e) {
		// ... but if it doesn't then capture the request parameters for the redirect
		throw new UserRedirectRequiredException(e.getRedirectUri(), request.toSingleValueMap());
	}

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:21,代码来源:ImplicitAccessTokenProvider.java


示例5: obtainAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
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));

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:17,代码来源:AuthorizationCodeAccessTokenProvider.java


示例6: getAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
/**
 * Get the current access token. Should be available inside a test method as long as a resource has been setup with
 * {@link OAuth2ContextConfiguration &#64;OAuth2ContextConfiguration}.
 * 
 * @return the current access token initializing it if necessary
 */
public OAuth2AccessToken getAccessToken() {
	if (resource == null || client == null) {
		return null;
	}
	if (accessToken != null) {
		return accessToken;
	}
	try {
		if (accessTokenProvider != null) {
			client.setAccessTokenProvider(accessTokenProvider);
		}
		return client.getAccessToken();
	}
	catch (OAuth2AccessDeniedException e) {
		Throwable cause = e.getCause();
		if (cause instanceof RuntimeException) {
			throw (RuntimeException) cause;
		}
		if (cause instanceof Error) {
			throw (Error) cause;
		}
		throw e;
	}
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:31,代码来源:OAuth2ContextSetup.java


示例7: authenticate

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
/**
 * Expects the incoming authentication request to have a principal value that is an access token value (e.g. from an
 * authorization header) .Loads an authentication from the {@link ResourceServerTokenServices} and checks that the
 * resource id is contained in the {@link AuthorizationRequest} (if one is specified). Also copies authentication
 * details over from the input to the output (e.g. typically so that the access token value and request details can
 * be reported later).
 * 
 * @param authentication an authentication request containing an access token value as the principal
 * @return an {@link OAuth2Authentication}
 * 
 * @see org.springframework.security.authentication.AuthenticationManager#authenticate(org.springframework.security.core.Authentication)
 */
public Authentication authenticate(Authentication authentication) throws AuthenticationException {

	String token = (String) authentication.getPrincipal();
	OAuth2Authentication auth = tokenServices.loadAuthentication(token);
	if (auth == null) {
		throw new InvalidTokenException("Invalid token: " + token);
	}

	Collection<String> resourceIds = auth.getOAuth2Request().getResourceIds();
	if (resourceId != null && resourceIds != null && !resourceIds.isEmpty() && !resourceIds.contains(resourceId)) {
		throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" + resourceId + ")");
	}

	auth.setDetails(authentication.getDetails());
	return auth;

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:30,代码来源:OAuth2AuthenticationManager.java


示例8: createToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
private OAuth2AccessToken createToken(String username, String password, String clientId, String clientSecret) {
    OAuth2ProtectedResourceDetails resource = getResourceDetails(username, password, clientId, clientSecret);
    AccessTokenRequest request = createAccessTokenRequest(username, password);

    ResourceOwnerPasswordAccessTokenProvider provider = createResourceOwnerPasswordAccessTokenProvider();
    try {
        return provider.obtainAccessToken(resource, request);
    } catch (OAuth2AccessDeniedException oauthEx) {
        HttpStatus status = HttpStatus.valueOf(oauthEx.getHttpErrorCode());
        throw new CloudFoundryException(status, oauthEx.getMessage(), oauthEx.getSummary());
    }
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:13,代码来源:OauthClient.java


示例9: obtainAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest request) throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException, OAuth2AccessDeniedException {
    AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails)details;
    System.out.println(request.getCurrentUri());
    if(request.getAuthorizationCode() == null) {
        if(request.getStateKey() == null) {
            throw this.getRedirectForAuthorization(resource, request);
        }

        this.obtainAuthorizationCode(resource, request);
    }
    System.out.println("code == " + request.getAuthorizationCode());
    return this.retrieveToken(request,
            resource, this.getParametersForTokenRequest(resource, request), this.getHeadersForTokenRequest(request));
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:15,代码来源:MyAuthorizationCodeAccessTokenProvider.java


示例10: refreshAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource, OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException, OAuth2AccessDeniedException {
    MultiValueMap<String, String> form = new LinkedMultiValueMap();
    form.add("grant_type", "refresh_token");
    form.add("refresh_token", refreshToken.getValue());
    form.add("appid", resource.getClientId());

    try {
        return this.retrieveToken(request, resource, form, this.getHeadersForTokenRequest(request));
    } catch (OAuth2AccessDeniedException var6) {
        throw this.getRedirectForAuthorization((AuthorizationCodeResourceDetails)resource, request);
    }
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:13,代码来源:MyAuthorizationCodeAccessTokenProvider.java


示例11: retrieveToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
protected OAuth2AccessToken retrieveToken(final AccessTokenRequest request,
                                          OAuth2ProtectedResourceDetails resource,
                                          MultiValueMap<String, String> form,
                                          HttpHeaders headers) throws OAuth2AccessDeniedException {
    try {
        this.authenticationHandler.authenticateTokenRequest(resource, form, headers);
        this.tokenRequestEnhancer.enhance(request, resource, form, headers);
        final ResponseExtractor<OAuth2AccessToken> delegate = this.getResponseExtractor();

        ResponseExtractor<OAuth2AccessToken> extractor = new ResponseExtractor<OAuth2AccessToken>() {
            public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
                if(response.getHeaders().containsKey("Set-Cookie")) {
                    request.setCookie(response.getHeaders().getFirst("Set-Cookie"));
                }

                return (OAuth2AccessToken)delegate.extractData(response);
            }
        };
        System.out.println("URI == " + this.getAccessTokenUri(resource, form));
        return (OAuth2AccessToken)this.getRestTemplate().execute(this.getAccessTokenUri(resource, form),
                this.getHttpMethod(),
                this.getRequestCallback(resource, form, headers),
                extractor,
                form.toSingleValueMap());
    } catch (OAuth2Exception var8) {
        System.out.println(var8.toString());
        throw new OAuth2AccessDeniedException("Access token denied.", resource, var8);
    } catch (RestClientException var9) {
        System.out.println(var9.toString());
        throw new OAuth2AccessDeniedException("Error requesting access token.", resource, var9);
    }
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:33,代码来源:MyAuthorizationCodeAccessTokenProvider.java


示例12: handleCustomBindException

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
@ExceptionHandler(OAuth2AccessDeniedException.class)
public String handleCustomBindException(OAuth2AccessDeniedException ex, Model model) {
    model.addAttribute("exception_message",
            String.format("Http Error Code: %s, OAuth2Error Code: %s, Exception Message: %s",
                    ex.getHttpErrorCode(), ex.getOAuth2ErrorCode(), ex.getMessage()));
    return "exception_page";
}
 
开发者ID:bijukunjummen,项目名称:oauth-uaa-sample,代码行数:8,代码来源:ExceptionHandlingAdvice.java


示例13: obtainAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
@Override
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest request)
    throws UserRedirectRequiredException, AccessDeniedException, OAuth2AccessDeniedException {

    ResourceOwnerPasswordResourceDetails resource = (ResourceOwnerPasswordResourceDetails) details;
    return retrieveToken(request, resource, getParametersForTokenRequest(resource, request), new HttpHeaders());

}
 
开发者ID:pivotal-cf,项目名称:identity-sample-apps,代码行数:9,代码来源:CompositeAccessTokenProvider.java


示例14: addAccount

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
private void addAccount(GMMCredential credential) {
	try {
		ProjectBinding[] projects = client.GETMyProjects(credential);
		ArrayList<Object> list = new ArrayList<Object>();
		list.add(credential);
		for (ProjectBinding project : projects) {
			list.add(project);
		}

		if (save != null) {
			IMemento child = save.createChild("credential");
			child.putString("username", credential.getUsername());
			child.putString("password", credential.getPassword());
		}

		content.addElement(list);
		content.initialize();
		viewer.setContentProvider(content);
		keyStore.addCredential(credential.getUsername(), credential);
	} catch (OAuth2AccessDeniedException e) {
		IStatus err = new Status(
				Status.ERROR,
				Activator.PLUGIN_ID,
				Status.ERROR,
				"Login/password error\n\tPlease verify your information and be sure that you set a passord for your account.",
				e);
		StatusManager.getManager().handle(err, StatusManager.BLOCK);
	}
}
 
开发者ID:Axellience,项目名称:gmm-eclipse-plugins,代码行数:30,代码来源:GenMyModelExplorer.java


示例15: refreshAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
@Override
public OAuth2AccessToken refreshAccessToken(
        OAuth2ProtectedResourceDetails resource,
        OAuth2RefreshToken refreshToken, AccessTokenRequest request)
        throws UserRedirectRequiredException,
        OAuth2AccessDeniedException {

    OAuth2AccessToken accessToken = super.refreshAccessToken(resource, refreshToken, request);
    // Google does not replace refresh tokens, so we need to hold on to the existing refresh token...
    if (accessToken.getRefreshToken() == null) {
        ((DefaultOAuth2AccessToken) accessToken).setRefreshToken(refreshToken);
    }
    return accessToken;
}
 
开发者ID:openmhealth,项目名称:shimmer,代码行数:15,代码来源:GoogleFitShim.java


示例16: refreshAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
/**
 * Obtain a new access token for the specified resource using the refresh token.
 * 
 * @param resource The resource.
 * @param refreshToken The refresh token.
 * @return The access token, or null if failed.
 * @throws UserRedirectRequiredException
 */
public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource,
		OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException {
	for (AccessTokenProvider tokenProvider : chain) {
		if (tokenProvider.supportsRefresh(resource)) {
			return tokenProvider.refreshAccessToken(resource, refreshToken, request);
		}
	}
	throw new OAuth2AccessDeniedException("Unable to obtain a new access token for resource '" + resource.getId()
			+ "'. The provider manager is not configured to support it.", resource);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:19,代码来源:AccessTokenProviderChain.java


示例17: refreshAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource,
		OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException,
		OAuth2AccessDeniedException {
	MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
	form.add("grant_type", "refresh_token");
	form.add("refresh_token", refreshToken.getValue());
	try {
		return retrieveToken(request, resource, form, getHeadersForTokenRequest(request));
	}
	catch (OAuth2AccessDeniedException e) {
		throw getRedirectForAuthorization((AuthorizationCodeResourceDetails) resource, request);
	}
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:14,代码来源:AuthorizationCodeAccessTokenProvider.java


示例18: refreshAccessToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource,
		OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException,
		OAuth2AccessDeniedException {
	MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
	form.add("grant_type", "refresh_token");
	form.add("refresh_token", refreshToken.getValue());
	return retrieveToken(request, resource, form, new HttpHeaders());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:9,代码来源:ResourceOwnerPasswordAccessTokenProvider.java


示例19: testHelloEve

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
@Test(expected = OAuth2AccessDeniedException.class)
@OAuth2ContextConfiguration(EveDetails.class)
public void testHelloEve() {
	restTemplate.getForEntity(host + "/hello", String.class);
}
 
开发者ID:timtebeek,项目名称:resource-server-testing,代码行数:6,代码来源:MyControllerIT.java


示例20: tryToAcquireToken

import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; //导入依赖的package包/类
@Test(expected = OAuth2AccessDeniedException.class)
public void tryToAcquireToken() {
	oAuth2FeignRequestInterceptor = new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), new BaseOAuth2ProtectedResourceDetails());
	OAuth2AccessToken oAuth2AccessToken = oAuth2FeignRequestInterceptor.getToken();
	Assert.assertTrue(oAuth2AccessToken.getValue() + " Must be null", oAuth2AccessToken.getValue() == null);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-security,代码行数:7,代码来源:OAuth2FeignRequestInterceptorTests.java



注:本文中的org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IExtendedModifier类代码示例发布时间:2022-05-21
下一篇:
Java TSimpleServer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap