diff --git a/dependencies/server-all/pom.xml b/dependencies/server-all/pom.xml index 21ae45fe7d..f98cbc8a83 100755 --- a/dependencies/server-all/pom.xml +++ b/dependencies/server-all/pom.xml @@ -72,6 +72,10 @@ org.keycloak keycloak-model-map-hot-rod + + org.keycloak + keycloak-model-map-file + org.twitter4j diff --git a/model/map-file/pom.xml b/model/map-file/pom.xml new file mode 100644 index 0000000000..a4e0ed1f7e --- /dev/null +++ b/model/map-file/pom.xml @@ -0,0 +1,42 @@ + + + + + + keycloak-model-pom + org.keycloak + 999-SNAPSHOT + + 4.0.0 + + keycloak-model-map-file + Keycloak Model Map File + + + org.keycloak + keycloak-model-map + + + junit + junit + test + + + \ No newline at end of file diff --git a/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileKeycloakTransaction.java b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileKeycloakTransaction.java new file mode 100644 index 0000000000..249411aead --- /dev/null +++ b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileKeycloakTransaction.java @@ -0,0 +1,95 @@ +/* + * Copyright 2022 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.models.map.storage.file; + +import java.util.stream.Stream; + +import org.keycloak.models.map.common.AbstractEntity; +import org.keycloak.models.map.storage.MapKeycloakTransaction; +import org.keycloak.models.map.storage.QueryParameters; + +/** + * {@link MapKeycloakTransaction} implementation used with the file map storage. + * + * @author Stefan Guilhen + */ +public class FileKeycloakTransaction implements MapKeycloakTransaction { + + private boolean active; + private boolean rollback; + + @Override + public V create(V value) { + return null; + } + + @Override + public V read(String key) { + return null; + } + + @Override + public Stream read(QueryParameters queryParameters) { + return null; + } + + @Override + public long getCount(QueryParameters queryParameters) { + return 0; + } + + @Override + public boolean delete(String key) { + return false; + } + + @Override + public long delete(QueryParameters queryParameters) { + return 0; + } + + @Override + public void begin() { + active = true; + } + + @Override + public void commit() { + if (rollback) { + throw new RuntimeException("Rollback only!"); + } + } + + @Override + public void rollback() { + } + + @Override + public void setRollbackOnly() { + rollback = true; + } + + @Override + public boolean getRollbackOnly() { + return rollback; + } + + @Override + public boolean isActive() { + return active; + } +} diff --git a/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorage.java b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorage.java new file mode 100644 index 0000000000..f51727a9b9 --- /dev/null +++ b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorage.java @@ -0,0 +1,35 @@ +/* + * Copyright 2022 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.models.map.storage.file; + +import org.keycloak.models.KeycloakSession; +import org.keycloak.models.map.common.AbstractEntity; +import org.keycloak.models.map.storage.MapKeycloakTransaction; +import org.keycloak.models.map.storage.MapStorage; + +/** + * A file-based {@link MapStorage}. + * + * @author Stefan Guilhen + */ +public class FileMapStorage implements MapStorage { + + @Override + public MapKeycloakTransaction createTransaction(KeycloakSession session) { + return new FileKeycloakTransaction(); + } +} diff --git a/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorageProvider.java b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorageProvider.java new file mode 100644 index 0000000000..68058ddb03 --- /dev/null +++ b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorageProvider.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 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.models.map.storage.file; + +import org.keycloak.models.map.common.AbstractEntity; +import org.keycloak.models.map.storage.MapStorage; +import org.keycloak.models.map.storage.MapStorageProvider; +import org.keycloak.models.map.storage.MapStorageProviderFactory; + +/** + * File-based {@link MapStorageProvider} implementation. + * + * @author Stefan Guilhen + */ +public class FileMapStorageProvider implements MapStorageProvider { + + public FileMapStorageProvider() { + } + + @Override + public MapStorage getStorage(Class modelType, MapStorageProviderFactory.Flag... flags) { + return null; + } + + @Override + public void close() { + } +} diff --git a/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorageProviderFactory.java b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorageProviderFactory.java new file mode 100644 index 0000000000..d4f563cdfe --- /dev/null +++ b/model/map-file/src/main/java/org/keycloak/models/map/storage/file/FileMapStorageProviderFactory.java @@ -0,0 +1,68 @@ +/* + * Copyright 2022 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.models.map.storage.file; + +import org.keycloak.Config; +import org.keycloak.common.Profile; +import org.keycloak.component.AmphibianProviderFactory; +import org.keycloak.models.KeycloakSession; +import org.keycloak.models.KeycloakSessionFactory; +import org.keycloak.models.map.storage.MapStorageProvider; +import org.keycloak.models.map.storage.MapStorageProviderFactory; +import org.keycloak.provider.EnvironmentDependentProviderFactory; + +/** + * A {@link MapStorageProviderFactory} that creates file-based {@link MapStorageProvider}s. + * + * @author Stefan Guilhen + */ +public class FileMapStorageProviderFactory implements AmphibianProviderFactory, + MapStorageProviderFactory, + EnvironmentDependentProviderFactory { + + public static final String PROVIDER_ID = "file"; + private Config.Scope config; + + @Override + public MapStorageProvider create(KeycloakSession session) { + return new FileMapStorageProvider(); + } + + @Override + public String getHelpText() { + return "File Map Storage"; + } + + @Override + public boolean isSupported() { + return Profile.isFeatureEnabled(Profile.Feature.MAP_STORAGE); + } + + @Override + public void init(Config.Scope config) { + this.config = config; + } + + @Override + public void postInit(KeycloakSessionFactory factory) { + } + + @Override + public String getId() { + return PROVIDER_ID; + } +} diff --git a/model/map-file/src/main/resources/META-INF/services/org.keycloak.models.map.storage.MapStorageProviderFactory b/model/map-file/src/main/resources/META-INF/services/org.keycloak.models.map.storage.MapStorageProviderFactory new file mode 100644 index 0000000000..b7f981f257 --- /dev/null +++ b/model/map-file/src/main/resources/META-INF/services/org.keycloak.models.map.storage.MapStorageProviderFactory @@ -0,0 +1,18 @@ +# +# Copyright 2022 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.models.map.storage.file.FileMapStorageProviderFactory diff --git a/model/pom.xml b/model/pom.xml index 5857196926..03a20be041 100755 --- a/model/pom.xml +++ b/model/pom.xml @@ -41,5 +41,6 @@ build-processor map-hot-rod map-ldap + map-file diff --git a/pom.xml b/pom.xml index b72c9fbf66..a64fc62cee 100644 --- a/pom.xml +++ b/pom.xml @@ -1318,6 +1318,11 @@ keycloak-model-map-hot-rod ${project.version} + + org.keycloak + keycloak-model-map-file + ${project.version} + org.keycloak launcher diff --git a/quarkus/runtime/pom.xml b/quarkus/runtime/pom.xml index e65b09e112..e2463488b9 100644 --- a/quarkus/runtime/pom.xml +++ b/quarkus/runtime/pom.xml @@ -340,6 +340,16 @@ + + org.keycloak + keycloak-model-map-file + + + * + * + + +