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

Removes support for APIKEY #76

Merged
merged 1 commit into from
Jan 19, 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
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ services:
reuse_cached_search_results_millis: 0
subscription.resthook.enabled: true
subscription.websocket.enabled: true
APIKEY_ENABLED: false
APIKEY: abc123
OAUTH_ENABLED: true
OAUTH_CLIENT_ID: fhir4-api
OAUTH_USER_ROLE: fhir4-user
Expand Down
36 changes: 3 additions & 33 deletions src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class AppProperties {

private Validation validation = new Validation();
private Map<String, Tester> tester = null;
private Apikey apikey = new Apikey();
private Oauth oauth = new Oauth();
private Smart smart = new Smart();
private Logger logger = new Logger();
Expand Down Expand Up @@ -244,14 +243,6 @@ public void setSupported_resource_types(List<String> supported_resource_types) {
this.supported_resource_types = supported_resource_types;
}

public Apikey getApikey() {
return apikey;
}

public void setApikey(Apikey apikey) {
this.apikey = apikey;
}

public Oauth getOauth() {
return oauth;
}
Expand Down Expand Up @@ -578,15 +569,15 @@ public void setNormalized_quantity_search_level(NormalizedQuantitySearchLevel no
public boolean getInstall_transitive_ig_dependencies() {
return install_transitive_ig_dependencies;
}

public void setInstall_transitive_ig_dependencies(boolean install_transitive_ig_dependencies) {
this.install_transitive_ig_dependencies = install_transitive_ig_dependencies;
}

public boolean getReload_existing_implementationguides() {
return reload_existing_implementationguides;
}

public void setReload_existing_implementationguides(boolean reload_existing_implementationguides) {
this.reload_existing_implementationguides = reload_existing_implementationguides;
}
Expand Down Expand Up @@ -634,27 +625,6 @@ public void setAllow_Credentials(Boolean allow_Credentials) {

}

public static class Apikey {
private Boolean enabled = false;
private String key;

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}
}

public static class Oauth {
private Boolean enabled = false;
private String jwks_url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public FhirServerConfigCommon(AppProperties appProperties) {
ourLog.info("Indexed on contained resource enabled");
}

ourLog.info("Server configured to {} API Key authentication", appProperties.getApikey().getEnabled() ? "enable" : "disable");
ourLog.info("Server configured to {} OAuth2 authentication", appProperties.getOauth().getEnabled() ? "enable" : "disable");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,14 @@ public RestfulServer restfulServer(IFhirSystemDao<?, ?> fhirSystemDao, AppProper
// Support for OAuth2 and API_KEY authentication
if (appProperties.getOauth().getEnabled()) {
fhirServer.registerInterceptor(new CapabilityStatementCustomizer(appProperties));
fhirServer.registerInterceptor(new CustomAuthorizationInterceptor(appProperties));
fhirServer.registerInterceptor(new CustomSearchNarrowingInterceptor(appProperties));
FhirVersionEnum fhirVersion = fhirServer.getFhirContext().getVersion().getVersion();
if (fhirVersion != FhirVersionEnum.R5) {
// Utilize the consent interceptor to simulate a patient compartment for the Task resource
fhirServer.registerInterceptor(new ConsentInterceptor(new CustomConsentService(daoRegistry, appProperties)));
}
}
if (appProperties.getOauth().getEnabled()
|| appProperties.getApikey().getEnabled()) {
fhirServer.registerInterceptor(new CustomAuthorizationInterceptor(appProperties));
}

repositoryValidatingInterceptor.ifPresent(fhirServer::registerInterceptor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.jpa.starter.AppProperties;
import ca.uhn.fhir.jpa.starter.util.ApiKeyHelper;
import ca.uhn.fhir.jpa.starter.util.OAuth2Helper;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.RequestTypeEnum;
Expand All @@ -36,7 +35,7 @@ public CustomAuthorizationInterceptor(AppProperties config) {

@Override
public List<IAuthRule> buildRuleList(RequestDetails theRequest) {
if (!isAnyEnabled()) {
if (!isOAuthEnabled()) {
return authorizedRule();
}

Expand All @@ -48,9 +47,6 @@ public List<IAuthRule> buildRuleList(RequestDetails theRequest) {
if (isUsingOAuth(theRequest)) {
return authorizeOAuth(theRequest);
}
if (isUsingApiKey(theRequest)) {
return authorizeApiKey(theRequest);
}
logger.warn("Authorization failed - no authorization supplied");
} catch (AuthenticationException e) {
throw e;
Expand All @@ -61,18 +57,10 @@ public List<IAuthRule> buildRuleList(RequestDetails theRequest) {
throw new AuthenticationException("Missing or invalid authorization");
}

private boolean isAnyEnabled() {
return isOAuthEnabled() || isApiKeyEnabled();
}

private boolean isUsingOAuth(RequestDetails theRequest) {
return isOAuthEnabled() && OAuth2Helper.hasToken(theRequest);
}

private boolean isUsingApiKey(RequestDetails theRequest) {
return isApiKeyEnabled() && ApiKeyHelper.hasApiKey(theRequest);
}

private List<IAuthRule> authorizedRule() {
return new RuleBuilder()
.allowAll()
Expand Down Expand Up @@ -158,22 +146,4 @@ private String getOAuthUserRole() {
private String getOAuthAdminRole() {
return config.getOauth().getAdmin_role();
}

private boolean isApiKeyEnabled() {
return config.getApikey().getEnabled();
}

private String getApiKey() {
return config.getApikey().getKey();
}

private List<IAuthRule> authorizeApiKey(RequestDetails theRequest) throws AuthenticationException {
logger.info("Authorizing via API Key");
if (ApiKeyHelper.isAuthorized(theRequest, getApiKey())) {
return authorizedRule();
}

logger.warn("API key authorization failure - invalid x-api-key specified");
throw new AuthenticationException("Invalid x-api-key");
}
}
23 changes: 0 additions & 23 deletions src/main/java/ca/uhn/fhir/jpa/starter/util/ApiKeyHelper.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/resources/application-custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ hapi:
token_url: ${OAUTH_TOKEN_URL}
manage_url: ${OAUTH_MANAGE_URL}

apikey:
enabled: ${APIKEY_ENABLED:false}
key: ${APIKEY}

smart:
issuer: ${SMART_ISSUER}
jwks_url: ${SMART_JWKS_URL}
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ hapi:
token_url: ${OAUTH_TOKEN_URL}
manage_url: ${OAUTH_MANAGE_URL}

apikey:
enabled: ${APIKEY_ENABLED:false}
key: ${APIKEY}

smart:
issuer: ${SMART_ISSUER}
jwks_url: ${SMART_JWKS_URL}
Expand Down
Loading