Skip to content

Commit

Permalink
Adds support for default first broker login flow on realm level
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilian-krauss committed Nov 7, 2024
1 parent 6f62723 commit 87c2a51
Show file tree
Hide file tree
Showing 12 changed files with 2,250 additions and 2 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ jobs:
key: ${{ runner.os }}-maven-${{ matrix.env.KEYCLOAK_VERSION }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-${{ matrix.env.KEYCLOAK_VERSION }}

- name: Adapt sources for Keycloak versions < 24.0.0
if: ${{ matrix.env.KEYCLOAK_VERSION < '24.0.0' }}
run: |
echo "COMPATIBILITY_PROFILE=-Ppre-keycloak24" >> $GITHUB_ENV
- name: Adapt sources for Keycloak versions < 23.0.0
if: ${{ matrix.env.KEYCLOAK_VERSION < '23.0.0' }}
run: |
Expand All @@ -72,7 +77,9 @@ jobs:
echo "COMPATIBILITY_PROFILE=-Ppre-keycloak19" >> $GITHUB_ENV
- name: Build & Test
run: ./mvnw ${MAVEN_CLI_OPTS} -Dkeycloak.version=${{ matrix.env.KEYCLOAK_VERSION }} ${ADJUSTED_RESTEASY_VERSION} clean verify -Pcoverage ${COMPATIBILITY_PROFILE}
run: |
echo "using COMPATIBILITY_PROFILE: ${COMPATIBILITY_PROFILE}"
./mvnw ${MAVEN_CLI_OPTS} -Dkeycloak.version=${{ matrix.env.KEYCLOAK_VERSION }} ${ADJUSTED_RESTEASY_VERSION} clean verify -Pcoverage ${COMPATIBILITY_PROFILE}
- name: Upload coverage to Codecov
uses: codecov/[email protected]
Expand Down Expand Up @@ -185,6 +192,11 @@ jobs:
key: ${{ runner.os }}-${{ matrix.java }}-maven-build-pom-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-${{ matrix.java }}-maven-build-pom

- name: Adapt sources for Keycloak versions < 24.0.0
if: ${{ matrix.env.KEYCLOAK_VERSION < '24.0.0' }}
run: |
echo "COMPATIBILITY_PROFILE=-Ppre-keycloak24" >> $GITHUB_ENV
- name: Adapt sources for Keycloak versions < 23.0.0
if: ${{ matrix.env.KEYCLOAK_VERSION < '23.0.0' }}
run: |
Expand Down Expand Up @@ -222,6 +234,10 @@ jobs:
key: ${{ runner.os }}-maven-keycloak-legacy-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-keycloak-legacy
- name: Adapt sources for Keycloak versions < 24.0.0
if: ${{ matrix.env.KEYCLOAK_VERSION < '24.0.0' }}
run: |
echo "COMPATIBILITY_PROFILE=-Ppre-keycloak24" >> $GITHUB_ENV
- name: Adapt sources for Keycloak versions < 23.0.0
if: ${{ matrix.env.KEYCLOAK_VERSION < '23.0.0' }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Fix versioning in artifact to contain the correct keycloak version [#1097](https://github.com/adorsys/keycloak-config-cli/issues/1097)

### Added

- Support for first broker login flows defined on realm level

### Fixed

- Allow executions of same provider with different configurations in Sub-Auth-Flows
Expand Down
80 changes: 80 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,39 @@ import org.keycloak.representations.userprofile.config.UPConfig;</token>
<destinationFile>${project.basedir}/src/test/java/de/adorsys/keycloak/config/test/util/SubGroupUtil.java</destinationFile>
</configuration>
</execution>
<execution>
<id>replace-used-authentication-flow-workaround-with-legacy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/factory/UsedAuthenticationFlowWorkaroundFactory.java.legacy</sourceFile>
<destinationFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/factory/UsedAuthenticationFlowWorkaroundFactory.java</destinationFile>
</configuration>
</execution>
<execution>
<id>replace-authentication-flow-import-service-with-legacy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/service/AuthenticationFlowsImportService.java.legacy</sourceFile>
<destinationFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/service/AuthenticationFlowsImportService.java</destinationFile>
</configuration>
</execution>
<execution>
<id>replace-authentication-flow-import-service-test-with-legacy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.basedir}/src/test/java/de/adorsys/keycloak/config/service/ImportAuthenticationFlowsIT.java.legacy</sourceFile>
<destinationFile>${project.basedir}/src/test/java/de/adorsys/keycloak/config/service/ImportAuthenticationFlowsIT.java</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -883,6 +916,53 @@ import org.keycloak.representations.userprofile.config.UPConfig;</token>
</plugins>
</build>
</profile>
<profile>
<id>pre-keycloak24</id>
<build>
<plugins>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>replace-used-authentication-flow-workaround-with-legacy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/factory/UsedAuthenticationFlowWorkaroundFactory.java.legacy</sourceFile>
<destinationFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/factory/UsedAuthenticationFlowWorkaroundFactory.java</destinationFile>
</configuration>
</execution>
<execution>
<id>replace-authentication-flow-import-service-with-legacy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/service/AuthenticationFlowsImportService.java.legacy</sourceFile>
<destinationFile>${project.basedir}/src/main/java/de/adorsys/keycloak/config/service/AuthenticationFlowsImportService.java</destinationFile>
</configuration>
</execution>
<execution>
<id>replace-authentication-flow-import-service-test-with-legacy</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.basedir}/src/test/java/de/adorsys/keycloak/config/service/ImportAuthenticationFlowsIT.java.legacy</sourceFile>
<destinationFile>${project.basedir}/src/test/java/de/adorsys/keycloak/config/service/ImportAuthenticationFlowsIT.java</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>coverage</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class UsedAuthenticationFlowWorkaround {
private String dockerAuthenticationFlow;
private String registrationFlow;
private String resetCredentialsFlow;
private String firstBrokerLoginFlow;

private UsedAuthenticationFlowWorkaround(RealmImport realmImport) {
this.realmImport = realmImport;
Expand Down Expand Up @@ -168,6 +169,13 @@ private void disableFirstBrokerLoginFlowsIfNeeded(String topLevelFlowAlias, Real
}
}
}
if (Objects.equals(existingRealm.getFirstBrokerLoginFlow(), topLevelFlowAlias)) {
logger.debug(
"Temporary disable first-broker-login-flow for in realm '{}' which is '{}'",
realmImport.getRealm(), topLevelFlowAlias
);
disableFirstBrokerLoginFlow(existingRealm);
}
}

