split scopes table

pull/166/head
Justin Richer 2012-08-10 13:37:26 -04:00
parent ed99bd36cf
commit bb7d6b2e94
5 changed files with 14 additions and 34 deletions

View File

@ -451,7 +451,7 @@ public class ClientDetailsEntity implements ClientDetails {
*/
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
name="scope",
name="client_scope",
joinColumns=@JoinColumn(name="owner_id")
)
@Override

View File

@ -215,7 +215,7 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@ElementCollection(fetch=FetchType.EAGER)
@CollectionTable(
joinColumns=@JoinColumn(name="owner_id"),
name="scope"
name="token_scope"
)
public Set<String> getScope() {
return scope;

View File

@ -70,8 +70,6 @@ public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
// our refresh tokens might expire
private Date expiration;
private Set<String> scope; // we save the scope issued to the refresh token so that we can reissue a new access token
/**
*
*/
@ -173,25 +171,6 @@ public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
this.client = client;
}
/**
* @return the scope
*/
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
joinColumns=@JoinColumn(name="owner_id"),
name="scope"
)
public Set<String> getScope() {
return scope;
}
/**
* @param scope the scope to set
*/
public void setScope(Set<String> scope) {
this.scope = scope;
}
/**
* Get the JWT object directly
* @return the jwt

View File

@ -131,7 +131,12 @@ CREATE TABLE resource_id (
resource_id VARCHAR(256)
);
CREATE TABLE scope (
CREATE TABLE client_scope (
owner_id VARCHAR(4096),
scope VARCHAR(2048)
);
CREATE TABLE token_scope (
owner_id VARCHAR(4096),
scope VARCHAR(2048)
);

View File

@ -111,12 +111,6 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
Date expiration = new Date(System.currentTimeMillis() + (client.getRefreshTokenValiditySeconds() * 1000L));
refreshToken.setExpiration(expiration);
}
// save our scopes so that we can reuse them later for more auth tokens
// TODO: save the auth instead of the just the scope?
if (client.isScoped()) {
refreshToken.setScope(token.getScope());
}
//Add the authentication
refreshToken.setAuthenticationHolder(authHolder);
@ -173,20 +167,22 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
OAuth2AccessTokenEntity token = new OAuth2AccessTokenEntity();
// get the stored scopes from the authentication holder's authorization request; these are the scopes associated with the refresh token
Set<String> refreshScopes = refreshToken.getAuthenticationHolder().getAuthentication().getAuthorizationRequest().getScope();
if (scope != null && !scope.isEmpty()) {
// ensure a proper subset of scopes
if (refreshToken.getScope() != null && refreshToken.getScope().containsAll(scope)) {
// ensure a proper subset of scopes
if (refreshScopes != null && refreshScopes.containsAll(scope)) {
// set the scope of the new access token if requested
token.setScope(scope);
} else {
// up-scoping is not allowed
// (TODO: should this throw InvalidScopeException? For now just pass through)
token.setScope(refreshToken.getScope());
token.setScope(refreshScopes);
}
} else {
// otherwise inherit the scope of the refresh token (if it's there -- this can return a null scope set)
token.setScope(refreshToken.getScope());
token.setScope(refreshScopes);
}
token.setClient(client);