我尝试使用 spring 安全性来保护我的 osgi 服务和 Web 应用程序,拦截 url 工作正常,但全局方法安全性根本不起作用。对于纯 OSGI 捆绑包,代理模式不起作用,因为 spring-beans 无法访问 SpringProxy。我尝试了代理模式和 aspectj 模式,并在 aspectj 模式下启用了加载时间编织,捆绑包已成功加载。但是预授权不起作用(在 xml 配置中添加了 pre-post-annotations="enabled"),并且在接口和实现上都添加了注释,但它仍然不起作用。
我不知道弹簧安全保护豆的方法的机制。有人可以给我一些提示吗?谢谢!
找到原因,默认情况下上下文:组件扫描不会为生成的 bean 生成代理。
<context:component-scan base-package="org.ops4j.pax.web.samples.spring.service" scoped-proxy="targetClass/interfaces" />
在组件扫描OsgiBundleResourcePatternResolver中定义搜索类时,spring-osgi-io中存在错误,这真的很可悲。类路径从开头删除,因此在步骤 2 中,它搜索捆绑包根文件夹,而不是类路径
消除类路径路径 final String path = OsgiResourceUtils.stripPrefix(locationPattern);
final Collection foundPaths = new LinkedHashSet();
// 1. search the imported packages
// find folder path matching
final String rootDirPath = determineFolderPattern(path);
if (System.getSecurityManager() != null) {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
for (int i = 0; i < importedBundles.length; i++) {
final ImportedBundle importedBundle = importedBundles[i];
if (!bundle.equals(importedBundle.getBundle())) {
findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
}
}
return null;
}
});
}
else {
for (int i = 0; i < importedBundles.length; i++) {
final ImportedBundle importedBundle = importedBundles[i];
if (!bundle.equals(importedBundle.getBundle())) {
findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
}
}
}
// 2. search the target bundle
findSyntheticClassPathMatchingResource(bundle, path, foundPaths);