-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Schwilk <david.schwilk@bosch.io>
- Loading branch information
1 parent
1c1eae9
commit f51b321
Showing
29 changed files
with
229 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ment/src/main/java/org/eclipse/ditto/policies/enforcement/DefaultPreEnforcerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.policies.enforcement; | ||
|
||
import org.eclipse.ditto.base.model.headers.DittoHeadersSettable; | ||
import org.eclipse.ditto.internal.utils.namespaces.BlockNamespaceBehavior; | ||
import org.eclipse.ditto.internal.utils.namespaces.BlockedNamespaces; | ||
import org.eclipse.ditto.policies.enforcement.placeholders.PlaceholderSubstitution; | ||
import org.eclipse.ditto.policies.enforcement.validators.CommandWithOptionalEntityValidator; | ||
|
||
import akka.actor.ActorSystem; | ||
|
||
public class DefaultPreEnforcerProvider implements PreEnforcerProvider{ | ||
|
||
private final ActorSystem actorSystem; | ||
|
||
public DefaultPreEnforcerProvider(final ActorSystem actorSystem) { | ||
this.actorSystem = actorSystem; | ||
} | ||
|
||
@Override | ||
public <T extends DittoHeadersSettable<?>> PreEnforcer<T> getPreEnforcer() { | ||
return dittoHeadersSettable -> | ||
BlockNamespaceBehavior.of(BlockedNamespaces.of(actorSystem)) | ||
.block(dittoHeadersSettable) | ||
.thenApply(CommandWithOptionalEntityValidator.createInstance()) | ||
.thenApply(PreEnforcer::setOriginatorHeader) | ||
.thenCompose(PlaceholderSubstitution.newInstance()); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...enforcement/src/main/java/org/eclipse/ditto/policies/enforcement/PreEnforcerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.policies.enforcement; | ||
|
||
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.ditto.base.model.headers.DittoHeadersSettable; | ||
import org.eclipse.ditto.base.service.DittoExtensionPoint; | ||
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader; | ||
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig; | ||
|
||
import akka.actor.ActorSystem; | ||
|
||
/** | ||
* Extension to provide the pre-enforcer for a service. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public interface PreEnforcerProvider extends DittoExtensionPoint { | ||
|
||
static final String CONFIG_PATH = "pre-enforcer-provider"; | ||
|
||
/** | ||
* Gets the pre-enforcer. | ||
*/ | ||
<T extends DittoHeadersSettable<?>> PreEnforcer<T> getPreEnforcer(); | ||
|
||
/** | ||
* Loads the implementation of {@code PreEnforcerProvider} which is configured for the | ||
* {@code ActorSystem}. | ||
* | ||
* @param actorSystem the actorSystem in which the {@code PreEnforcerProvider} should be loaded. | ||
* @return the {@code PreEnforcerProvider} implementation. | ||
* @throws NullPointerException if {@code actorSystem} is {@code null}. | ||
*/ | ||
static PreEnforcerProvider get(final ActorSystem actorSystem) { | ||
checkNotNull(actorSystem, "actorSystem"); | ||
final DefaultScopedConfig dittoScoped = DefaultScopedConfig.dittoScoped(actorSystem.settings().config()); | ||
final var implementation = dittoScoped.getString(CONFIG_PATH); | ||
|
||
return AkkaClassLoader.instantiate(actorSystem, PreEnforcerProvider.class, | ||
implementation, | ||
List.of(ActorSystem.class), | ||
List.of(actorSystem)); | ||
} | ||
} |
Oops, something went wrong.