Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 66665: Provide option to supply role mapping from a properties file #631

Closed
wants to merge 1 commit into from

Conversation

michael-o
Copy link
Member

No description provided.

@michael-o michael-o requested a review from markt-asf June 26, 2023 09:50
@michael-o
Copy link
Member Author

If there are no objections, I will merge this week.

Copy link
Contributor

@markt-asf markt-asf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of exposing this feature. I'm somewhat surprised that it isn't part of the specification but, unless I am reading the XSDs incorrectly, the spec only defines role-mapping on a per Servlet basis which seems odd to me.

I'm not convinced an extra file configuration is necessary. This looks like something that could be a nested element in the context.xml file and implemented with an extra digester rule.


private static final String WEBAPP_RESOURCE_PREFIX = "webapp:";
private static final String CLASSPATH_RESOURCE_PREFIX = "classpath:";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a new scheme for naming configuration files. It should instead use the ConfigFileLoader and ConfigurationSource. They would need extending to include web application relative resources as they currently only support absolute file, files relative to $CATALINA_BASE, classpath and URI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the specific case of this feature, it seems the only "real" location that makes sense would be the default one anyway. So I would simply remove the option to have it in random places and be done with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the specific case of this feature, it seems the only "real" location that makes sense would be the default one anyway. So I would simply remove the option to have it in random places and be done with it.

I disagree, see my explanation below.

Copy link
Member Author

@michael-o michael-o Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a new scheme for naming configuration files. It should instead use the ConfigFileLoader and ConfigurationSource. They would need extending to include web application relative resources as they currently only support absolute file, files relative to $CATALINA_BASE, classpath and URI.

Correct, that is a problem. I didn't know what features are available to make this happen. Let me look into the mentioned classes and try to rewrite it.

Copy link
Member Author

@michael-o michael-o Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a new scheme for naming configuration files. It should instead use the ConfigFileLoader and ConfigurationSource. They would need extending to include web application relative resources as they currently only support absolute file, files relative to $CATALINA_BASE, classpath and URI.

@markt-asf While looking into this, I understand how the system works how classpath: is registered with the JVM, hoping that it will use the webapp's classpath, but I fail to see how to provide the Context to org.apache.tomcat.util.file.ConfigFileLoader.getSource() without modifing it. Any pointers I could evaluate? I could of course first look into servlet context and then if not found pass to the ConfigFileLoader... (chaining basically)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I tried to find a spot to add a new call in the configuration source for a "public Resource getResource(Context context, String name)" but IMO this doesn't add anything and also there's no ideal spot for that.

Correct, I would consider improving the ConfigurationSource a separate discussion which should not be solved here. If the class is being improved, I'd be happy to skim this class after that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about it for a bit, adding a helper method to the Context interface seemed like the way to go to me. This is helpful to allow more flexibility on location of configs that can be bundled in the webapp, and also it makes the ConfigurationSource API a bit more visible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you are after:
public Resource org.apache.catalina.Context#getResource(String) which will probe for webapp: and the delegate to ConfigFileLoader?

I will happily add this, but it should be a separate PR after this one. Then when the new PR is done, I can modify this listener and it will be its first use case. Is that OK for you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, this is a minor detail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, then I will proceed with the merge and start working on the draft.

@michael-o
Copy link
Member Author

michael-o commented Jun 28, 2023

I like the idea of exposing this feature. I'm somewhat surprised that it isn't part of the specification but, unless I am reading the XSDs incorrectly, the spec only defines role-mapping on a per Servlet basis which seems odd to me.

Correct and I consider the per-Servlet one as unusable if you have tens of them.

I'm not convinced an extra file configuration is necessary. This looks like something that could be a nested element in the context.xml file and implemented with an extra digester rule.

Both should be possible because the file could be in the classpath which contains more than just the mapping. Just being in the context.xml it is not available to the actual application, but just to Tomcat. In a future revision the source could be done flexible. At least in my usecase, having it in context.xml would force me to duplicate the mapping and that is unacceptable.

@michael-o
Copy link
Member Author

@rmaucher @markt-asf Incorporated your comments. Please have a look again.

@michael-o
Copy link
Member Author

Merged manually.

@michael-o michael-o closed this Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants