-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include wlcg.groups information in userinfo response
Even though the IAM access token is a JWT and even though groups are included in the access token when requested, as mandated by the WLCG JWT profile, there are still apps treating the access token as an opaque string. To support those apps, and be more consistent with the traditional IAM profile behaviour, IAM should include group information in the userinfo endpoint response also for the WLCG profile. Issue: #432
- Loading branch information
1 parent
195c2d7
commit 4bfc271
Showing
6 changed files
with
227 additions
and
35 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
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
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
122 changes: 122 additions & 0 deletions
122
...ice/src/test/java/it/infn/mw/iam/test/oauth/profile/WLCGProfileUserinfoEndpointTests.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,122 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2019 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package it.infn.mw.iam.test.oauth.profile; | ||
|
||
import static org.hamcrest.CoreMatchers.hasItems; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.boot.test.WebIntegrationTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.jayway.restassured.RestAssured; | ||
|
||
import it.infn.mw.iam.IamLoginService; | ||
import it.infn.mw.iam.test.TestUtils; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = {IamLoginService.class}) | ||
@WebIntegrationTest(randomPort = true) | ||
@Transactional | ||
@TestPropertySource(properties = { | ||
// @formatter:off | ||
"iam.jwt-profile.default-profile=wlcg", | ||
"scope.matchers[0].name=storage.read", | ||
"scope.matchers[0].type=path", | ||
"scope.matchers[0].prefix=storage.read", | ||
"scope.matchers[0].path=/", | ||
"scope.matchers[1].name=storage.write", | ||
"scope.matchers[1].type=path", | ||
"scope.matchers[1].prefix=storage.write", | ||
"scope.matchers[1].path=/", | ||
"scope.matchers[2].name=wlcg.groups", | ||
"scope.matchers[2].type=regexp", | ||
"scope.matchers[2].regexp=^wlcg\\.groups(?::((?:\\/[a-zA-Z0-9][a-zA-Z0-9_.-]*)+))?$", | ||
// @formatter:on | ||
}) | ||
public class WLCGProfileUserinfoEndpointTests { | ||
|
||
private static final String USERNAME = "test"; | ||
private static final String PASSWORD = "password"; | ||
private static final String USERINFO_URL_TEMPLATE = "http://localhost:%d/userinfo"; | ||
|
||
@Value("${local.server.port}") | ||
private Integer iamPort; | ||
|
||
private String userinfoUrl; | ||
|
||
@Autowired | ||
ObjectMapper mapper; | ||
|
||
@BeforeClass | ||
public static void init() { | ||
TestUtils.initRestAssured(); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); | ||
RestAssured.port = iamPort; | ||
userinfoUrl = String.format(USERINFO_URL_TEMPLATE, iamPort); | ||
} | ||
|
||
@Test | ||
public void testUserinfoResponseWithGroups() { | ||
String accessToken = TestUtils.passwordTokenGetter() | ||
.port(iamPort) | ||
.username(USERNAME) | ||
.password(PASSWORD) | ||
.scope("openid profile wlcg.groups") | ||
.getAccessToken(); | ||
|
||
RestAssured.given() | ||
.header("Authorization", String.format("Bearer %s", accessToken)) | ||
.when() | ||
.get(userinfoUrl) | ||
.then() | ||
.statusCode(HttpStatus.OK.value()) | ||
.body("\"wlcg.groups\"", hasItems("/Analysis", "/Production")); | ||
} | ||
|
||
@Test | ||
public void testUserinfoResponseWithoutGroups() { | ||
String accessToken = TestUtils.passwordTokenGetter() | ||
.port(iamPort) | ||
.username(USERNAME) | ||
.password(PASSWORD) | ||
.scope("openid profile") | ||
.getAccessToken(); | ||
|
||
RestAssured.given() | ||
.header("Authorization", String.format("Bearer %s", accessToken)) | ||
.when() | ||
.get(userinfoUrl) | ||
.then() | ||
.statusCode(HttpStatus.OK.value()) | ||
.body("\"wlcg.groups\"", nullValue()); | ||
} | ||
|
||
} |