forked from opensearch-project/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove support for v6 configuration (opensearch-project#4546)
Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
- Loading branch information
Showing
86 changed files
with
646 additions
and
6,586 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
93 changes: 93 additions & 0 deletions
93
src/main/java/org/opensearch/security/configuration/ConfigurationMap.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,93 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.configuration; | ||
|
||
import java.util.Set; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import org.opensearch.security.securityconf.impl.CType; | ||
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration; | ||
|
||
/** | ||
* Allows type safe access of configuration instances via the configuration type | ||
*/ | ||
public class ConfigurationMap { | ||
public static final ConfigurationMap EMPTY = new ConfigurationMap(ImmutableMap.of()); | ||
|
||
private final ImmutableMap<CType<?>, SecurityDynamicConfiguration<?>> map; | ||
|
||
private ConfigurationMap(ImmutableMap<CType<?>, SecurityDynamicConfiguration<?>> map) { | ||
this.map = map; | ||
} | ||
|
||
public <T> SecurityDynamicConfiguration<T> get(CType<T> ctype) { | ||
@SuppressWarnings("unchecked") | ||
SecurityDynamicConfiguration<T> config = (SecurityDynamicConfiguration<T>) map.get(ctype); | ||
|
||
if (config == null) { | ||
return null; | ||
} | ||
|
||
if (!config.getCType().equals(ctype)) { | ||
throw new RuntimeException("Stored configuration does not match type: " + ctype + "; " + config); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
public boolean containsKey(CType<?> ctype) { | ||
return map.containsKey(ctype); | ||
} | ||
|
||
public Set<CType<?>> keySet() { | ||
return map.keySet(); | ||
} | ||
|
||
public int size() { | ||
return this.map.size(); | ||
} | ||
|
||
public ImmutableMap<CType<?>, SecurityDynamicConfiguration<?>> rawMap() { | ||
return this.map; | ||
} | ||
|
||
public static ConfigurationMap of(SecurityDynamicConfiguration<?>... configs) { | ||
Builder builder = new Builder(); | ||
|
||
for (SecurityDynamicConfiguration<?> config : configs) { | ||
builder.with(config); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
public static class Builder { | ||
private ImmutableMap.Builder<CType<?>, SecurityDynamicConfiguration<?>> map = new ImmutableMap.Builder<>(); | ||
|
||
public Builder() {} | ||
|
||
public <T> Builder with(SecurityDynamicConfiguration<T> config) { | ||
map.put(config.getCType(), config); | ||
return this; | ||
} | ||
|
||
public Builder with(ConfigurationMap configurationMap) { | ||
map.putAll(configurationMap.map); | ||
return this; | ||
} | ||
|
||
public ConfigurationMap build() { | ||
return new ConfigurationMap(this.map.build()); | ||
} | ||
} | ||
} |
Oops, something went wrong.