本文整理了Java中org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException.<init>()
方法的一些代码示例,展示了OAuth2AccessDeniedException.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OAuth2AccessDeniedException.<init>()
方法的具体详情如下:
包路径:org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException
类名称:OAuth2AccessDeniedException
方法名:<init>
暂无
代码示例来源:origin: spring-projects/spring-security-oauth
private void checkClientDetails(OAuth2Authentication auth) {
if (clientDetailsService != null) {
ClientDetails client;
try {
client = clientDetailsService.loadClientByClientId(auth.getOAuth2Request().getClientId());
}
catch (ClientRegistrationException e) {
throw new OAuth2AccessDeniedException("Invalid token contains invalid client id");
}
Set<String> allowed = client.getScope();
for (String scope : auth.getOAuth2Request().getScope()) {
if (!allowed.contains(scope)) {
throw new OAuth2AccessDeniedException(
"Invalid token contains disallowed scope (" + scope + ") for this client");
}
}
}
}
代码示例来源:origin: spring-projects/spring-security-oauth
@Override
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor) throws RestClientException {
OAuth2AccessToken accessToken = context.getAccessToken();
RuntimeException rethrow = null;
try {
return super.doExecute(url, method, requestCallback, responseExtractor);
}
catch (AccessTokenRequiredException e) {
rethrow = e;
}
catch (OAuth2AccessDeniedException e) {
rethrow = e;
}
catch (InvalidTokenException e) {
// Don't reveal the token value in case it is logged
rethrow = new OAuth2AccessDeniedException("Invalid token for client=" + getClientId());
}
if (accessToken != null && retryBadAccessTokens) {
context.setAccessToken(null);
try {
return super.doExecute(url, method, requestCallback, responseExtractor);
}
catch (InvalidTokenException e) {
// Don't reveal the token value in case it is logged
rethrow = new OAuth2AccessDeniedException("Invalid token for client=" + getClientId());
}
}
throw rethrow;
}
代码示例来源:origin: spring-projects/spring-security-oauth
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);
final AccessTokenRequest copy = request;
final ResponseExtractor<OAuth2AccessToken> delegate = getResponseExtractor();
ResponseExtractor<OAuth2AccessToken> extractor = new ResponseExtractor<OAuth2AccessToken>() {
@Override
public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
if (response.getHeaders().containsKey("Set-Cookie")) {
copy.setCookie(response.getHeaders().getFirst("Set-Cookie"));
}
return delegate.extractData(response);
}
};
return getRestTemplate().execute(getAccessTokenUri(resource, form), getHttpMethod(),
getRequestCallback(resource, form, headers), extractor , 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);
}
}
代码示例来源:origin: spring-projects/spring-security-oauth
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);
}
代码示例来源:origin: spring-projects/spring-security-oauth
/**
* 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)) {
DefaultOAuth2AccessToken refreshedAccessToken = new DefaultOAuth2AccessToken(
tokenProvider.refreshAccessToken(resource, refreshToken,
request));
if (refreshedAccessToken.getRefreshToken() == null) {
// Fixes gh-712
refreshedAccessToken.setRefreshToken(refreshToken);
}
return refreshedAccessToken;
}
}
throw new OAuth2AccessDeniedException(
"Unable to obtain a new access token for resource '" + resource.getId()
+ "'. The provider manager is not configured to support it.",
resource);
}
代码示例来源:origin: spring-projects/spring-security-oauth
throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" + resourceId + ")");
代码示例来源:origin: spring-projects/spring-security-oauth
oauth2Exception = new OAuth2AccessDeniedException(oauth2Exception.getMessage());
代码示例来源:origin: pl.touk.widerest/widerest-api
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
OAuth2Authentication auth = (OAuth2Authentication) super.authenticate(authentication);
Collection<String> resourceIds = auth.getOAuth2Request().getResourceIds();
if (resourceIds != null && !resourceIds.isEmpty() && (resourceIdSupplier == null || !resourceIds.contains(resourceIdSupplier.get()))) {
throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" + resourceIdSupplier.get() + ")");
}
return auth;
}
});
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
private void checkClientDetails(OAuth2Authentication auth) {
if (clientDetailsService != null) {
ClientDetails client;
try {
client = clientDetailsService.loadClientByClientId(auth.getOAuth2Request().getClientId());
}
catch (ClientRegistrationException e) {
throw new OAuth2AccessDeniedException("Invalid token contains invalid client id");
}
Set<String> allowed = client.getScope();
for (String scope : auth.getOAuth2Request().getScope()) {
if (!allowed.contains(scope)) {
throw new OAuth2AccessDeniedException(
"Invalid token contains disallowed scope (" + scope + ") for this client");
}
}
}
}
代码示例来源:origin: br.com.anteros/Anteros-Security-Spring
private void checkClientDetails(OAuth2Authentication auth) {
ClientDetails client;
try {
client = this.loadClientByClientId(auth.getOAuth2Request().getClientId());
} catch (ClientRegistrationException e) {
throw new OAuth2AccessDeniedException("Invalid token contains invalid client id");
}
Set<String> allowed = client.getScope();
for (String scope : auth.getOAuth2Request().getScope()) {
if (!allowed.contains(scope)) {
throw new OAuth2AccessDeniedException(
"Invalid token contains disallowed scope (" + scope + ") for this client");
}
}
}
代码示例来源:origin: luotuo/springboot-security-wechat
protected OAuth2AccessToken obtainNewAccessTokenInternal(OAuth2ProtectedResourceDetails details, AccessTokenRequest request) throws UserRedirectRequiredException, AccessDeniedException {
if(request.isError()) {
throw OAuth2Exception.valueOf(request.toSingleValueMap());
} else {
Iterator var3 = this.chain.iterator();
AccessTokenProvider tokenProvider;
do {
if(!var3.hasNext()) {
throw new OAuth2AccessDeniedException("Unable to obtain a new access token for resource '" + details.getId() + "'. The provider manager is not configured to support it.", details);
}
tokenProvider = (AccessTokenProvider)var3.next();
} while(!tokenProvider.supportsResource(details));
if (tokenProvider != null)
System.out.println("tokeProvider == " + tokenProvider.toString());
return tokenProvider.obtainAccessToken(details, request);
}
}
代码示例来源:origin: luotuo/springboot-security-wechat
public OAuth2AccessToken refreshAccessToken(OAuth2ProtectedResourceDetails resource, OAuth2RefreshToken refreshToken, AccessTokenRequest request) throws UserRedirectRequiredException {
Iterator var4 = this.chain.iterator();
AccessTokenProvider tokenProvider;
do {
if(!var4.hasNext()) {
throw new OAuth2AccessDeniedException("Unable to obtain a new access token for resource '" + resource.getId() + "'. The provider manager is not configured to support it.", resource);
}
tokenProvider = (AccessTokenProvider)var4.next();
} while(!tokenProvider.supportsRefresh(resource));
DefaultOAuth2AccessToken refreshedAccessToken = new DefaultOAuth2AccessToken(tokenProvider.refreshAccessToken(resource, refreshToken, request));
if(refreshedAccessToken.getRefreshToken() == null) {
refreshedAccessToken.setRefreshToken(refreshToken);
}
return refreshedAccessToken;
}
}
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
@Override
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor) throws RestClientException {
OAuth2AccessToken accessToken = context.getAccessToken();
RuntimeException rethrow = null;
try {
return super.doExecute(url, method, requestCallback, responseExtractor);
}
catch (AccessTokenRequiredException e) {
rethrow = e;
}
catch (OAuth2AccessDeniedException e) {
rethrow = e;
}
catch (InvalidTokenException e) {
// Don't reveal the token value in case it is logged
rethrow = new OAuth2AccessDeniedException("Invalid token for client=" + getClientId());
}
if (accessToken != null && retryBadAccessTokens) {
context.setAccessToken(null);
try {
return super.doExecute(url, method, requestCallback, responseExtractor);
}
catch (InvalidTokenException e) {
// Don't reveal the token value in case it is logged
rethrow = new OAuth2AccessDeniedException("Invalid token for client=" + getClientId());
}
}
throw rethrow;
}
代码示例来源:origin: luotuo/springboot-security-wechat
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);
}
}
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
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);
final AccessTokenRequest copy = request;
final ResponseExtractor<OAuth2AccessToken> delegate = getResponseExtractor();
ResponseExtractor<OAuth2AccessToken> extractor = new ResponseExtractor<OAuth2AccessToken>() {
@Override
public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
if (response.getHeaders().containsKey("Set-Cookie")) {
copy.setCookie(response.getHeaders().getFirst("Set-Cookie"));
}
return delegate.extractData(response);
}
};
return getRestTemplate().execute(getAccessTokenUri(resource, form), getHttpMethod(),
getRequestCallback(resource, form, headers), extractor , 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);
}
}
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
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);
}
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
/**
* 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)) {
DefaultOAuth2AccessToken refreshedAccessToken = new DefaultOAuth2AccessToken(
tokenProvider.refreshAccessToken(resource, refreshToken,
request));
if (refreshedAccessToken.getRefreshToken() == null) {
// Fixes gh-712
refreshedAccessToken.setRefreshToken(refreshToken);
}
return refreshedAccessToken;
}
}
throw new OAuth2AccessDeniedException(
"Unable to obtain a new access token for resource '" + resource.getId()
+ "'. The provider manager is not configured to support it.",
resource);
}
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" + resourceId + ")");
代码示例来源:origin: br.com.anteros/Anteros-Security-Spring
if (resourceId != null && resourceIds != null && !resourceIds.isEmpty()
&& !resourceIds.contains(resourceId)) {
throw new OAuth2AccessDeniedException(
"Invalid token does not contain resource id (" + resourceId + ")");
代码示例来源:origin: org.springframework.security.oauth/spring-security-oauth2
oauth2Exception = new OAuth2AccessDeniedException(oauth2Exception.getMessage());
内容来源于网络,如有侵权,请联系作者删除!