-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Keycloak integration test to DataflowOAuthIT Adds Authorities mapping test similar to keycloak role usage. Added scripts to src/local for testing keycloak locally with preconfigured roles / group and user.
- Loading branch information
Showing
36 changed files
with
4,940 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 130 additions & 53 deletions
183
...ava/org/springframework/cloud/dataflow/integration/test/db/container/DataflowCluster.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...c/test/java/org/springframework/cloud/dataflow/unit/test/DataFlowAuthenticationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.springframework.cloud.dataflow.unit.test; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import dasniko.testcontainers.keycloak.KeycloakContainer; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.cloud.dataflow.rest.client.DataFlowOperations; | ||
import org.springframework.cloud.dataflow.rest.client.config.DataFlowClientAutoConfiguration; | ||
import org.springframework.cloud.dataflow.rest.resource.about.AboutResource; | ||
import org.springframework.cloud.dataflow.server.single.DataFlowServerApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ActiveProfiles("keycloak") | ||
@SpringBootTest(classes = { DataFlowServerApplication.class }, | ||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) | ||
@Testcontainers | ||
@Disabled("Determine how to run app and test client in different contexts") | ||
public class DataFlowAuthenticationTests { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DataFlowAuthenticationTests.class); | ||
|
||
@Container | ||
static KeycloakContainer keycloakContainer = new KeycloakContainer("keycloak/keycloak:25.0") | ||
.withRealmImportFiles("/dataflow-realm.json", "/dataflow-users-0.json") | ||
.withAdminUsername("admin") | ||
.withAdminPassword("admin") | ||
.withExposedPorts(8080, 9000) | ||
.withLogConsumer(outputFrame -> { | ||
switch (outputFrame.getType()) { | ||
case STDERR: | ||
logger.error(outputFrame.getUtf8StringWithoutLineEnding()); | ||
break; | ||
default: | ||
logger.info(outputFrame.getUtf8StringWithoutLineEnding()); | ||
} | ||
}); | ||
|
||
@DynamicPropertySource | ||
static void configureProperties(DynamicPropertyRegistry registry) { | ||
registry.add("keycloak.url", keycloakContainer::getAuthServerUrl); | ||
} | ||
|
||
@Test | ||
void testAuthentication() throws Exception { | ||
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(CommandLineApp.class, | ||
"--spring.profiles.active=keycloak-client", | ||
"--spring.cloud.dataflow.client.authentication.basic.username=joe", | ||
"--spring.cloud.dataflow.client.authentication.basic.password=password", | ||
"--keycloak.url=" + keycloakContainer.getAuthServerUrl(), | ||
"--spring.cloud.dataflow.client.authentication.token-uri=" + keycloakContainer.getAuthServerUrl() | ||
+ "/realms/dataflow/protocol/openid-connect/token")) { | ||
DataFlowOperations dataFlowOperations = applicationContext.getBean(DataFlowOperations.class); | ||
assertThat(dataFlowOperations).isNotNull(); | ||
AboutResource aboutResource = dataFlowOperations.aboutOperation().get(); | ||
assertThat(aboutResource).isNotNull(); | ||
assertThat(aboutResource.getSecurityInfo()).isNotNull(); | ||
assertThat(aboutResource.getSecurityInfo().isAuthenticated()).isTrue(); | ||
assertThat(aboutResource.getSecurityInfo().getUsername()).isEqualTo("joe"); | ||
CommandLineApp.completed.set(true); | ||
} | ||
finally { | ||
CommandLineApp.completed.set(true); | ||
} | ||
} | ||
|
||
@SpringBootApplication | ||
@ImportAutoConfiguration(DataFlowClientAutoConfiguration.class) | ||
public static class CommandLineApp implements CommandLineRunner { | ||
|
||
public static AtomicBoolean completed = new AtomicBoolean(false); | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
Awaitility.await().until(() -> completed.get()); | ||
} | ||
|
||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
spring-cloud-dataflow-server/src/test/resources/application-keycloak-client.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
spring: | ||
cloud: | ||
dataflow: | ||
security: | ||
authorization: | ||
provider-role-mappings: | ||
keycloak: | ||
map-group-claims: true | ||
role-mappings: | ||
ROLE_VIEW: dataflow_view | ||
ROLE_CREATE: dataflow_create | ||
ROLE_MANAGE: dataflow_manage | ||
ROLE_DEPLOY: dataflow_deploy | ||
ROLE_DESTROY: dataflow_destroy | ||
ROLE_MODIFY: dataflow_modify | ||
ROLE_SCHEDULE: dataflow_schedule | ||
client: | ||
authentication: | ||
client-id: 'dataflow' | ||
client-secret: '090RucamvekrMLyGHMr4lkHX9xhAlsqK' | ||
oauth2: | ||
client-registration-id: keycloak | ||
scope: openid, roles | ||
security: | ||
oauth2: | ||
client: | ||
provider: | ||
keycloak: | ||
issuer-uri: '${keycloak.url}/realms/dataflow' | ||
jwk-set-uri: '${keycloak.url}/realms/dataflow/protocol/openid-connect/certs' | ||
token-uri: '${keycloak.url}/realms/dataflow/protocol/openid-connect/token' | ||
user-info-uri: '${keycloak.url}/realms/dataflow/protocol/openid-connect/userinfo' | ||
user-name-attribute: 'user_name' | ||
authorization-uri: '${keycloak.url}/realms/dataflow/protocol/openid-connect/auth' | ||
registration: | ||
keycloak: | ||
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}' | ||
client-id: 'dataflow' | ||
client-name: 'dataflow' | ||
client-secret: '090RucamvekrMLyGHMr4lkHX9xhAlsqK' | ||
provider: 'keycloak' | ||
authorization-grant-type: 'authorization_code' | ||
# client-authentication-method: # unsure of value | ||
scope: | ||
- openid | ||
- roles | ||
resourceserver: | ||
opaquetoken: | ||
introspection-uri: ${keycloak.url}/realms/dataflow/protocol/openid-connect/token/introspect | ||
client-id: 'dataflow' | ||
client-secret: '090RucamvekrMLyGHMr4lkHX9xhAlsqK' | ||
authorization: | ||
check-token-access: isAuthenticated() | ||
logging: | ||
level: | ||
org.springframework.security: debug | ||
org.springframework.web: debug | ||
org.springframework.cloud.dataflow: debug | ||
org.springframework.cloud.common: debug | ||
org.apache.hc: debug | ||
org.apache.http: debug | ||
threshold: | ||
console: debug |
Oops, something went wrong.