本文整理了Java中org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException
类的一些代码示例,展示了OAuth2AccessDeniedException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OAuth2AccessDeniedException
类的具体详情如下:
包路径:org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException
类名称:OAuth2AccessDeniedException
[英]When access is denied we usually want a 403, but we want the same treatment as all teh other OAuth2Exception types, so this is not a Spring Security AccessDeniedException.
[中]当访问被拒绝时,我们通常想要403,但我们想要与所有其他OAuth2Exception类型相同的处理,因此这不是Spring Security AccessDeniedException。
代码示例来源: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
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
代码示例来源:origin: com.sap.cloud.lm.sl/cloudfoundry-client-lib
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 CloudOperationException(status, oauthEx.getMessage(), oauthEx.getSummary());
}
}
代码示例来源:origin: cloudfoundry-attic/eclipse-integration-cloudfoundry
/**
* Error due to invalid credentials, typically 401 or 403 HTTP errors.
* Returns null if the error is NOT an invalid credentials error.
* @param error error to parse
* @return Error message if invalid credentials error (401 or 403), or null.
*/
public static String getInvalidCredentialsError(Throwable error) {
if (isUnauthorisedException(error)) {
return Messages.ERROR_WRONG_EMAIL_OR_PASSWORD_UNAUTHORISED;
}
else if (isForbiddenException(error)) {
return Messages.ERROR_WRONG_EMAIL_OR_PASSWORD_FORBIDDEN;
}
else {
OAuth2AccessDeniedException oauthException = null;
if (error instanceof OAuth2AccessDeniedException) {
oauthException = (OAuth2AccessDeniedException) error;
}
else if (error.getCause() instanceof OAuth2AccessDeniedException) {
oauthException = (OAuth2AccessDeniedException) error.getCause();
}
if (oauthException != null) {
return NLS.bind(Messages.ERROR_ACCESS_TOKEN, oauthException.getOAuth2ErrorCode());
}
}
return null;
}
代码示例来源:origin: org.cloudfoundry/cloudfoundry-client-lib
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());
CloudFoundryException cfEx = new CloudFoundryException(status, oauthEx.getMessage());
cfEx.setDescription(oauthEx.getSummary());
throw cfEx;
}
}
代码示例来源: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
@Test
@OAuth2ContextConfiguration(value=ResourceOwner.class, initialize=false)
public void testTokenEndpointWrongPassword() throws Exception {
ResourceOwnerPasswordResourceDetails resource = (ResourceOwnerPasswordResourceDetails) context
.getResource();
resource.setPassword("bogus");
try {
new OAuth2RestTemplate(resource).getAccessToken();
} catch (OAuth2AccessDeniedException e) {
String summary = ((OAuth2Exception)e.getCause()).getSummary();
assertTrue("Wrong summary: " + summary, summary.contains("Bad credentials"));
}
}
代码示例来源: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: org.springframework.security.oauth/spring-security-oauth2
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
代码示例来源: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-cloud/spring-cloud-dataflow
if (e.getCause() instanceof ResourceAccessException) {
final String errorMessage = String.format(
"While authenticating user '%s': " + "Unable to access accessTokenUri '%s'.", username,
accessTokenUri);
logger.error(errorMessage + " Error message: {}.", e.getCause().getMessage());
throw new AuthenticationServiceException(errorMessage, e);
代码示例来源: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: org.springframework.cloud/spring-cloud-dataflow-server-core
if (e.getCause() instanceof ResourceAccessException) {
final String errorMessage = String.format(
"While authenticating user '%s': " + "Unable to access accessTokenUri '%s'.", username,
accessTokenUri);
logger.error(errorMessage + " Error message: {}.", e.getCause().getMessage());
throw new AuthenticationServiceException(errorMessage, e);
代码示例来源:origin: spring-projects/spring-security-oauth
throw new OAuth2AccessDeniedException("Invalid token does not contain resource id (" + resourceId + ")");
代码示例来源:origin: org.springframework.cloud/spring-cloud-common-security-config-web
if (e.getCause() instanceof ResourceAccessException) {
final String errorMessage = String.format(
"While authenticating user '%s': " + "Unable to access accessTokenUri '%s'.", username,
accessTokenUri);
logger.error(errorMessage + " Error message: {}.", e.getCause().getMessage());
throw new AuthenticationServiceException(errorMessage, e);
代码示例来源: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);
}
}
内容来源于网络,如有侵权,请联系作者删除!