diff --git a/elytron/src/main/java/org/wildfly/extension/elytron/JdbcRealmDefinition.java b/elytron/src/main/java/org/wildfly/extension/elytron/JdbcRealmDefinition.java index a23ed7d5b54..b95141c0f22 100644 --- a/elytron/src/main/java/org/wildfly/extension/elytron/JdbcRealmDefinition.java +++ b/elytron/src/main/java/org/wildfly/extension/elytron/JdbcRealmDefinition.java @@ -19,7 +19,6 @@ import static org.wildfly.extension.elytron._private.ElytronSubsystemMessages.ROOT_LOGGER; import java.nio.charset.Charset; -import java.security.InvalidKeyException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -33,8 +32,10 @@ import org.jboss.as.controller.ObjectListAttributeDefinition; import org.jboss.as.controller.ObjectTypeAttributeDefinition; import org.jboss.as.controller.OperationContext; +import org.jboss.as.controller.OperationContext.Stage; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; +import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.RunningMode; @@ -43,11 +44,12 @@ import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.operations.validation.CharsetValidator; -import org.jboss.as.controller.operations.validation.StringAllowedValuesValidator; import org.jboss.as.controller.operations.validation.IntRangeValidator; +import org.jboss.as.controller.operations.validation.StringAllowedValuesValidator; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.OperationEntry; +import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.msc.inject.InjectionException; @@ -455,7 +457,7 @@ public PasswordKeyMapper toPasswordKeyMapper(OperationContext context, ModelNode } interface PasswordMapperObjectDefinition { - PasswordKeyMapper toPasswordKeyMapper(OperationContext context, ModelNode propertyNode) throws OperationFailedException, InvalidKeyException; + PasswordKeyMapper toPasswordKeyMapper(OperationContext context, ModelNode propertyNode) throws OperationFailedException; } static class AttributeMappingObjectDefinition { @@ -591,6 +593,13 @@ private RealmAddHandler() { super(SECURITY_REALM_RUNTIME_CAPABILITY); } + @Override + protected void populateModel(OperationContext context, ModelNode operation, Resource resource) + throws OperationFailedException { + super.populateModel(context, operation, resource); + context.addStep(new JdbcRealmDefinitionValidation(), Stage.MODEL); + } + @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { @@ -653,6 +662,26 @@ private AttributeMapper[] resolveAttributeMappers(OperationContext context, Mode } } + private static class JdbcRealmDefinitionValidation implements OperationStepHandler { + + @Override + public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { + + ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); + List queries = model.get(PrincipalQueryAttributes.PRINCIPAL_QUERIES_7_0.getName()).asList(); + + for (ModelNode modelNode : queries) { + long mappersCount = modelNode.keys().stream() + .filter(PrincipalQueryAttributes.SUPPORTED_PASSWORD_MAPPERS::containsKey).count(); + + // We need to make sure that the principal-query has only one mapper + if (mappersCount > 1) { + throw ROOT_LOGGER.jdbcRealmOnlySingleKeyMapperAllowed(); + } + } + } + } + private static KeyMapper resolveKeyMappers(OperationContext context, ModelNode authenticationQueryNode) throws OperationFailedException { KeyMapper keyMapper = null; @@ -669,17 +698,10 @@ private static KeyMapper resolveKeyMappers(OperationContext context, ModelNode a continue; } - if (keyMapper != null) { - throw ROOT_LOGGER.jdbcRealmOnlySingleKeyMapperAllowed(); - } - - try { - keyMapper = mapperResource.toPasswordKeyMapper(context, propertyNode); - } catch (InvalidKeyException e) { - throw new OperationFailedException("Invalid key type.", e); - } + keyMapper = mapperResource.toPasswordKeyMapper(context, propertyNode); } return keyMapper; } + } diff --git a/elytron/src/test/java/org/wildfly/extension/elytron/ResolveExpressionAttributesTestCase.java b/elytron/src/test/java/org/wildfly/extension/elytron/ResolveExpressionAttributesTestCase.java index c935f880069..5fd05336484 100644 --- a/elytron/src/test/java/org/wildfly/extension/elytron/ResolveExpressionAttributesTestCase.java +++ b/elytron/src/test/java/org/wildfly/extension/elytron/ResolveExpressionAttributesTestCase.java @@ -181,7 +181,8 @@ private void testJaspiConfiguration() { } private void testJdbcRealm() { - ModelNode jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcRealm").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); + + ModelNode jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcRealmBcrypt").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); // Bcrypt password mapper ModelNode mapper = jdbcRealm.get(ElytronDescriptionConstants.BCRYPT_MAPPER); @@ -192,15 +193,18 @@ private void testJdbcRealm() { assertEquals("hex", getValue(mapper, ElytronDescriptionConstants.SALT_ENCODING)); // Clear password mapper + jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcRealmClearPassword").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); mapper = jdbcRealm.get(ElytronDescriptionConstants.CLEAR_PASSWORD_MAPPER); assertEquals("2", getValue(mapper, ElytronDescriptionConstants.PASSWORD_INDEX)); // Simple digest password mapper + jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcRealmSimple").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); mapper = jdbcRealm.get(ElytronDescriptionConstants.SIMPLE_DIGEST_MAPPER); assertEquals("2", getValue(mapper, ElytronDescriptionConstants.PASSWORD_INDEX)); assertEquals("hex", getValue(mapper, ElytronDescriptionConstants.HASH_ENCODING)); // Salted simple digest password mapper + jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcRealmSalted").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); mapper = jdbcRealm.get(ElytronDescriptionConstants.SALTED_SIMPLE_DIGEST_MAPPER); assertEquals("2", getValue(mapper, ElytronDescriptionConstants.PASSWORD_INDEX)); assertEquals("3", getValue(mapper, ElytronDescriptionConstants.SALT_INDEX)); @@ -209,6 +213,7 @@ private void testJdbcRealm() { assertEquals("hex", getValue(mapper, ElytronDescriptionConstants.SALT_ENCODING)); // Scram password mapper + jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcScram").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); mapper = jdbcRealm.get(ElytronDescriptionConstants.SCRAM_MAPPER); assertEquals("2", getValue(mapper, ElytronDescriptionConstants.PASSWORD_INDEX)); assertEquals("3", getValue(mapper, ElytronDescriptionConstants.SALT_INDEX)); @@ -217,6 +222,7 @@ private void testJdbcRealm() { assertEquals("hex", getValue(mapper, ElytronDescriptionConstants.SALT_ENCODING)); // Modular crypt mapper + jdbcRealm = serverModel.get(ElytronDescriptionConstants.JDBC_REALM).get("JdbcRealmModular").get(ElytronDescriptionConstants.PRINCIPAL_QUERY).get(0); mapper = jdbcRealm.get(ElytronDescriptionConstants.MODULAR_CRYPT_MAPPER); assertEquals("2", getValue(mapper, ElytronDescriptionConstants.PASSWORD_INDEX)); } diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-expressions.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-expressions.xml index df6e6e46c8f..4a4d8c068f9 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-expressions.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-expressions.xml @@ -57,19 +57,52 @@ - + + + + + + - + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-18.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-18.0.xml index e1e77e73fd6..82f47340b48 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-18.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-18.0.xml @@ -48,17 +48,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-community-18.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-community-18.0.xml index 79811affd81..d07f3bf2ff7 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-community-18.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/elytron-subsystem-community-18.0.xml @@ -51,17 +51,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-10.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-10.0.xml index 521d4b1e0ad..bc59d27533b 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-10.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-10.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-11.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-11.0.xml index 033e089d880..06266ba434d 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-11.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-11.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-12.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-12.0.xml index 744b3f68ad8..33a6560ac5a 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-12.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-12.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-13.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-13.0.xml index 29e67c58031..ad1812bcdfc 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-13.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-13.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-14.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-14.0.xml index 21515ee0888..3508e2ed4a9 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-14.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-14.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.0.xml index 58161611d52..e601f66eec7 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.1.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.1.xml index ea71d44c20c..8a5ec4590d8 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.1.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-15.1.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-16.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-16.0.xml index 0c2ded26c28..624f538d616 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-16.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-16.0.xml @@ -43,17 +43,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-17.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-17.0.xml index 93d58d749b4..c47fc645456 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-17.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-17.0.xml @@ -48,17 +48,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-7.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-7.0.xml index 094d9eefa79..7ba1ed9f106 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-7.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-7.0.xml @@ -35,17 +35,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-8.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-8.0.xml index 98c1bd85390..0eac98c151b 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-8.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-8.0.xml @@ -40,17 +40,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + diff --git a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-9.0.xml b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-9.0.xml index ba7c524e5d7..9956c393429 100644 --- a/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-9.0.xml +++ b/elytron/src/test/resources/org/wildfly/extension/elytron/legacy-elytron-subsystem-9.0.xml @@ -40,17 +40,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + +