|
8 | 8 | import javax.json.JsonObject; |
9 | 9 | import javax.ws.rs.WebApplicationException; |
10 | 10 | import javax.ws.rs.core.MultivaluedMap; |
11 | | -import java.util.*; |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.Date; |
| 13 | +import java.util.HashSet; |
| 14 | +import java.util.Set; |
12 | 15 |
|
13 | 16 | @Named("refresh_token") |
14 | 17 | public class RefreshTokenGrantTypeHandler extends AbstractGrantTypeHandler { |
@@ -40,24 +43,23 @@ public JsonObject createAccessToken(String clientId, MultivaluedMap<String, Stri |
40 | 43 | String subject = signedRefreshToken.getJWTClaimsSet().getSubject(); |
41 | 44 | String approvedScopes = signedRefreshToken.getJWTClaimsSet().getStringClaim("scope"); |
42 | 45 |
|
43 | | - String finalScope = approvedScopes; |
44 | 46 | String requestedScopes = params.getFirst("scope"); |
45 | 47 | if (requestedScopes != null && !requestedScopes.isEmpty()) { |
46 | | - Set<String> allowedScopes = new LinkedHashSet<>(); |
47 | 48 | Set<String> rScopes = new HashSet(Arrays.asList(requestedScopes.split(" "))); |
48 | 49 | Set<String> aScopes = new HashSet(Arrays.asList(approvedScopes.split(" "))); |
49 | | - for (String scope : rScopes) { |
50 | | - if (aScopes.contains(scope)) allowedScopes.add(scope); |
| 50 | + if (!aScopes.containsAll(rScopes)) { |
| 51 | + throw new WebApplicationException("Requested scopes should be a subset of those authorized by the resource owner."); |
51 | 52 | } |
52 | | - finalScope = String.join(" ", allowedScopes); |
| 53 | + } else { |
| 54 | + requestedScopes = approvedScopes; |
53 | 55 | } |
54 | 56 |
|
55 | | - String accessToken = getAccessToken(clientId, subject, finalScope); |
| 57 | + String accessToken = getAccessToken(clientId, subject, requestedScopes); |
56 | 58 | return Json.createObjectBuilder() |
57 | 59 | .add("token_type", "Bearer") |
58 | 60 | .add("access_token", accessToken) |
59 | 61 | .add("expires_in", expiresInMin * 60) |
60 | | - .add("scope", finalScope) |
| 62 | + .add("scope", requestedScopes) |
61 | 63 | .add("refresh_token", refreshToken) |
62 | 64 | .build(); |
63 | 65 | } |
|
0 commit comments