rmaucher commented on code in PR #631: URL: https://github.com/apache/tomcat/pull/631#discussion_r1244989146
########## java/org/apache/catalina/core/PropertiesRoleMappingListener.java: ########## @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.core; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Properties; + +import org.apache.catalina.Context; +import org.apache.catalina.Lifecycle; +import org.apache.catalina.LifecycleEvent; +import org.apache.catalina.LifecycleListener; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.res.StringManager; + +/** + * Implementation of {@code LifecycleListener} that will populate the context's role mapping from a properties file. + * <p> + * This listener must only be nested within {@link Context} elements. + * <p> + * The keys represent application roles (e.g., admin, user, uservisor, etc.) while the values represent technical roles + * (e.g., DNs, SIDs, UUIDs, etc.). A key can also be prefixed if, e.g., the properties file contains generic + * application configuration as well: {@code app-roles.}. + * <p> + * Note: The default value for the {@code roleMappingFile} is {@code webapp:/WEB-INF/role-mapping.properties}. + */ +public class PropertiesRoleMappingListener implements LifecycleListener { + + private static final String WEBAPP_RESOURCE_PREFIX = "webapp:"; + private static final String CLASSPATH_RESOURCE_PREFIX = "classpath:"; + Review Comment: > > 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) Ok, so since the multiple location options are useful, then you can use the configuration source instead of the last fallback after checking for the webapp: prefix (I would argue "ok keep this one, but the other classpath prefix is then overkill"). The configuration source is a server level setting and so would have trouble accessing the Context object itself. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org