Skip to content

Commit 92eea4d

Browse files
authored
fix(config-api) authorization code issue (#11576)
Signed-off-by: pujavs <[email protected]>
1 parent c8b7437 commit 92eea4d

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

jans-config-api/docs/jans-config-api-swagger.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9336,19 +9336,19 @@ components:
93369336
type: string
93379337
selected:
93389338
type: boolean
9339-
whitePagesCanView:
9339+
userCanView:
93409340
type: boolean
9341-
adminCanAccess:
9341+
userCanEdit:
9342+
type: boolean
9343+
adminCanView:
93429344
type: boolean
93439345
adminCanEdit:
93449346
type: boolean
93459347
userCanAccess:
93469348
type: boolean
9347-
adminCanView:
9348-
type: boolean
9349-
userCanView:
9349+
adminCanAccess:
93509350
type: boolean
9351-
userCanEdit:
9351+
whitePagesCanView:
93529352
type: boolean
93539353
baseDn:
93549354
type: string
@@ -10232,6 +10232,8 @@ components:
1023210232
type: boolean
1023310233
lockMessageConfig:
1023410234
$ref: '#/components/schemas/LockMessageConfig'
10235+
fapi:
10236+
type: boolean
1023510237
allResponseTypesSupported:
1023610238
uniqueItems: true
1023710239
type: array
@@ -10241,8 +10243,6 @@ components:
1024110243
- code
1024210244
- token
1024310245
- id_token
10244-
fapi:
10245-
type: boolean
1024610246
AuthenticationFilter:
1024710247
required:
1024810248
- baseDn
@@ -11995,8 +11995,6 @@ components:
1199511995
$ref: '#/components/schemas/TokenAttributes'
1199611996
dpop:
1199711997
type: string
11998-
accessToken:
11999-
type: boolean
1200011998
tokenTypeEnum:
1200111999
type: string
1200212000
enum:
@@ -12006,6 +12004,8 @@ components:
1200612004
- REFRESH_TOKEN
1200712005
- AUTHORIZATION_CODE
1200812006
- TX_TOKEN
12007+
accessToken:
12008+
type: boolean
1200912009
TokenEntityPagedResult:
1201012010
type: object
1201112011
properties:

jans-config-api/server/src/main/java/io/jans/configapi/security/service/OpenIdAuthorizationService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ private String validateScope(String accessToken, List<String> tokenScopes, Resou
128128
List<String> resourceScopes = getAllScopeList(resourceScopesByType);
129129
logger.debug("Validate scope, resourceScopesByType: {}, resourceScopes: {}", resourceScopesByType,
130130
resourceScopes);
131-
131+
132+
//If no scope required
133+
if (resourceScopes == null || resourceScopes.isEmpty()) {
134+
logger.info(" If no resource scopes required return original accessToken");
135+
return AUTHENTICATION_SCHEME + accessToken;
136+
}
137+
132138
// find missing scopes
133139
List<String> missingScopes = findMissingScopes(resourceScopesByType, tokenScopes);
134140
logger.info("missingScopes:{}", missingScopes);

jans-config-api/server/src/main/java/io/jans/configapi/util/AuthUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,12 @@ public List<String> getAuthSpecificScopeRequired(ResourceInfo resourceInfo) {
359359
}
360360

361361
public List<String> findMissingElements(List<String> list1, List<String> list2) {
362-
if (list1 == null || list1.isEmpty() || list2 == null || list2.isEmpty()) {
362+
if (list1 == null || list1.isEmpty()) {
363363
return Collections.emptyList();
364364
}
365+
if(list2==null || list2.isEmpty()) {
366+
return list1;
367+
}
365368
return list1.stream().filter(e -> !list2.contains(e)).collect(Collectors.toList());
366369
}
367370

jans-config-api/server/src/test/java/io/jans/configapi/test/auth/ClientResourceTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ public void getAllClient(final String issuer, final String openidClientsUrl) {
3232
assertEquals(response.getStatus(), Status.OK.getStatusCode());
3333

3434
}
35+
36+
@Parameters({ "test.issuer", "openidClientsUrl" })
37+
@Test
38+
public void getClientsWithInvalidToken(final String issuer, final String openidClientsUrl) {
39+
log.info("getAllClient() - issuer:{}, openidClientsUrl:{}", issuer, openidClientsUrl);
40+
String invalidToken = this.getAccessTokenForGivenScope("https://jans.io/oauth/config/attributes.readonly");
41+
log.info("getAllClient() - invalidToken:{}, issuer:{}, openidClientsUrl:{}", invalidToken, issuer, openidClientsUrl);
42+
Builder request = getResteasyService().getClientBuilder(issuer + openidClientsUrl);
43+
request.header(AUTHORIZATION, AUTHORIZATION_TYPE + " " + invalidToken);
44+
request.header(CONTENT_TYPE, MediaType.APPLICATION_JSON);
45+
46+
Response response = request.get();
47+
log.info("Response for getClientsWithInvalidToken - response:{}, response.getStatus():{}", response, response.getStatus());
48+
assertEquals(response.getStatus(), Status.UNAUTHORIZED.getStatusCode());
49+
50+
}
3551

3652
@Parameters({ "test.issuer", "openidClientsUrl", "openid_client_1" })
3753
@Test

jans-config-api/shared/src/main/java/io/jans/configapi/core/test/BaseTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ public void getAccessToken() {
7272
log.info("accessToken:{}", accessToken);
7373
}
7474

75+
public String getAccessTokenForGivenScope(String scopes) {
76+
log.info("getAccessToken - propertiesMap:{}", propertiesMap);
77+
String tokenUrl = propertiesMap.get("token.endpoint");
78+
String strGrantType = propertiesMap.get("token.grant.type");
79+
String clientId = propertiesMap.get("test.client.id");
80+
String clientSecret = propertiesMap.get("test.client.secret");
81+
GrantType grantType = GrantType.fromString(strGrantType);
82+
String token = getToken(tokenUrl, clientId, clientSecret, grantType, scopes);
83+
log.info("token:{}", token);
84+
return token;
85+
}
86+
7587
protected String getToken(final String tokenUrl, final String clientId, final String clientSecret,
7688
GrantType grantType, final String scopes) {
7789
return getTokenService().getToken(tokenUrl, clientId, clientSecret, grantType, scopes);

0 commit comments

Comments
 (0)