CRD generation from RealmRepresentation (#9759)

Enabling CRD generation from RealmRepresentation

Closes #9759
This commit is contained in:
Andrea Peruffo 2022-01-27 09:56:46 +00:00 committed by GitHub
parent 0f082dde5b
commit 24d6f75d11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 487 additions and 15 deletions

View file

@ -67,6 +67,9 @@ public class AbstractAuthenticationExecutionRepresentation implements Serializab
* *
* @return * @return
*/ */
@Deprecated
private boolean autheticatorFlow;
@Deprecated @Deprecated
public boolean isAutheticatorFlow() { public boolean isAutheticatorFlow() {
return authenticatorFlow; return authenticatorFlow;

56
operator/patch-sources.sh Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env bash
sedCommand="sed"
if [ "$(uname)" == "Darwin" ]; then
if hash gsed 2>/dev/null; then
sedCommand="gsed"
fi
fi
function addAnnotation() {
local match=$1
local annotation=$2
local file=$3
$sedCommand -i "/^.*${match}.*/i ${annotation}" ${file}
}
addAnnotation \
"protected List<GroupRepresentation> subGroups;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.NoSubGroupsGroupRepresentationList.class)" \
target/keycloak-core/org/keycloak/representations/idm/GroupRepresentation.java
addAnnotation \
"private MultivaluedHashMap<String, ComponentExportRepresentation> components;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.ComponentExportRepresentationMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/RealmRepresentation.java
addAnnotation \
"private MultivaluedHashMap<String, String> config;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/CredentialRepresentation.java
addAnnotation \
"private MultivaluedHashMap<String, String> config;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/ComponentRepresentation.java
addAnnotation \
"private MultivaluedHashMap<String, ComponentExportRepresentation> subComponents = new MultivaluedHashMap<>();" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.NoSubcomponentsComponentExportRepresentationMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/ComponentExportRepresentation.java
addAnnotation \
"private MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/ComponentExportRepresentation.java
addAnnotation \
"private List<PolicyRepresentation> policies;" \
"@com.fasterxml.jackson.annotation.JsonIgnore" \
target/keycloak-core/org/keycloak/representations/idm/authorization/ScopeRepresentation.java
addAnnotation \
"private List<ResourceRepresentation> resources;" \
"@com.fasterxml.jackson.annotation.JsonIgnore" \
target/keycloak-core/org/keycloak/representations/idm/authorization/ScopeRepresentation.java

View file

@ -22,6 +22,8 @@
--> -->
<resteasy.version>4.7.4.Final</resteasy.version> <resteasy.version>4.7.4.Final</resteasy.version>
<wildfly.common.version>1.5.4.Final-format-001</wildfly.common.version> <wildfly.common.version>1.5.4.Final-format-001</wildfly.common.version>
<jackson.version>2.13.1</jackson.version>
<kubernetes-client.version>5.12.0</kubernetes-client.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version> <compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters> <maven.compiler.parameters>true</maven.compiler.parameters>
@ -58,6 +60,18 @@
<dependencies> <dependencies>
<!-- Fabric8 -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-api</artifactId>
<version>${kubernetes-client.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-apt</artifactId>
<version>${kubernetes-client.version}</version>
</dependency>
<!-- Quarkus --> <!-- Quarkus -->
<dependency> <dependency>
<groupId>io.quarkiverse.operatorsdk</groupId> <groupId>io.quarkiverse.operatorsdk</groupId>
@ -103,7 +117,7 @@
<!-- Keycloak --> <!-- Keycloak -->
<dependency> <dependency>
<groupId>org.keycloak</groupId> <groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId> <artifactId>keycloak-common</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
@ -153,8 +167,62 @@
</resources> </resources>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>import-keycloak-core</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/keycloak-core</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../core/src/main/java</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/keycloak-core</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.6.0</version>
<executions>
<execution>
<id>patch-core-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/patch-sources.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View file

@ -0,0 +1,31 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.operator.v2alpha1.crds;
import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Plural;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;
import org.keycloak.operator.Constants;
@Group(Constants.CRDS_GROUP)
@Version(Constants.CRDS_VERSION)
public class Realm extends CustomResource<RealmSpec, Void> implements Namespaced {
}

View file

@ -0,0 +1,46 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.operator.v2alpha1.crds;
import org.keycloak.representations.idm.RealmRepresentation;
import javax.validation.constraints.NotNull;
public class RealmSpec {
@NotNull
private String keycloakCRName;
@NotNull
private RealmRepresentation realm;
public String getKeycloakCRName() {
return keycloakCRName;
}
public void setKeycloakCRName(String keycloakCRName) {
this.keycloakCRName = keycloakCRName;
}
public RealmRepresentation getRealm() {
return realm;
}
public void setRealm(RealmRepresentation realm) {
this.realm = realm;
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.representations.overrides;
import java.util.HashMap;
import java.util.List;
import org.keycloak.representations.idm.ComponentExportRepresentation;
public class ComponentExportRepresentationMap extends HashMap<String, List<ComponentExportRepresentation>> {
}

View file

@ -0,0 +1,24 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.representations.overrides;
import java.util.HashMap;
import java.util.List;
public class MultivaluedStringStringHashMap extends HashMap<String, List<String>> {
}

View file

@ -0,0 +1,98 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.representations.overrides;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NoSubGroupsGroupRepresentation {
protected String id;
protected String name;
protected String path;
protected Map<String, List<String>> attributes;
protected List<String> realmRoles;
protected Map<String, List<String>> clientRoles;
// TODO: eventually generate code for Nth levels of depth
// protected List<GroupRepresentation> subGroups;
private Map<String, Boolean> access;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public List<String> getRealmRoles() {
return realmRoles;
}
public void setRealmRoles(List<String> realmRoles) {
this.realmRoles = realmRoles;
}
public Map<String, List<String>> getClientRoles() {
return clientRoles;
}
public void setClientRoles(Map<String, List<String>> clientRoles) {
this.clientRoles = clientRoles;
}
public Map<String, List<String>> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, List<String>> attributes) {
this.attributes = attributes;
}
public NoSubGroupsGroupRepresentation singleAttribute(String name, String value) {
if (this.attributes == null) attributes = new HashMap<>();
attributes.put(name, Arrays.asList(value));
return this;
}
public Map<String, Boolean> getAccess() {
return access;
}
public void setAccess(Map<String, Boolean> access) {
this.access = access;
}
}

View file

@ -0,0 +1,23 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.representations.overrides;
import java.util.ArrayList;
public class NoSubGroupsGroupRepresentationList extends ArrayList<NoSubGroupsGroupRepresentation> {
}

View file

@ -0,0 +1,74 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.representations.overrides;
import org.keycloak.common.util.MultivaluedHashMap;
import io.fabric8.crd.generator.annotation.SchemaFrom;
public class NoSubcomponentsComponentExportRepresentation {
private String id;
private String name;
private String providerId;
private String subType;
// TODO: eventually generate code for Nth levels of depth
// private MultivaluedHashMap<String, ComponentExportRepresentation> subComponents = new MultivaluedHashMap<>();
@SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)
private MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProviderId() {
return providerId;
}
public void setProviderId(String providerId) {
this.providerId = providerId;
}
public String getSubType() {
return subType;
}
public void setSubType(String subType) {
this.subType = subType;
}
public MultivaluedHashMap<String, String> getConfig() {
return config;
}
public void setConfig(MultivaluedHashMap<String, String> config) {
this.config = config;
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.representations.overrides;
import java.util.HashMap;
import java.util.List;
public class NoSubcomponentsComponentExportRepresentationMap extends HashMap<String, List<NoSubcomponentsComponentExportRepresentation>> {
}