|
| 1 | +/** |
| 2 | +* Copyright (C) 2025 Red Hat, Inc. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +*/ |
| 16 | +package org.jboss.intersmash.tests.wildfly.elytron.oidc.client.keycloak; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | +import org.jboss.intersmash.application.openshift.OpenShiftApplication; |
| 20 | +import org.jboss.intersmash.application.operator.KeycloakOperatorApplication; |
| 21 | +import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.Clients; |
| 22 | +import org.keycloak.k8s.v2alpha1.keycloakrealmimportspec.realm.ClientsBuilder; |
| 23 | + |
| 24 | +/** |
| 25 | + * Deploys one basic Keycloak instance with a realm with users and a client. |
| 26 | + * This can be re-used and extended with other realms and/or clients for different applications. |
| 27 | + */ |
| 28 | +public class BasicKeycloakOperatorOidcHttpsApplication |
| 29 | + extends BasicKeycloakOperatorDynamicClientOidcApplication |
| 30 | + implements KeycloakOperatorApplication, OpenShiftApplication { |
| 31 | + |
| 32 | + /** The OIDC client identifier used for authentication with Keycloak. */ |
| 33 | + public static final String SSO_OIDC_CLIENT_ID = "elytron-oidc-client-id"; |
| 34 | + |
| 35 | + /** The OIDC client secret used for authentication with Keycloak. */ |
| 36 | + public static final String SSO_OIDC_CLIENT_SECRET = "3up7r37cr7doidccli7ntpa33word"; |
| 37 | + |
| 38 | + /** |
| 39 | + * Creates a new Keycloak instance which is pre-configured with an OIDC Client; that is for cases when we DON'T use |
| 40 | + * dynamic client registration. |
| 41 | + * |
| 42 | + * @throws IOException if an I/O error occurs during certificate generation |
| 43 | + */ |
| 44 | + public BasicKeycloakOperatorOidcHttpsApplication() throws IOException { |
| 45 | + super(); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Return the list of pre-configured OIDC Clients |
| 50 | + * @return the list of pre-configured OIDC Clients |
| 51 | + */ |
| 52 | + @Override |
| 53 | + protected Clients getClients() { |
| 54 | + String route = WildflyBootableJarWithElytronOidcClientApplication.getRoute(); |
| 55 | + return new ClientsBuilder() |
| 56 | + .withClientId(SSO_OIDC_CLIENT_ID) |
| 57 | + .withPublicClient(true) |
| 58 | + .withStandardFlowEnabled(true) |
| 59 | + .withEnabled(true) |
| 60 | + .withRootUrl( |
| 61 | + String.format("https://%s/", route)) |
| 62 | + .withRedirectUris( |
| 63 | + String.format("https://%s/*", route)) |
| 64 | + .withAdminUrl( |
| 65 | + String.format("https://%s/", route)) |
| 66 | + .withWebOrigins( |
| 67 | + String.format("https://%s/", route)) |
| 68 | + .withSecret(SSO_OIDC_CLIENT_SECRET) |
| 69 | + .withFullScopeAllowed(true) |
| 70 | + .build(); |
| 71 | + } |
| 72 | +} |
0 commit comments