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 Oct 21, 2024
1 parent 84bd406 commit 9c857ae
Show file tree
Hide file tree
Showing 11 changed files with 966 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .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 Down Expand Up @@ -185,6 +190,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 +232,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 @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### 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
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,42 @@ 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>
</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 9c857ae

Please sign in to comment.