Skip to content

Commit

Permalink
Merge branch 'WFCORE-7112' into ModuleIdentifier_in_API
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Dec 22, 2024
2 parents 2d5e40a + 9e59bf1 commit 5054f88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PermissionFactory> 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<PermissionFactory> parse(final XMLStreamReader reader, final ModuleLoader loader, final String moduleName)
throws XMLStreamException {

reader.require(XMLStreamConstants.START_DOCUMENT, null, null);

Expand All @@ -42,7 +60,7 @@ public static List<PermissionFactory> 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);
Expand All @@ -57,7 +75,7 @@ public static List<PermissionFactory> parse(final XMLStreamReader reader, final
throw unexpectedEndOfDocument(reader);
}

private static List<PermissionFactory> parsePermissions(final XMLStreamReader reader, final ModuleLoader loader, final ModuleIdentifier identifier)
private static List<PermissionFactory> parsePermissions(final XMLStreamReader reader, final ModuleLoader loader, final String moduleName)
throws XMLStreamException {

List<PermissionFactory> factories = new ArrayList<PermissionFactory>();
Expand Down Expand Up @@ -98,7 +116,7 @@ private static List<PermissionFactory> 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;
}
Expand All @@ -116,7 +134,7 @@ private static List<PermissionFactory> 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.
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> wflyResolverFunc = deploymentUnit.getAttachment(Attachments.WFLY_DESCRIPTOR_EXPR_EXPAND_FUNCTION);
final Function<String, String> specResolverFunc = deploymentUnit.getAttachment(Attachments.SPEC_DESCRIPTOR_EXPR_EXPAND_FUNCTION);

Expand Down Expand Up @@ -129,21 +128,21 @@ 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<PermissionFactory> parsePermissions(final VirtualFile file, final ModuleLoader loader, final ModuleIdentifier identifier, final Function<String, String> exprExpandFunction)
private List<PermissionFactory> parsePermissions(final VirtualFile file, final ModuleLoader loader, final String moduleName, final Function<String, String> exprExpandFunction)
throws DeploymentUnitProcessingException {

InputStream inputStream = null;
try {
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 {
Expand Down

0 comments on commit 5054f88

Please sign in to comment.