Skip to content

Commit

Permalink
feat: support keycloakTokenUrl for Self-Managed
Browse files Browse the repository at this point in the history
(cherry picked from commit 7e98147)
  • Loading branch information
1nb0und committed Jan 2, 2024
1 parent 4e529ca commit 56af414
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SelfManagedAuthentication extends JwtAuthentication {
// TODO: Check with Identity about upcoming IDPs to abstract this
private String keycloakRealm = "camunda-platform";
private String keycloakUrl;
private String keycloakTokenUrl;
private JwtConfig jwtConfig;
private Map<Product, String> tokens;

Expand All @@ -51,13 +52,21 @@ public void setKeycloakUrl(String keycloakUrl) {
this.keycloakUrl = keycloakUrl;
}

public void setKeycloakTokenUrl(String keycloakTokenUrl) {
this.keycloakTokenUrl = keycloakTokenUrl;
}

public void setJwtConfig(JwtConfig jwtConfig) {
this.jwtConfig = jwtConfig;
}

@Override
public Authentication build() {
authUrl = keycloakUrl+"/auth/realms/"+keycloakRealm+"/protocol/openid-connect/token";
if (keycloakTokenUrl != null) {
authUrl = keycloakTokenUrl;
} else {
authUrl = keycloakUrl+"/auth/realms/"+keycloakRealm+"/protocol/openid-connect/token";
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public SelfManagedAuthenticationBuilder keycloakRealm(String keycloakRealm) {
return this;
}

public SelfManagedAuthenticationBuilder keycloakTokenUrl(String keycloakTokenUrl) {
if (keycloakTokenUrl != null) {
selfManagedAuthentication.setKeycloakTokenUrl(keycloakTokenUrl);
}
return this;
}

public Authentication build() {
return selfManagedAuthentication.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public Authentication authentication() {
.keycloakUrl(operateClientConfigurationProperties.getKeycloakUrl())
.keycloakRealm(operateClientConfigurationProperties.getKeycloakRealm())
.build();
} else if (operateClientConfigurationProperties.getUsername() != null && operateClientConfigurationProperties.getPassword() != null) {
} else if (operateClientConfigurationProperties.getKeycloakTokenUrl() != null) {
return SelfManagedAuthentication.builder()
.jwtConfig(configureJwtConfig())
.keycloakTokenUrl(operateClientConfigurationProperties.getKeycloakTokenUrl())
.build();
} else if (operateClientConfigurationProperties.getUsername() != null && operateClientConfigurationProperties.getPassword() != null) {
SimpleConfig simpleConfig = new SimpleConfig();
SimpleCredential simpleCredential = new SimpleCredential(operateClientConfigurationProperties.getUsername(), operateClientConfigurationProperties.getPassword());
simpleConfig.addProduct(Product.OPERATE, simpleCredential);
Expand All @@ -68,6 +73,11 @@ public Authentication authentication() {
.keycloakUrl(commonConfigurationProperties.getKeycloak().getUrl())
.keycloakRealm(commonConfigurationProperties.getKeycloak().getRealm())
.build();
} else if (commonConfigurationProperties.getKeycloak().getTokenUrl() != null) {
return SelfManagedAuthentication.builder()
.jwtConfig(configureJwtConfig())
.keycloakTokenUrl(commonConfigurationProperties.getKeycloak().getTokenUrl())
.build();
} else if (commonConfigurationProperties.getUsername() != null && commonConfigurationProperties.getPassword() != null) {
SimpleConfig simpleConfig = new SimpleConfig();
SimpleCredential simpleCredential = new SimpleCredential(commonConfigurationProperties.getUsername(), commonConfigurationProperties.getPassword());
Expand Down Expand Up @@ -125,8 +135,8 @@ private JwtConfig configureJwtConfig() {
jwtConfig.addProduct(Product.OPERATE, new JwtCredential(
commonConfigurationProperties.getClientId(),
commonConfigurationProperties.getClientSecret(),
operateAuthUrl,
operateAudience)
operateAudience,
operateAuthUrl)
);
} else if (zeebeClientConfigurationProperties.getCloud().getClientId() != null && zeebeClientConfigurationProperties.getCloud().getClientSecret() != null) {
jwtConfig.addProduct(Product.OPERATE, new JwtCredential(zeebeClientConfigurationProperties.getCloud().getClientId(), zeebeClientConfigurationProperties.getCloud().getClientSecret(), operateAudience, operateAuthUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ static class BaseUrlCondition { }
@ConditionalOnProperty(name = "camunda.operate.client.keycloak-url")
static class KeycloakUrlCondition { }

@ConditionalOnProperty(name = "camunda.operate.client.keycloak-token-url")
static class KeycloakTokenUrlCondition { }

@ConditionalOnProperty(name = "camunda.operate.client.url")
static class UrlCondition { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class OperateClientConfigurationProperties {
private String keycloakUrl;
private String keycloakRealm = "camunda-platform";

private String keycloakTokenUrl;

private String baseUrl;

private String authUrl;
Expand Down Expand Up @@ -96,6 +98,14 @@ public void setKeycloakRealm(String keycloakRealm) {
this.keycloakRealm = keycloakRealm;
}

public String getKeycloakTokenUrl() {
return keycloakTokenUrl;
}

public void setKeycloakTokenUrl(String keycloakTokenUrl) {
this.keycloakTokenUrl = keycloakTokenUrl;
}

public String getBaseUrl() {
return baseUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class Keycloak {

private String url;
private String realm;
private String tokenUrl;

public String getUrl() {
return url;
Expand All @@ -20,4 +21,12 @@ public String getRealm() {
public void setRealm(String realm) {
this.realm = realm;
}

public String getTokenUrl() {
return tokenUrl;
}

public void setTokenUrl(String tokenUrl) {
this.tokenUrl = tokenUrl;
}
}

0 comments on commit 56af414

Please sign in to comment.