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

fix(jans-auth-server): do not recognize different agama flows as different acr #8652 #8654

Merged
merged 3 commits into from
Jun 4, 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 @@ -32,6 +32,8 @@
@Named
public class AcrService {

public static final String AGAMA = "agama";

@Inject
private Logger log;

Expand All @@ -48,7 +50,7 @@ public class AcrService {
private AppConfiguration appConfiguration;

public static boolean isAgama(String acr) {
return StringUtils.isNotBlank(acr) && acr.startsWith("agama_");
return StringUtils.isNotBlank(acr) && (acr.startsWith("agama_") || acr.equalsIgnoreCase(AGAMA));
}

public void validateAcrs(AuthzRequest authzRequest, Client client) throws AcrChangedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public String getAcr(SessionId session) {
return acr;
}

public static boolean isAgamaInSessionAndRequest(String sessionAcr, List<String> acrValuesList) {
return isAgama(sessionAcr) && !acrValuesList.isEmpty() && isAgama(acrValuesList.iterator().next());
}

// #34 - update session attributes with each request
// 1) redirect_uri change -> update session
// 2) acr change -> throw acr change exception
Expand All @@ -190,8 +194,7 @@ public SessionId assertAuthenticatedSessionCorrespondsToNewRequest(SessionId ses
}

List<String> acrValuesList = acrValuesList(acrValuesStr);
boolean isAgama = isAgama(sessionAcr) && !acrValuesList.isEmpty() && isAgama(acrValuesList.iterator().next());
boolean isAcrChanged = !acrValuesList.isEmpty() && !acrValuesList.contains(sessionAcr) && !isAgama;
boolean isAcrChanged = !acrValuesList.isEmpty() && !acrValuesList.contains(sessionAcr) && !isAgamaInSessionAndRequest(sessionAcr, acrValuesList);
if (isAcrChanged) {
Map<String, Integer> acrToLevel = externalAuthenticationService.acrToLevelMapping();
Integer sessionAcrLevel = Util.asInt(acrToLevel.get(externalAuthenticationService.scriptName(sessionAcr)), -1);
Expand Down Expand Up @@ -916,9 +919,16 @@ public List<String> acrValuesList(String acrValues) {

HashSet<String> resultAcrs = new HashSet<>();
for (String acr : acrs) {
resultAcrs.add(externalAuthenticationService.scriptName(acr));
String acrForScript = isAgama(acr) ? AcrService.AGAMA : acr;
final String scriptName = externalAuthenticationService.scriptName(acrForScript);
if (StringUtils.isNotBlank(scriptName)) {
resultAcrs.add(acr);
}
}

if (log.isTraceEnabled()) {
log.trace("acrValuesList {}", resultAcrs);
}
return new ArrayList<>(resultAcrs);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jans.as.server.service;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.jans.as.common.model.session.SessionId;
import io.jans.as.common.service.common.UserService;
Expand Down Expand Up @@ -82,6 +83,18 @@ public class SessionIdServiceTest {
@Mock
private StatService statService;

@Test
public void isAgamaInSessionAndRequest_forAgama_shouldReturnTrue() {
assertTrue(SessionIdService.isAgamaInSessionAndRequest("agama", Lists.newArrayList("agama_io.jans.agamaLab.main")));
assertTrue(SessionIdService.isAgamaInSessionAndRequest("agama", Lists.newArrayList("agama")));
}

@Test
public void isAgamaInSessionAndRequest_forBasic_shouldReturnFalse() {
assertFalse(SessionIdService.isAgamaInSessionAndRequest("agama", Lists.newArrayList("basic")));
assertFalse(SessionIdService.isAgamaInSessionAndRequest("basic", Lists.newArrayList("agama_io.jans.agamaLab.main")));
}

@Test
public void hasAllScopes_whenSessionIsNull_shouldReturnFalse() {
assertFalse(sessionIdService.hasAllScopes((SessionId) null, null));
Expand Down