Skip to content

Commit

Permalink
[squash] updated schema to make it more consistent with other clients…
Browse files Browse the repository at this point in the history
… and updated class names
  • Loading branch information
PrarthonaPaul committed Feb 7, 2024
1 parent 22c7d6b commit ebcedca
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@

/**
* A lazily-initialized holder for the default encrypted expression context.
* If an error occurs setting up the default identity
* If an error occurs setting up the default encryption client
* context, the empty context is used.
*
* @author <a href="mailto:prpaul@redhat.com">Prarthona Paul</a>
*/
class DefaultEncryptedExpressionContextProvider {
class DefaultEncryptionClientContextProvider {

static final EncryptedExpressionContext DEFAULT;
static final EncryptionClientContext DEFAULT;

static {
DEFAULT = doPrivileged((PrivilegedAction<EncryptedExpressionContext>) () -> {
DEFAULT = doPrivileged((PrivilegedAction<EncryptionClientContext>) () -> {
try {
return EncryptedExpressionsXmlParser.parseEncryptedExpressionClientConfiguration().create();
return EncryptionClientXmlParser.parseEncryptionClientConfiguration().create();
} catch (Throwable t) {
throw new InvalidEncryptedExpressionConfigurationException(t);
throw new InvalidEncryptionClientConfigurationException(t);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class EncryptedExpressionResolver {
public EncryptedExpressionResolver() {
}

public String resolveExpression(String expression, EncryptedExpressionConfiguration config) {
public String resolveExpression(String expression, EncryptionClientConfiguration config) {
checkNotNullParam("expression", expression);
checkNotNullParam("encrypted expression configuration", config);
return resolveExpressionInternal(expression, config);
Expand All @@ -59,7 +59,7 @@ public Map<String, ResolverConfiguration> getResolverConfiguration() {
return resolverConfigurations;
}

private String resolveExpressionInternal(String fullExpression, EncryptedExpressionConfiguration config) {
private String resolveExpressionInternal(String fullExpression, EncryptionClientConfiguration config) {
assert config != null;

if (fullExpression.length() > 3) {
Expand Down Expand Up @@ -101,11 +101,11 @@ private String resolveExpressionInternal(String fullExpression, EncryptedExpress
return null;
}

public String createExpression(final String clearText, EncryptedExpressionConfiguration config) {
public String createExpression(final String clearText, EncryptionClientConfiguration config) {
return createExpression(null, clearText, config);
}

public String createExpression(final String resolver, final String clearText, EncryptedExpressionConfiguration config) {
public String createExpression(final String resolver, final String clearText, EncryptionClientConfiguration config) {
String resolvedResolver = resolver != null ? resolver : defaultResolver;
if (resolvedResolver == null) {
throw xmlLog.noResolverSpecifiedAndNoDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.wildfly.security.credential.store.CredentialStore;
import org.wildfly.security.provider.util.ProviderFactory;

import javax.security.auth.callback.CallbackHandler;
import java.security.Provider;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -36,39 +35,31 @@
* @author <a href="mailto:prpaul@redhat.com">Prarthona Paul</a>
*/

public final class EncryptedExpressionConfiguration {
public final class EncryptionClientConfiguration {

private static final int SET_CREDENTIAL_STORE = 0;
private static final int ADD_CREDENTIAL_STORE = 1;
private static final int REMOVE_CREDENTIAL_STORE = 3;
private static final int SET_RESOLVER = 4;
private static final int SET_DEFAULT_RESOLVER = 5;
private static final int SET_USER_CALLBACK_HANDLER = 6;
private static final Supplier<Provider[]> DEFAULT_PROVIDER_SUPPLIER = ProviderFactory.getDefaultProviderSupplier(EncryptedExpressionConfiguration.class.getClassLoader());
private static final Supplier<Provider[]> DEFAULT_PROVIDER_SUPPLIER = ProviderFactory.getDefaultProviderSupplier(EncryptionClientConfiguration.class.getClassLoader());

public EncryptedExpressionConfiguration(CallbackHandler userCallbackHandler) {
this.userCallbackHandler = userCallbackHandler;
}

public static EncryptedExpressionConfiguration empty() {
return new EncryptedExpressionConfiguration();
public static EncryptionClientConfiguration empty() {
return new EncryptionClientConfiguration();
}
Map<String, CredentialStore> credentialStoreMap;
Map<String, EncryptedExpressionResolver.ResolverConfiguration> resolverMap;
String defaultResolverName;
EncryptedExpressionResolver encryptedExpressionResolver;
CallbackHandler userCallbackHandler;

EncryptedExpressionConfiguration() {
EncryptionClientConfiguration() {
this.credentialStoreMap = new HashMap<>();
this.resolverMap = new HashMap<>();
this.defaultResolverName = null;
this.encryptedExpressionResolver = null;
this.userCallbackHandler = null;
}

private EncryptedExpressionConfiguration(final EncryptedExpressionConfiguration original, final int what, final Object value) {

private EncryptionClientConfiguration(final EncryptionClientConfiguration original, final int what, final Object value) {
if (what == SET_CREDENTIAL_STORE) {
if (value == null || ((Map<String, CredentialStore>) value).isEmpty()) {return;}
setCredentialStoreMap((Map<String, CredentialStore>) value);
Expand All @@ -86,30 +77,24 @@ private EncryptedExpressionConfiguration(final EncryptedExpressionConfiguration
} else {
this.credentialStoreMap = original.credentialStoreMap;
}
if (what == SET_RESOLVER) {
if (value == null || ((EncryptedExpressionResolver) value).getResolverConfiguration().isEmpty()) {return;}
setResolverMap(((EncryptedExpressionResolver) value).getResolverConfiguration());
this.encryptedExpressionResolver = ((EncryptedExpressionResolver) value);
} else {
this.resolverMap = original.resolverMap;
}
if (what == SET_DEFAULT_RESOLVER) {
this.defaultResolverName = (String) value;
} else {
this.defaultResolverName = original.defaultResolverName;
}
if (what == SET_USER_CALLBACK_HANDLER) {
this.userCallbackHandler = (CallbackHandler) value;
} else {
this.userCallbackHandler = original.userCallbackHandler;
}
}

private EncryptedExpressionConfiguration(final EncryptedExpressionConfiguration original, final EncryptedExpressionConfiguration other) {
if (what == SET_RESOLVER) {
if (value == null || ((EncryptedExpressionResolver) value).getResolverConfiguration().isEmpty()) {return;}
setResolverMap(((EncryptedExpressionResolver) value).getResolverConfiguration());
this.encryptedExpressionResolver = ((EncryptedExpressionResolver) value);
} else {
this.resolverMap = original.resolverMap;
}
if (what == SET_DEFAULT_RESOLVER) {
this.defaultResolverName = (String) value;
} else {
this.defaultResolverName = original.defaultResolverName;
}
}

private EncryptionClientConfiguration(final EncryptionClientConfiguration original, final EncryptionClientConfiguration other) {
this.credentialStoreMap = other.credentialStoreMap;
this.resolverMap = other.resolverMap;
this.defaultResolverName = other.defaultResolverName;
this.userCallbackHandler = other.userCallbackHandler;
}

private static <T> T getOrDefault(T value, T defVal) {
Expand All @@ -124,12 +109,12 @@ Map<String, CredentialStore> getCredentialStoreMap() {
return credentialStoreMap;
}

public EncryptedExpressionConfiguration useCredential(Credential credential) {
public EncryptionClientConfiguration useCredential(Credential credential) {
if (credential == null) return this;
if (getCredentialStoreMap().isEmpty()) {
return new EncryptedExpressionConfiguration(this, SET_CREDENTIAL_STORE, IdentityCredentials.NONE.withCredential(credential));
return new EncryptionClientConfiguration(this, SET_CREDENTIAL_STORE, IdentityCredentials.NONE.withCredential(credential));
} else {
return new EncryptedExpressionConfiguration(this, ADD_CREDENTIAL_STORE, IdentityCredentials.NONE.withCredential(credential));
return new EncryptionClientConfiguration(this, ADD_CREDENTIAL_STORE, IdentityCredentials.NONE.withCredential(credential));
}
}

Expand Down Expand Up @@ -157,12 +142,12 @@ public void setDefaultResolverName(String defaultResolverName) {
* @param credentialStore the credential store to add (must not be {@code null})
* @return the new configuration
*/
public EncryptedExpressionConfiguration addCredentialStore(String credentialStoreName, CredentialStore credentialStore) {
public EncryptionClientConfiguration addCredentialStore(String credentialStoreName, CredentialStore credentialStore) {
Assert.checkNotNullParam("name", credentialStoreName);
Assert.checkNotNullParam("credentialStore", credentialStore);
Map<String, CredentialStore> credentialStorePair = new HashMap<>();
credentialStorePair.put(credentialStoreName, credentialStore);
EncryptedExpressionConfiguration config = new EncryptedExpressionConfiguration(this, ADD_CREDENTIAL_STORE, credentialStorePair);
EncryptionClientConfiguration config = new EncryptionClientConfiguration(this, ADD_CREDENTIAL_STORE, credentialStorePair);
return config;
}

Expand All @@ -173,9 +158,9 @@ public EncryptedExpressionConfiguration addCredentialStore(String credentialStor
* @param credentialStoreMap the map of the credential store to use in place of the current ones (must not be {@code null})
* @return the new configuration
*/
public EncryptedExpressionConfiguration useCredentialStoreMap(Map<String, CredentialStore> credentialStoreMap) {
public EncryptionClientConfiguration useCredentialStoreMap(Map<String, CredentialStore> credentialStoreMap) {
if (credentialStoreMap == null || credentialStoreMap.isEmpty()) { return this; }
return new EncryptedExpressionConfiguration(this, SET_CREDENTIAL_STORE, credentialStoreMap);
return new EncryptionClientConfiguration(this, SET_CREDENTIAL_STORE, credentialStoreMap);
}

/**
Expand All @@ -185,9 +170,9 @@ public EncryptedExpressionConfiguration useCredentialStoreMap(Map<String, Creden
* @param credentialStoreName the name of the credential store to add (must not be {@code null})
* @return the new configuration
*/
public EncryptedExpressionConfiguration removeCredentialStore(String credentialStoreName) {
public EncryptionClientConfiguration removeCredentialStore(String credentialStoreName) {
Assert.checkNotNullParam("name", credentialStoreName);
EncryptedExpressionConfiguration config = new EncryptedExpressionConfiguration(this, REMOVE_CREDENTIAL_STORE, credentialStoreName);
EncryptionClientConfiguration config = new EncryptionClientConfiguration(this, REMOVE_CREDENTIAL_STORE, credentialStoreName);
return config;
}

Expand All @@ -198,11 +183,11 @@ public EncryptedExpressionConfiguration removeCredentialStore(String credentialS
* @param resolver the Encrypted Expression Resolver to add (must not be {@code null})
* @return the new configuration
*/
public EncryptedExpressionConfiguration addEncryptedExpressionResolver(EncryptedExpressionResolver resolver) {
public EncryptionClientConfiguration addEncryptedExpressionResolver(EncryptedExpressionResolver resolver) {
Assert.checkNotNullParam("encrypted expression resolver", resolver);
Map<String, EncryptedExpressionResolver.ResolverConfiguration> resolverConfigurationMap = new HashMap<>();
resolverConfigurationMap.putAll(resolver.getResolverConfiguration());
EncryptedExpressionConfiguration config = new EncryptedExpressionConfiguration(this, SET_RESOLVER, resolver);
EncryptionClientConfiguration config = new EncryptionClientConfiguration(this, SET_RESOLVER, resolver);
return config;
}
}
Loading

0 comments on commit ebcedca

Please sign in to comment.