This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SECOAUTH-241: added InsufficientScopeException
- Loading branch information
Showing
8 changed files
with
104 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ava/org/springframework/security/oauth2/common/exceptions/InsufficientScopeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.springframework.security.oauth2.common.exceptions; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.oauth2.common.util.OAuth2Utils; | ||
|
||
/** | ||
* Exception representing insufficient scope in a token when a request is handled by a Resource Server. It is akin to an | ||
* {@link AccessDeniedException} and should result in a 403 (FORBIDDEN) HTTP status. | ||
* | ||
* @author Dave Syer | ||
*/ | ||
public class InsufficientScopeException extends OAuth2Exception { | ||
|
||
public InsufficientScopeException(String msg, Set<String> validScope) { | ||
this(msg); | ||
addAdditionalInformation("scope", OAuth2Utils.formatParameterList(validScope)); | ||
} | ||
|
||
public InsufficientScopeException(String msg) { | ||
super(msg); | ||
} | ||
|
||
@Override | ||
public int getHttpErrorCode() { | ||
return 403; | ||
} | ||
|
||
@Override | ||
public String getOAuth2ErrorCode() { | ||
// Not defined in the spec, so not really an OAuth2Exception | ||
return "insufficient_scope"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../src/main/java/org/springframework/security/oauth2/provider/token/TokenEnhancerChain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Cloud Foundry 2012.02.03 Beta | ||
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
|
||
package org.springframework.security.oauth2.provider.token; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.springframework.security.oauth2.common.OAuth2AccessToken; | ||
import org.springframework.security.oauth2.provider.OAuth2Authentication; | ||
|
||
/** | ||
* A composite token enhancer that loops over its delegate enhancers. | ||
* | ||
* @author Dave Syer | ||
* | ||
*/ | ||
public class TokenEnhancerChain implements TokenEnhancer { | ||
|
||
private List<TokenEnhancer> delegates = Collections.emptyList(); | ||
|
||
/** | ||
* @param delegates the delegates to set | ||
*/ | ||
public void setTokenEnhancers(List<TokenEnhancer> delegates) { | ||
this.delegates = delegates; | ||
} | ||
|
||
/** | ||
* Loop over the {@link #setTokenEnhancers(List) delegates} passing the result into the next member of the chain. | ||
* | ||
* @see org.springframework.security.oauth2.provider.token.TokenEnhancer#enhance(org.springframework.security.oauth2.common.OAuth2AccessToken, | ||
* org.springframework.security.oauth2.provider.OAuth2Authentication) | ||
*/ | ||
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { | ||
OAuth2AccessToken result = accessToken; | ||
for (TokenEnhancer enhancer : delegates) { | ||
result = enhancer.enhance(result, authentication); | ||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters