diff --git a/examples/providers/domain-extension/README.md b/examples/providers/domain-extension/README.md deleted file mode 100644 index f50f5272a7..0000000000 --- a/examples/providers/domain-extension/README.md +++ /dev/null @@ -1,44 +0,0 @@ -Example Domain Extension -======================== - -To run, deploy as a module by running: - - $KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add --name=org.keycloak.examples.domain-extension-example --resources=target/domain-extension-example.jar --dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-services,org.keycloak.keycloak-model-jpa,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private,javax.ws.rs.api,javax.persistence.api,org.hibernate,org.javassist,org.liquibase" - - -Then registering the provider by editing `standalone/configuration/standalone.xml` and adding the module to the providers element: - - - ... - module:org.keycloak.examples.domain-extension-example - - -Then start (or restart) the server. - -Testing -------- -First you can create some example companies with these CURL requests. - -```` -curl -i --request POST http://localhost:8080/auth/realms/master/example/companies --data "{ \"name\": \"foo company\" }" --header "Content-type: application/json" -curl -i --request POST http://localhost:8080/auth/realms/master/example/companies --data "{ \"name\": \"bar company\" }" --header "Content-type: application/json" -```` - -Then you can look up all companies - -```` -curl -i --request GET http://localhost:8080/auth/realms/master/example/companies --header "Accept: application/json" -```` - -If you create realm `foo` in Keycloak admin console and then replace the realm name in the URI (for example like `http://localhost:8080/auth/realms/foo/example/companies` ) you will see -that companies are scoped per-realm. So you will see different companies for realm `master` and for realm `foo` . - - -Testing with authenticated access ---------------------------------- -Example contains the endpoint, which is accessible just for authenticated users. REST request must be authenticated with bearer access token -of authenticated user and the user must be in realm role `admin` in order to access the resource. You can run bash script from the current directory: -```` -./invoke-authenticated.sh -```` -The script assumes user `admin` with password `admin` exists in realm `master`. Also it assumes that you have `curl` installed. diff --git a/examples/providers/domain-extension/invoke-authenticated.sh b/examples/providers/domain-extension/invoke-authenticated.sh deleted file mode 100755 index 5e2f397d40..0000000000 --- a/examples/providers/domain-extension/invoke-authenticated.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -export DIRECT_GRANT_RESPONSE=$(curl -i --request POST http://localhost:8080/auth/realms/master/protocol/openid-connect/token --header "Accept: application/json" --header "Content-Type: application/x-www-form-urlencoded" --data "grant_type=password&username=admin&password=admin&client_id=admin-cli") - -echo -e "\n\nSENT RESOURCE-OWNER-PASSWORD-CREDENTIALS-REQUEST. OUTPUT IS:\n\n"; -echo $DIRECT_GRANT_RESPONSE; - -export ACCESS_TOKEN=$(echo $DIRECT_GRANT_RESPONSE | grep "access_token" | sed 's/.*\"access_token\":\"\([^\"]*\)\".*/\1/g'); -echo -e "\n\nACCESS TOKEN IS \"$ACCESS_TOKEN\""; - -echo -e "\n\nSENDING UN-AUTHENTICATED REQUEST. THIS SHOULD FAIL WITH 401: "; -curl -i --request POST http://localhost:8080/auth/realms/master/example/companies-auth --data "{ \"name\": \"auth foo company\" }" --header "Content-type: application/json" - -echo -e "\n\nSENDING AUTHENTICATED REQUEST. THIS SHOULD SUCCESSFULLY CREATE COMPANY AND SUCCESS WITH 201: "; -curl -i --request POST http://localhost:8080/auth/realms/master/example/companies-auth --data "{ \"name\": \"auth foo company\" }" --header "Content-type: application/json" --header "Authorization: Bearer $ACCESS_TOKEN"; - -echo -e "\n\nSEARCH COMPANIES: "; -curl -i --request GET http://localhost:8080/auth/realms/master/example/companies-auth --header "Accept: application/json" --header "Authorization: Bearer $ACCESS_TOKEN"; - diff --git a/examples/providers/domain-extension/pom.xml b/examples/providers/domain-extension/pom.xml deleted file mode 100755 index f8da91f341..0000000000 --- a/examples/providers/domain-extension/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - keycloak-examples-providers-parent - org.keycloak - 999.0.0-SNAPSHOT - - - Domain Extension Example - - 4.0.0 - - keycloak-examples-providers-domain-extension - jar - - - - org.keycloak - keycloak-core - provided - - - org.keycloak - keycloak-services - provided - - - org.keycloak - keycloak-server-spi - provided - - - org.keycloak - keycloak-server-spi-private - provided - - - org.keycloak - keycloak-model-jpa - provided - - - jakarta.ws.rs - jakarta.ws.rs-api - - - io.quarkus.resteasy.reactive - resteasy-reactive-common - provided - - - - - domain-extension-example - - diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/CompanyRepresentation.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/CompanyRepresentation.java deleted file mode 100644 index 2b76d576aa..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/CompanyRepresentation.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.keycloak.examples.domainextension; - -import org.keycloak.examples.domainextension.jpa.Company; - -public class CompanyRepresentation { - - private String id; - private String name; - - public CompanyRepresentation() { - } - - public CompanyRepresentation(Company company) { - id = company.getId(); - name = company.getName(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public void setId(String id) { - this.id = id; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/Company.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/Company.java deleted file mode 100644 index a8cb97a2f0..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/Company.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.examples.domainextension.jpa; - - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.NamedQueries; -import jakarta.persistence.NamedQuery; -import jakarta.persistence.Table; - -@Entity -@Table(name = "EXAMPLE_COMPANY") -@NamedQueries({ @NamedQuery(name = "findByRealm", query = "from Company where realmId = :realmId") }) -public class Company { - - @Id - @Column(name = "ID") - private String id; - - @Column(name = "NAME", nullable = false) - private String name; - - @Column(name = "REALM_ID", nullable = false) - private String realmId; - - public String getId() { - return id; - } - - public String getRealmId() { - return realmId; - } - - public String getName() { - return name; - } - - public void setId(String id) { - this.id = id; - } - - public void setName(String name) { - this.name = name; - } - - public void setRealmId(String realmId) { - this.realmId = realmId; - } -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/ExampleJpaEntityProvider.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/ExampleJpaEntityProvider.java deleted file mode 100644 index fe22b27a7d..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/ExampleJpaEntityProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.examples.domainextension.jpa; - -import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider; - -import java.util.Collections; -import java.util.List; - -/** - * @author Erik Mulder - * - * Example JpaEntityProvider. - */ -public class ExampleJpaEntityProvider implements JpaEntityProvider { - - @Override - public List> getEntities() { - return Collections.>singletonList(Company.class); - } - - @Override - public String getChangelogLocation() { - return "META-INF/example-changelog.xml"; - } - - @Override - public void close() { - } - - @Override - public String getFactoryId() { - return ExampleJpaEntityProviderFactory.ID; - } -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/ExampleJpaEntityProviderFactory.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/ExampleJpaEntityProviderFactory.java deleted file mode 100644 index 2c919f4c2e..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/jpa/ExampleJpaEntityProviderFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.examples.domainextension.jpa; - -import org.keycloak.Config.Scope; -import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider; -import org.keycloak.connections.jpa.entityprovider.JpaEntityProviderFactory; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; - -/** - * @author Erik Mulder - * - * Example JpaEntityProviderFactory. - */ -public class ExampleJpaEntityProviderFactory implements JpaEntityProviderFactory { - - protected static final String ID = "example-entity-provider"; - - @Override - public JpaEntityProvider create(KeycloakSession session) { - return new ExampleJpaEntityProvider(); - } - - @Override - public String getId() { - return ID; - } - - @Override - public void init(Scope config) { - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - } - - @Override - public void close() { - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/CompanyResource.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/CompanyResource.java deleted file mode 100644 index 1ef47bf750..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/CompanyResource.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.keycloak.examples.domainextension.rest; - -import org.jboss.resteasy.reactive.NoCache; -import org.keycloak.examples.domainextension.CompanyRepresentation; -import org.keycloak.examples.domainextension.spi.ExampleService; -import org.keycloak.models.KeycloakSession; - -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; -import java.util.List; - -public class CompanyResource { - - private final KeycloakSession session; - - public CompanyResource(KeycloakSession session) { - this.session = session; - } - - @GET - @Path("") - @NoCache - @Produces(MediaType.APPLICATION_JSON) - public List getCompanies() { - return session.getProvider(ExampleService.class).listCompanies(); - } - - @POST - @Path("") - @NoCache - @Consumes(MediaType.APPLICATION_JSON) - public Response createCompany(CompanyRepresentation rep) { - session.getProvider(ExampleService.class).addCompany(rep); - return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(rep.getId()).build()).build(); - } - - @GET - @NoCache - @Path("{id}") - @Produces(MediaType.APPLICATION_JSON) - public CompanyRepresentation getCompany(@PathParam("id") final String id) { - return session.getProvider(ExampleService.class).findCompany(id); - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRealmResourceProvider.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRealmResourceProvider.java deleted file mode 100644 index 0882d22044..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRealmResourceProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.examples.domainextension.rest; - -import org.keycloak.models.KeycloakSession; -import org.keycloak.services.resource.RealmResourceProvider; - -public class ExampleRealmResourceProvider implements RealmResourceProvider { - - private KeycloakSession session; - - public ExampleRealmResourceProvider(KeycloakSession session) { - this.session = session; - } - - @Override - public Object getResource() { - return new ExampleRestResource(session); - } - - @Override - public void close() { - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRealmResourceProviderFactory.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRealmResourceProviderFactory.java deleted file mode 100644 index 33c2ca2720..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRealmResourceProviderFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.examples.domainextension.rest; - -import org.keycloak.Config.Scope; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; -import org.keycloak.services.resource.RealmResourceProvider; -import org.keycloak.services.resource.RealmResourceProviderFactory; - -public class ExampleRealmResourceProviderFactory implements RealmResourceProviderFactory { - - public static final String ID = "example"; - - @Override - public String getId() { - return ID; - } - - @Override - public RealmResourceProvider create(KeycloakSession session) { - return new ExampleRealmResourceProvider(session); - } - - @Override - public void init(Scope config) { - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - } - - @Override - public void close() { - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRestResource.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRestResource.java deleted file mode 100644 index dc439a734e..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/rest/ExampleRestResource.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.keycloak.examples.domainextension.rest; - -import org.keycloak.models.KeycloakSession; -import org.keycloak.services.managers.AppAuthManager; -import org.keycloak.services.managers.AuthenticationManager; - -import jakarta.ws.rs.ForbiddenException; -import jakarta.ws.rs.NotAuthorizedException; -import jakarta.ws.rs.Path; - -public class ExampleRestResource { - - private final KeycloakSession session; - private final AuthenticationManager.AuthResult auth; - - public ExampleRestResource(KeycloakSession session) { - this.session = session; - this.auth = new AppAuthManager.BearerTokenAuthenticator(session).authenticate(); - } - - @Path("companies") - public CompanyResource getCompanyResource() { - return new CompanyResource(session); - } - - // Same like "companies" endpoint, but REST endpoint is authenticated with Bearer token and user must be in realm role "admin" - // Just for illustration purposes - @Path("companies-auth") - public CompanyResource getCompanyResourceAuthenticated() { - checkRealmAdmin(); - return new CompanyResource(session); - } - - private void checkRealmAdmin() { - if (auth == null) { - throw new NotAuthorizedException("Bearer"); - } else if (auth.getToken().getRealmAccess() == null || !auth.getToken().getRealmAccess().isUserInRole("admin")) { - throw new ForbiddenException("Does not have realm admin role"); - } - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleService.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleService.java deleted file mode 100644 index 78ecc15154..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.examples.domainextension.spi; - -import org.keycloak.examples.domainextension.CompanyRepresentation; -import org.keycloak.provider.Provider; - -import java.util.List; - -public interface ExampleService extends Provider { - - List listCompanies(); - - CompanyRepresentation findCompany(String id); - - CompanyRepresentation addCompany(CompanyRepresentation company); - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleServiceProviderFactory.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleServiceProviderFactory.java deleted file mode 100644 index 2c6a122a73..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleServiceProviderFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.examples.domainextension.spi; - -import org.keycloak.provider.ProviderFactory; - -public interface ExampleServiceProviderFactory extends ProviderFactory { - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleSpi.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleSpi.java deleted file mode 100644 index 811ec92fb6..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/ExampleSpi.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.examples.domainextension.spi; - -import org.keycloak.provider.Provider; -import org.keycloak.provider.ProviderFactory; -import org.keycloak.provider.Spi; - -public class ExampleSpi implements Spi { - - @Override - public boolean isInternal() { - return false; - } - - @Override - public String getName() { - return "example"; - } - - @Override - public Class getProviderClass() { - return ExampleService.class; - } - - @Override - @SuppressWarnings("rawtypes") - public Class getProviderFactoryClass() { - return ExampleServiceProviderFactory.class; - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/impl/ExampleServiceImpl.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/impl/ExampleServiceImpl.java deleted file mode 100644 index 55cd876379..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/impl/ExampleServiceImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.examples.domainextension.spi.impl; - -import org.keycloak.connections.jpa.JpaConnectionProvider; -import org.keycloak.examples.domainextension.CompanyRepresentation; -import org.keycloak.examples.domainextension.jpa.Company; -import org.keycloak.examples.domainextension.spi.ExampleService; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.RealmModel; -import org.keycloak.models.utils.KeycloakModelUtils; - -import jakarta.persistence.EntityManager; -import java.util.LinkedList; -import java.util.List; - -public class ExampleServiceImpl implements ExampleService { - - private final KeycloakSession session; - - public ExampleServiceImpl(KeycloakSession session) { - this.session = session; - if (getRealm() == null) { - throw new IllegalStateException("The service cannot accept a session without a realm in its context."); - } - } - - private EntityManager getEntityManager() { - return session.getProvider(JpaConnectionProvider.class).getEntityManager(); - } - - protected RealmModel getRealm() { - return session.getContext().getRealm(); - } - - @Override - public List listCompanies() { - List companyEntities = getEntityManager().createNamedQuery("findByRealm", Company.class) - .setParameter("realmId", getRealm().getId()) - .getResultList(); - - List result = new LinkedList<>(); - for (Company entity : companyEntities) { - result.add(new CompanyRepresentation(entity)); - } - return result; - } - - @Override - public CompanyRepresentation findCompany(String id) { - Company entity = getEntityManager().find(Company.class, id); - return entity==null ? null : new CompanyRepresentation(entity); - } - - @Override - public CompanyRepresentation addCompany(CompanyRepresentation company) { - Company entity = new Company(); - String id = company.getId()==null ? KeycloakModelUtils.generateId() : company.getId(); - entity.setId(id); - entity.setName(company.getName()); - entity.setRealmId(getRealm().getId()); - getEntityManager().persist(entity); - - company.setId(id); - return company; - } - - public void close() { - // Nothing to do. - } - -} diff --git a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/impl/ExampleServiceProviderFactoryImpl.java b/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/impl/ExampleServiceProviderFactoryImpl.java deleted file mode 100644 index e4e2ddf092..0000000000 --- a/examples/providers/domain-extension/src/main/java/org/keycloak/examples/domainextension/spi/impl/ExampleServiceProviderFactoryImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.examples.domainextension.spi.impl; - -import org.keycloak.Config.Scope; -import org.keycloak.examples.domainextension.spi.ExampleService; -import org.keycloak.examples.domainextension.spi.ExampleServiceProviderFactory; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; - -public class ExampleServiceProviderFactoryImpl implements ExampleServiceProviderFactory { - - @Override - public ExampleService create(KeycloakSession session) { - return new ExampleServiceImpl(session); - } - - @Override - public void init(Scope config) { - - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - - } - - @Override - public void close() { - - } - - @Override - public String getId() { - return "exampleServiceImpl"; - } - -} diff --git a/examples/providers/domain-extension/src/main/resources/META-INF/example-changelog.xml b/examples/providers/domain-extension/src/main/resources/META-INF/example-changelog.xml deleted file mode 100644 index 5edd7191ee..0000000000 --- a/examples/providers/domain-extension/src/main/resources/META-INF/example-changelog.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.connections.jpa.entityprovider.JpaEntityProviderFactory b/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.connections.jpa.entityprovider.JpaEntityProviderFactory deleted file mode 100644 index c7b88db9a7..0000000000 --- a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.connections.jpa.entityprovider.JpaEntityProviderFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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. -# - -org.keycloak.examples.domainextension.jpa.ExampleJpaEntityProviderFactory diff --git a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.examples.domainextension.spi.ExampleServiceProviderFactory b/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.examples.domainextension.spi.ExampleServiceProviderFactory deleted file mode 100644 index 57f9f89dd5..0000000000 --- a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.examples.domainextension.spi.ExampleServiceProviderFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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. -# - -org.keycloak.examples.domainextension.spi.impl.ExampleServiceProviderFactoryImpl diff --git a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.provider.Spi b/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.provider.Spi deleted file mode 100644 index e013bbdce5..0000000000 --- a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.provider.Spi +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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. -# - -org.keycloak.examples.domainextension.spi.ExampleSpi diff --git a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory b/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory deleted file mode 100644 index ea81617385..0000000000 --- a/examples/providers/domain-extension/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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. -# - -org.keycloak.examples.domainextension.rest.ExampleRealmResourceProviderFactory \ No newline at end of file diff --git a/examples/providers/pom.xml b/examples/providers/pom.xml index d5c1191f25..198116d57c 100755 --- a/examples/providers/pom.xml +++ b/examples/providers/pom.xml @@ -32,7 +32,6 @@ rest - domain-extension authenticator