Skip to content

Commit d6fb618

Browse files
committed
Consolidate parameters
1 parent 98086f3 commit d6fb618

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
lines changed

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,35 @@ A [Bnd](https://bnd.bndtools.org/) plugin that validates OSGi bundle metadata co
1313

1414
- **Export Packages** - Validates that exported packages follow naming conventions
1515
- **Bundle Symbolic Names** - Ensures bundle symbolic names conform to organizational standards
16-
- **OSGi DS Component Service Interfaces** - Validates service interface FQCNs in OSGi DS components
17-
- **OSGi HTTP/Servlet Whiteboard** - Validates that HTTP servlets/filters registered via [HTTP/servlet whiteboard](https://docs.osgi.org/specification/osgi.cmpn/8.1.0/service.servlet.html) are listening to specific paths only
16+
- **DS Component Provided Services** - Validates [provided service FQCNs in DS components](https://docs.osgi.org/specification/osgi.cmpn/8.1.0/service.component.html#service.component-service.element)
17+
- **HTTP/Servlet Whiteboard** - Validates that HTTP servlets/filters registered via [HTTP/servlet whiteboard](https://docs.osgi.org/specification/osgi.cmpn/8.1.0/service.servlet.html) are listening to specific paths only
1818
- **Sling Servlet/Filter** - Validates [Sling servlet](https://sling.apache.org/documentation/the-sling-engine/servlets.html) paths, resource types, and resource super types as well as [Sling filter](https://sling.apache.org/documentation/the-sling-engine/filters.html) patterns/resource types
1919
- **Sling Authentication Handler** - Validates a [Sling Authentication Handler](https://sling.apache.org/documentation/the-sling-engine/authentication/authentication-authenticationhandler.html) is registered to a specific path only
2020

2121
## Features
2222

23-
### Export Package Validation
23+
### Export Packages
2424
Validates that all exported packages match a specified regular expression pattern.
2525

26-
### Bundle Symbolic Name Validation
26+
### Bundle Symbolic Name sn
2727
Ensures Bundle-SymbolicName headers conform to naming conventions, with support for parameter handling (e.g., `singleton:=true`).
2828

29-
### OSGi DS Component Service Validation
30-
Validates that OSGi Declarative Services components only implement services whose fully qualified class names match specified patterns.
31-
Apart from the explicitly managed configuration there is implicit allows for all those commons services which have multitenancy via a specific (validated) OSGi property.r
29+
### DS Component Provided Services
30+
Validates that Declarative Services components only provide services whose fully qualified class names match specified patterns.
31+
Apart from the explicitly managed configuration there is implicit allows for all those commons services which have multi-tenancy support built-in via a specific (validated) OSGi property. Those
32+
are validated on a different level.
3233

33-
### OSGi HTTP/Servlet Whiteboardd
34+
### HTTP/Servlet Whiteboard
3435
For DS components implementing `javax.servlet.Servlet` or `jakarta.servlet.Servlet`, validates
3536

36-
- `osgi.http.whiteboard.servlet.pattern` - Servlet path pattern
37+
- `osgi.http.whiteboard.servlet.pattern` - Servlet pattern
3738

3839

3940
For DS components implementing `javax.servlet.Filter` or `jakarta.servlet.Filter`, validates
4041

4142
- `osgi.http.whiteboard.filter.pattern` - Servlet filter pattern
4243

43-
### Sling Servlet/Filter Property Validation
44+
### Sling Servlet/Filter
4445
For DS components implementing `javax.servlet.Servlet` or `jakarta.servlet.Servlet`, validates:
4546
- `sling.servlet.paths` - Servlet path patterns
4647
- `sling.servlet.resourceTypes` - Resource type patterns
@@ -65,14 +66,14 @@ Parameter | Type | Description
6566
`allowedExportPackagePatterns` | Pattern[] | Regular expression(s) for validating exported package names
6667
`allowedBundleSymbolicNamePatterns` | Pattern[] | Regular expression(s) for validating Bundle-SymbolicName header
6768
`allowedServiceClassPatterns` | Pattern[] | Regular expression(s) for validating OSGi service interface FQCNs
68-
`allowedOsgiHttpWhiteboardServletPatterns` | Pattern[] | Regular expression(s) for validating OSGi HTTP Whiteboard servlet patterns (`osgi.http.whiteboard.servlet.pattern`)
69-
`allowedOsgiHttpWhiteboardFilterPatterns` | Pattern[] | Regular expression(s) for validating OSGi HTTP Whiteboard filter patterns (`osgi.http.whiteboard.filter.pattern`)
70-
`slingServletPathsPatterns` | Pattern[] | Regular expression(s) for validating Sling servlet paths (`sling.servlet.paths`)
71-
`slingServletResourceTypesPatterns` | Pattern[] | Regular expression(s) for validating Sling servlet resource types (`sling.servlet.resourceTypes`)
72-
`slingServletResourceSuperTypePatterns` | Pattern[] | Regular expression(s) for validating Sling servlet resource super types (`sling.servlet.resourceSuperType`)
73-
`slingFilterPatterns` | Pattern[] | Regular expression(s) for validating Sling filter patterns (`sling.filter.pattern`)
74-
`slingFilterResourceTypesPatterns` | Pattern[] | Regular expression(s) for validating Sling filter resource types (`sling.filter.resourceTypes`)
75-
`slingAuthHandlerPathPatterns` | Pattern[] | Regular expression(s) for validating Sling Authentication Handler path property (`path`)
69+
`allowedHttpWhiteboardServletPatterns` | Pattern[] | Regular expression(s) for validating HTTP Whiteboard servlet patterns (`osgi.http.whiteboard.servlet.pattern`)
70+
`allowedHttpWhiteboardFilterPatterns` | Pattern[] | Regular expression(s) for validating HTTP Whiteboard filter patterns (`osgi.http.whiteboard.filter.pattern`)
71+
`allowedSlingServletPathsPatterns` | Pattern[] | Regular expression(s) for validating Sling servlet paths (`sling.servlet.paths`)
72+
`allowedSlingServletResourceTypesPatterns` | Pattern[] | Regular expression(s) for validating Sling servlet resource types (`sling.servlet.resourceTypes`)
73+
`allowedSlingServletResourceSuperTypePatterns` | Pattern[] | Regular expression(s) for validating Sling servlet resource super types (`sling.servlet.resourceSuperType`)
74+
`allowedSlingFilterPatterns` | Pattern[] | Regular expression(s) for validating Sling filter patterns (`sling.filter.pattern`)
75+
`allowedSlingFilterResourceTypesPatterns` | Pattern[] | Regular expression(s) for validating Sling filter resource types (`sling.filter.resourceTypes`)
76+
`allowedSlingAuthenticationHandlerPathPatterns` | Pattern[] | Regular expression(s) for validating Sling Authentication Handler's path property (`path`)
7677

7778
Each parameter may take multiple [regular expression patterns](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) separated by comma. That makes the comma itself unusable within the regular expression pattern itself, however this shouldn't be necessary there.
7879
All parameters are optional. If not set the according property/name/header is not validated.

src/main/java/biz/netcentric/osgi/bnd/NamespaceValidatorsPlugin.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ public class NamespaceValidatorsPlugin implements VerifierPlugin, Plugin {
9595
"allowedExportPackagePatterns",
9696
"allowedServiceClassPatterns",
9797
"allowedBundleSymbolicNamePatterns",
98+
"allowedHttpWhiteboardServletPatternPatterns",
99+
"allowedHttpWhiteboardFilterPatternPatterns",
98100
"allowedSlingServletPathsPatterns",
99101
"allowedSlingServletResourceTypesPatterns",
100102
"allowedSlingServletResourceSuperTypePatterns",
101-
"allowedHttpWhiteboardServletPatternPatterns",
102-
"allowedAuthenticationHandlerPathPatterns",
103103
"allowedSlingFilterPatternPatterns",
104-
"allowedHttpWhiteboardFilterPatternPatterns");
104+
"allowedSlingFilterResourceTypesPatterns",
105+
"allowedSlingAuthenticationHandlerPathPatterns");
105106

106107
private static final Collection<Pattern> ALLOWED_TENANT_SPECIFIC_SERVICES;
107108

@@ -155,6 +156,18 @@ interface Config {
155156
*/
156157
Collection<Pattern> allowedBundleSymbolicNamePatterns();
157158

159+
/**
160+
* Patterns for validating HTTP Whiteboard filter pattern property (osgi.http.whiteboard.filter.pattern).
161+
* If not specified, no HTTP Whiteboard filter pattern validation is performed.
162+
*/
163+
Collection<Pattern> allowedHttpWhiteboardFilterPatternPatterns();
164+
165+
/**
166+
* Patterns for validating HTTP Whiteboard servlet pattern property (osgi.http.whiteboard.servlet.pattern).
167+
* If not specified, no HTTP Whiteboard servlet pattern validation is performed.
168+
*/
169+
Collection<Pattern> allowedHttpWhiteboardServletPatternPatterns();
170+
158171
/**
159172
* Pattern for validating Sling servlet paths property (sling.servlet.paths).
160173
* If not specified, no servlet paths validation is performed.
@@ -174,16 +187,10 @@ interface Config {
174187
Collection<Pattern> allowedSlingServletResourceSuperTypePatterns();
175188

176189
/**
177-
* Patterns for validating HTTP Whiteboard servlet pattern property (osgi.http.whiteboard.servlet.pattern).
178-
* If not specified, no HTTP Whiteboard servlet pattern validation is performed.
179-
*/
180-
Collection<Pattern> allowedHttpWhiteboardServletPatternPatterns();
181-
182-
/**
183-
* Patterns for validating AuthenticationHandler path property (path).
190+
* Patterns for validating Slings AuthenticationHandler path property (path).
184191
* If not specified, no AuthenticationHandler path validation is performed.
185192
*/
186-
Collection<Pattern> allowedAuthenticationHandlerPathPatterns();
193+
Collection<Pattern> allowedSlingAuthenticationHandlerPathPatterns();
187194

188195
/**
189196
* Patterns for validating Sling filter pattern property (sling.filter.pattern).
@@ -196,12 +203,6 @@ interface Config {
196203
* If not specified, no servlet resource types validation is performed.
197204
*/
198205
Collection<Pattern> allowedSlingFilterResourceTypesPatterns();
199-
200-
/**
201-
* Patterns for validating HTTP Whiteboard filter pattern property (osgi.http.whiteboard.filter.pattern).
202-
* If not specified, no HTTP Whiteboard filter pattern validation is performed.
203-
*/
204-
Collection<Pattern> allowedHttpWhiteboardFilterPatternPatterns();
205206
}
206207

207208
@Override
@@ -303,8 +304,9 @@ private void checkDSComponentServices(Analyzer analyzer) {
303304
.isEmpty())
304305
|| (config.allowedHttpWhiteboardServletPatternPatterns() != null
305306
&& !config.allowedHttpWhiteboardServletPatternPatterns().isEmpty())
306-
|| (config.allowedAuthenticationHandlerPathPatterns() != null
307-
&& !config.allowedAuthenticationHandlerPathPatterns().isEmpty());
307+
|| (config.allowedSlingAuthenticationHandlerPathPatterns() != null
308+
&& !config.allowedSlingAuthenticationHandlerPathPatterns()
309+
.isEmpty());
308310
if (!shouldCheck) {
309311
return; // No relevant patterns configured, skip validation
310312
}
@@ -643,22 +645,22 @@ private void validateServletProperties(String componentName, Map<String, String>
643645
* Validates AuthenticationHandler path against configured patterns.
644646
*/
645647
private void validateAuthenticationHandlerPath(String componentName, Map<String, String> properties) {
646-
if (config.allowedAuthenticationHandlerPathPatterns() == null
647-
|| config.allowedAuthenticationHandlerPathPatterns().isEmpty()) {
648+
if (config.allowedSlingAuthenticationHandlerPathPatterns() == null
649+
|| config.allowedSlingAuthenticationHandlerPathPatterns().isEmpty()) {
648650
return;
649651
}
650652
if (properties.containsKey(AUTH_HANDLER_PATH_PROPERTY)) {
651653
String propertyValue = properties.get(AUTH_HANDLER_PATH_PROPERTY);
652654
String[] paths = propertyValue.split(",");
653655
for (String path : paths) {
654656
String trimmedPath = path.trim();
655-
if (config.allowedAuthenticationHandlerPathPatterns().stream()
657+
if (config.allowedSlingAuthenticationHandlerPathPatterns().stream()
656658
.noneMatch(pattern -> pattern.matcher(trimmedPath).matches())) {
657659
reporter.error(
658660
"AuthenticationHandler component \"%s\" has path \"%s\" which does not match any of the allowed patterns [%s]",
659661
componentName,
660662
trimmedPath,
661-
config.allowedAuthenticationHandlerPathPatterns().stream()
663+
config.allowedSlingAuthenticationHandlerPathPatterns().stream()
662664
.map(Pattern::pattern)
663665
.collect(Collectors.joining(",")));
664666
}

src/test/java/biz/netcentric/osgi/bnd/NamespaceValidatorsPluginTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void testAuthenticationHandlerPath_Valid() throws Exception {
620620
void testAuthenticationHandlerPath_Invalid() throws Exception {
621621
Map<String, String> config = new HashMap<>();
622622
config.put("allowedExportPackagePatterns", ".*");
623-
config.put("allowedAuthenticationHandlerPathPatterns", "/auth|/secure");
623+
config.put("allowedSlingAuthenticationHandlerPathPatterns", "/auth|/secure");
624624
plugin.setProperties(config);
625625

626626
when(analyzer.getProperty("Service-Component")).thenReturn("OSGI-INF/AuthHandler.xml");
@@ -671,7 +671,7 @@ void testAuthenticationHandlerPath_NoPatternConfigured() throws Exception {
671671
void testAuthenticationHandlerPath_MultiplePaths() throws Exception {
672672
Map<String, String> config = new HashMap<>();
673673
config.put("allowedExportPackagePatterns", ".*");
674-
config.put("allowedAuthenticationHandlerPathPatterns", "/auth|/secure");
674+
config.put("allowedSlingAuthenticationHandlerPathPatterns", "/auth|/secure");
675675
plugin.setProperties(config);
676676

677677
when(analyzer.getProperty("Service-Component")).thenReturn("OSGI-INF/AuthHandler.xml");

0 commit comments

Comments
 (0)