Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jans-auth): removed extra info from acr claim in id_token when it's an agama flow #8369

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static boolean isAgama(String acr) {
}

public void validateAcrs(AuthzRequest authzRequest, Client client) throws AcrChangedException {
removeParametersForAgamaAcr(authzRequest);

applyAcrMappings(authzRequest);

checkClientAuthorizedAcrs(authzRequest, client);
Expand All @@ -60,6 +62,24 @@ public void validateAcrs(AuthzRequest authzRequest, Client client) throws AcrCha
checkAcrChanged(authzRequest, identity.getSessionId()); // check after redirect uri is validated
}

public static void removeParametersForAgamaAcr(AuthzRequest authzRequest) {
final List<String> acrValues = authzRequest.getAcrValuesList();
for (int i = 0; i < acrValues.size(); i++) {
final String acr = acrValues.get(i);
acrValues.set(i, removeParametersFromAgamaAcr(acr));
}

final String result = implode(acrValues, " ");
authzRequest.setAcrValues(result);
}

public static String removeParametersFromAgamaAcr(String acr) {
if (isAgama(acr)) {
return StringUtils.substringBefore(acr, "-");
}
return acr;
}

public void checkClientAuthorizedAcrs(AuthzRequest authzRequest, Client client) {
final List<String> authorizedAcrs = client.getAttributes().getAuthorizedAcrValues();
if (authorizedAcrs.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public class AcrServiceTest {
@Mock
private AppConfiguration appConfiguration;

@Test
public void removeParametersFromAgamaAcr_whenAcrHasParameters_shouldRemoveParameters() {
assertEquals(AcrService.removeParametersFromAgamaAcr("agama_flow-parameter1"), "agama_flow");
assertEquals(AcrService.removeParametersFromAgamaAcr("agama_io.jans.flow-parameter1"), "agama_io.jans.flow");
assertEquals(AcrService.removeParametersFromAgamaAcr("agama_io.jans.flow"), "agama_io.jans.flow");
}

@Test
public void removeParametersFromAgamaAcr_whenAuthzRequestIsWithAcrWithParameters_shouldRemoveParameters() {
AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setAcrValues("agama_io.jans.flow-parameter1 acr2");

AcrService.removeParametersForAgamaAcr(authzRequest);

assertEquals(authzRequest.getAcrValues(), "agama_io.jans.flow acr2");
}

@Test
public void isAgama_whenAcrIsNullOrNonAgama_shouldReturnFalse() {
assertFalse(AcrService.isAgama(null));
Expand Down