From 9e59bf1bcdf14bc00bccb13f7dfd0274fb6e9270 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Sat, 21 Dec 2024 19:09:40 -0500 Subject: [PATCH] [WFCORE-7112] Deprecate PermissionsParser.parse that takes ModuleIdentifier --- .../manager/deployment/PermissionsParser.java | 28 +++++++++++++++---- .../PermissionsParserProcessor.java | 9 +++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParser.java b/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParser.java index cc6c7e5c242..1440e4255c4 100644 --- a/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParser.java +++ b/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParser.java @@ -31,8 +31,26 @@ */ public class PermissionsParser { + // TODO remove this as soon as the full WF testsuite use of it is updated to use the string variant + /** + * @deprecated use {@link #parse(XMLStreamReader, ModuleLoader, String)} + */ + @Deprecated(forRemoval = true) public static List parse(final XMLStreamReader reader, final ModuleLoader loader, final ModuleIdentifier identifier) throws XMLStreamException { + return parse(reader,loader, identifier.toString()); + } + + /** + * Parse the contents exposed by a reader into a list of {@link PermissionFactory} instances. + * @param reader reader of a {@code permissions.xml} or {@code jboss-permissions.xml} descriptor. Cannot be {@code null}. + * @param loader loader to use for loading permission classes. Cannot be {@code null}. + * @param moduleName canonical name of the module to use for loading permission classes. Cannot be {@code null}. + * @return a list of {@link PermissionFactory} instances + * @throws XMLStreamException if a parsing error occurs + */ + public static List parse(final XMLStreamReader reader, final ModuleLoader loader, final String moduleName) + throws XMLStreamException { reader.require(XMLStreamConstants.START_DOCUMENT, null, null); @@ -42,7 +60,7 @@ public static List parse(final XMLStreamReader reader, final Element element = Element.forName(reader.getLocalName()); switch (element) { case PERMISSIONS: { - return parsePermissions(reader, loader, identifier); + return parsePermissions(reader, loader, moduleName); } default: { throw unexpectedElement(reader); @@ -57,7 +75,7 @@ public static List parse(final XMLStreamReader reader, final throw unexpectedEndOfDocument(reader); } - private static List parsePermissions(final XMLStreamReader reader, final ModuleLoader loader, final ModuleIdentifier identifier) + private static List parsePermissions(final XMLStreamReader reader, final ModuleLoader loader, final String moduleName) throws XMLStreamException { List factories = new ArrayList(); @@ -98,7 +116,7 @@ private static List parsePermissions(final XMLStreamReader re Element element = Element.forName(reader.getLocalName()); switch (element) { case PERMISSION: { - PermissionFactory factory = parsePermission(reader, loader, identifier); + PermissionFactory factory = parsePermission(reader, loader, moduleName); factories.add(factory); break; } @@ -116,7 +134,7 @@ private static List parsePermissions(final XMLStreamReader re throw unexpectedEndOfDocument(reader); } - private static PermissionFactory parsePermission(final XMLStreamReader reader, final ModuleLoader loader, final ModuleIdentifier identifier) + private static PermissionFactory parsePermission(final XMLStreamReader reader, final ModuleLoader loader, final String moduleName) throws XMLStreamException { // permission element has no attributes. @@ -136,7 +154,7 @@ private static PermissionFactory parsePermission(final XMLStreamReader reader, f // build a permission and add it to the list. PermissionFactory factory = new DeferredPermissionFactory(DeferredPermissionFactory.Type.DEPLOYMENT, - loader, identifier.toString(), permissionClass, permissionName, permissionActions); + loader, moduleName, permissionClass, permissionName, permissionActions); return factory; } case XMLStreamConstants.START_ELEMENT: { diff --git a/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParserProcessor.java b/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParserProcessor.java index 4a9386cbcf6..c17688dd604 100644 --- a/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParserProcessor.java +++ b/security-manager/src/main/java/org/wildfly/extension/security/manager/deployment/PermissionsParserProcessor.java @@ -20,7 +20,6 @@ import org.jboss.as.server.deployment.module.ExpressionStreamReaderDelegate; import org.jboss.as.server.deployment.module.ModuleSpecification; import org.jboss.as.server.deployment.module.ResourceRoot; -import org.jboss.modules.ModuleIdentifier; import org.jboss.modules.ModuleLoader; import org.jboss.modules.security.PermissionFactory; import org.jboss.vfs.VirtualFile; @@ -75,7 +74,7 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); - final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER); + final String moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER).toString(); final Function wflyResolverFunc = deploymentUnit.getAttachment(Attachments.WFLY_DESCRIPTOR_EXPR_EXPAND_FUNCTION); final Function specResolverFunc = deploymentUnit.getAttachment(Attachments.SPEC_DESCRIPTOR_EXPR_EXPAND_FUNCTION); @@ -129,13 +128,13 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU * * @param file the {@link VirtualFile} that contains the permissions declarations. * @param loader the {@link ModuleLoader} that is to be used by the factory to instantiate the permission. - * @param identifier the {@link ModuleIdentifier} that is to be used by the factory to instantiate the permission. + * @param moduleName the name of the module that is to be used by the factory to instantiate the permission. * @param exprExpandFunction A function which will be used, if provided, to expand any expressions (of the form of {@code ${foobar}}) * in the content being parsed. This function can be null, in which case the content is processed literally. * @return a list of {@link PermissionFactory} objects representing the parsed permissions. * @throws DeploymentUnitProcessingException if an error occurs while parsing the permissions. */ - private List parsePermissions(final VirtualFile file, final ModuleLoader loader, final ModuleIdentifier identifier, final Function exprExpandFunction) + private List parsePermissions(final VirtualFile file, final ModuleLoader loader, final String moduleName, final Function exprExpandFunction) throws DeploymentUnitProcessingException { InputStream inputStream = null; @@ -143,7 +142,7 @@ private List parsePermissions(final VirtualFile file, final M inputStream = file.openStream(); final XMLInputFactory inputFactory = XMLInputFactoryUtil.create(); final ExpressionStreamReaderDelegate expressionStreamReaderDelegate = new ExpressionStreamReaderDelegate(inputFactory.createXMLStreamReader(inputStream), exprExpandFunction); - return PermissionsParser.parse(expressionStreamReaderDelegate, loader, identifier); + return PermissionsParser.parse(expressionStreamReaderDelegate, loader, moduleName); } catch (Exception e) { throw new DeploymentUnitProcessingException(e.getMessage(), e); } finally {