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(oidc): add configurable read timeout #5088

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions datahub-frontend/app/auth/sso/oidc/OidcConfigs.java
Expand Up @@ -36,6 +36,7 @@ public class OidcConfigs extends SsoConfigs {
public static final String OIDC_RESPONSE_MODE = "auth.oidc.responseMode";
public static final String OIDC_USE_NONCE = "auth.oidc.useNonce";
public static final String OIDC_CUSTOM_PARAM_RESOURCE = "auth.oidc.customParam.resource";
public static final String OIDC_READ_TIMEOUT = "auth.oidc.readTimeout";

/**
* Default values
Expand All @@ -49,6 +50,7 @@ public class OidcConfigs extends SsoConfigs {
private static final String DEFAULT_OIDC_PRE_PROVISIONING_REQUIRED = "false";
private static final String DEFAULT_OIDC_EXTRACT_GROUPS_ENABLED = "false"; // False since extraction of groups can overwrite existing group membership.
private static final String DEFAULT_OIDC_GROUPS_CLAIM = "groups";
private static final String DEFAULT_OIDC_READ_TIMEOUT = "5000";

private String clientId;
private String clientSecret;
Expand All @@ -66,6 +68,7 @@ public class OidcConfigs extends SsoConfigs {
private Optional<String> responseMode;
private Optional<Boolean> useNonce;
private Optional<String> customParamResource;
private String readTimeout;

public OidcConfigs(final com.typesafe.config.Config configs) {
super(configs);
Expand All @@ -90,5 +93,6 @@ public OidcConfigs(final com.typesafe.config.Config configs) {
responseMode = getOptional(configs, OIDC_RESPONSE_MODE);
useNonce = getOptional(configs, OIDC_USE_NONCE).map(Boolean::parseBoolean);
customParamResource = getOptional(configs, OIDC_CUSTOM_PARAM_RESOURCE);
readTimeout = getOptional(configs, OIDC_READ_TIMEOUT, DEFAULT_OIDC_READ_TIMEOUT);
}
}
7 changes: 7 additions & 0 deletions datahub-frontend/app/auth/sso/oidc/OidcProvider.java
Expand Up @@ -3,6 +3,7 @@
import auth.sso.SsoProvider;
import auth.sso.oidc.custom.CustomOidcClient;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.pac4j.core.client.Client;
import org.pac4j.core.http.callback.PathParameterCallbackUrlResolver;
import org.pac4j.oidc.config.OidcConfiguration;
Expand All @@ -19,6 +20,7 @@
* It is responsible for initializing this client from a configuration object ({@link OidcConfigs}. Note that
* this class is not related to the logic performed when an IdP performs a callback to DataHub.
*/
@Slf4j
public class OidcProvider implements SsoProvider<OidcConfigs> {

private static final String OIDC_CLIENT_NAME = "oidc";
Expand Down Expand Up @@ -53,6 +55,11 @@ private Client<OidcCredentials, OidcProfile> createPac4jClient() {
oidcConfiguration.setDiscoveryURI(_oidcConfigs.getDiscoveryUri());
oidcConfiguration.setClientAuthenticationMethodAsString(_oidcConfigs.getClientAuthenticationMethod());
oidcConfiguration.setScope(_oidcConfigs.getScope());
try {
oidcConfiguration.setReadTimeout(Integer.parseInt(_oidcConfigs.getReadTimeout()));
} catch (NumberFormatException e) {
log.warn("Invalid read timeout configuration, defaulting to 5000ms");
}
_oidcConfigs.getResponseType().ifPresent(oidcConfiguration::setResponseType);
_oidcConfigs.getResponseMode().ifPresent(oidcConfiguration::setResponseMode);
_oidcConfigs.getUseNonce().ifPresent(oidcConfiguration::setUseNonce);
Expand Down
1 change: 1 addition & 0 deletions datahub-frontend/conf/application.conf
Expand Up @@ -136,6 +136,7 @@ auth.oidc.responseType = ${?AUTH_OIDC_RESPONSE_TYPE}
auth.oidc.responseMode = ${?AUTH_OIDC_RESPONSE_MODE}
auth.oidc.useNonce = ${?AUTH_OIDC_USE_NONCE}
auth.oidc.customParam.resource = ${?AUTH_OIDC_CUSTOM_PARAM_RESOURCE}
auth.oidc.readTimeout = ${?AUTH_OIDC_READ_TIMEOUT}

#
# By default, the callback URL that should be registered with the identity provider is computed as {$baseUrl}/callback/oidc.
Expand Down
1 change: 1 addition & 0 deletions datahub-frontend/play.gradle
Expand Up @@ -49,6 +49,7 @@ dependencies {

testImplementation externalDependency.mockito
testImplementation externalDependency.playTest
testCompile externalDependency.testng

compileOnly externalDependency.lombok
runtime externalDependency.guice
Expand Down
2 changes: 1 addition & 1 deletion datahub-frontend/test/security/DummyLoginModuleTest.java
Expand Up @@ -4,7 +4,7 @@
import java.util.HashMap;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import org.junit.Test;
import org.testng.annotations.Test;

import static org.junit.Assert.*;

Expand Down