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-server): added sector_identifier_uri content validation (certification) #3639 #3641

Merged
merged 1 commit into from
Jan 17, 2023
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 @@ -312,6 +312,7 @@ public boolean validateRedirectUris(List<GrantType> grantTypes, List<ResponseTyp
}

// Validate Sector Identifier URL
boolean noRedirectUriInSectorIdentifierUri = false;
if (valid && StringUtils.isNotBlank(sectorIdentifierUrl)) {
try {
URI uri = new URI(sectorIdentifierUrl);
Expand All @@ -337,6 +338,10 @@ public boolean validateRedirectUris(List<GrantType> grantTypes, List<ResponseTyp
} catch (Exception e) {
log.debug(e.getMessage(), e);
valid = false;
} finally {
if (!valid) {
noRedirectUriInSectorIdentifierUri = true;
}
}
}

Expand All @@ -345,6 +350,10 @@ public boolean validateRedirectUris(List<GrantType> grantTypes, List<ResponseTyp
valid = checkWhiteListRedirectUris(redirectUris) && checkBlackListRedirectUris(redirectUris);
}

if (noRedirectUriInSectorIdentifierUri) {
throw errorResponseFactory.createWebApplicationException(Response.Status.BAD_REQUEST, RegisterErrorResponseType.INVALID_CLIENT_METADATA, "Failed to validate redirect uris. No redirect_uri in sector_identifier_uri content.");
}

return valid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import com.beust.jcommander.internal.Lists;
import io.jans.as.client.RegisterRequest;
import io.jans.as.model.common.GrantType;
import io.jans.as.model.common.ResponseType;
import io.jans.as.model.common.SubjectType;
import io.jans.as.model.configuration.AppConfiguration;
import io.jans.as.model.crypto.signature.SignatureAlgorithm;
import io.jans.as.model.error.ErrorResponseFactory;
import io.jans.as.model.register.ApplicationType;
import io.jans.as.model.register.RegisterErrorResponseType;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
Expand All @@ -14,7 +20,7 @@
import org.testng.annotations.Test;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

/**
* @author Yuriy Z
Expand All @@ -34,6 +40,22 @@ public class RegisterParamsValidatorTest {
@Mock
private ErrorResponseFactory errorResponseFactory;

@Test
public void validateRedirectUris_whenSectorIdentifierDoesNotHostValidRedirectUri_shouldThrowInvalidClientMetadataError() {
try {
when(errorResponseFactory.createWebApplicationException(any(), any(), any())).thenCallRealMethod();
registerParamsValidator.validateRedirectUris(
Lists.newArrayList(GrantType.AUTHORIZATION_CODE),
Lists.newArrayList(ResponseType.CODE),
ApplicationType.WEB,
SubjectType.PAIRWISE,
Lists.newArrayList("https://someuri.com"),
"https://invaliduri.com");
} catch (WebApplicationException e) {
verify(errorResponseFactory, times(1)).createWebApplicationException(eq(Response.Status.BAD_REQUEST), eq(RegisterErrorResponseType.INVALID_CLIENT_METADATA), any());
}
}

@Test
public void validateAlgorithms_whenAlgIsAmoungSupported_shouldNotRaiseException() {
RegisterRequest request = new RegisterRequest();
Expand Down