private void disablePostBrokerLoginFlowsIfNeeded(String topLevelFlowAlias, RealmRepresentation existingRealm) {
Expand Down Expand Up @@ -241,6 +249,15 @@ private void disableResetCredentialsFlow(RealmRepresentation existingRealm) {
realmRepository.update(existingRealm);
}

private void disableFirstBrokerLoginFlow(RealmRepresentation existingRealm) {
String otherFlowAlias = searchTemporaryCreatedTopLevelFlowForReplacement();

firstBrokerLoginFlow = existingRealm.getFirstBrokerLoginFlow();

existingRealm.setFirstBrokerLoginFlow(otherFlowAlias);
realmRepository.update(existingRealm);
}

private void disableFirstBrokerLoginFlow(String realmName, IdentityProviderRepresentation identityProvider) {
String otherFlowAlias = searchTemporaryCreatedTopLevelFlowForReplacement();

Expand Down Expand Up @@ -323,7 +340,8 @@ private boolean hasToResetFlows() {
|| Strings.isNotBlank(registrationFlow)
|| Strings.isNotBlank(resetCredentialsFlow)
|| !resetFirstBrokerLoginFlow.isEmpty()
|| !resetPostBrokerLoginFlow.isEmpty();
|| !resetPostBrokerLoginFlow.isEmpty()
|| Strings.isNotBlank(firstBrokerLoginFlow);
}

private void resetFlows(RealmRepresentation existingRealm) {
Expand Down Expand Up @@ -416,6 +434,14 @@ private void resetFirstBrokerLoginFlowsIfNeeded(RealmRepresentation existingReal
identityProviderRepresentation.setFirstBrokerLoginFlowAlias(entry.getValue());
identityProviderRepository.update(existingRealm.getRealm(), identityProviderRepresentation);
}
if (Strings.isNotBlank(firstBrokerLoginFlow)) {
logger.debug(
"Reset first-broker-login-flow in realm '{}' to '{}'",
realmImport.getRealm(), firstBrokerLoginFlow
);

existingRealm.setFirstBrokerLoginFlow(firstBrokerLoginFlow);
}
}

private void resetPostBrokerLoginFlowsIfNeeded(RealmRepresentation existingRealm) {
Expand Down
Loading

0 comments on commit 87c2a51

Please sign in to comment.