我确信它是可行的,尽管我已经看到一些限制/问题突然出现。 对于 1)没有尝试过,虽然你需要确保你告诉pax-web和jetty它,它需要将它添加到jetty.xml,甚至可能需要将一个片段包添加到pax- web-jetty所以可以加载所需的类。这很可能是您的第一个类别未发现的问题。 2)不知道WSO2所以不知道 3)如果你想使用注释,要小心。对于Guice,你最需要使用Peaberry,因为afai Guice不是“OSGi-fied”。由于类加载器的限制,在OSGi环境中使用AspectJ并不是一个好主意。如果你有编译时编织它应该没问题,但运行时编织将是一个挑战。
更新: 完全忘了它,但有一个 Pax Shiro 项目可用,也许这可以是一个很好的起点,让你的设置正确的阵容。
为了读者的利益,我正在分享我在对现有工具进行一些研究后得出的解决方案。首先,简单的部分:在OSGi环境中使用Shiro注释。我最后编写了下面的类,因为开发人员共享的大多数Shiro-Jersey适配器都基于Jersey 1.x.
@Provider public class ShiroAnnotationResourceFilter implements ContainerRequestFilter { private static final Map, AuthorizingAnnotationHandler> ANNOTATION_MAP = new HashMap, AuthorizingAnnotationHandler>(); @Context private ResourceInfo resourceInfo; public ShiroAnnotationResourceFilter() { ANNOTATION_MAP.put(RequiresPermissions.class, new PermissionAnnotationHandler()); ANNOTATION_MAP.put(RequiresRoles.class, new RoleAnnotationHandler()); ANNOTATION_MAP.put(RequiresUser.class, new UserAnnotationHandler()); ANNOTATION_MAP.put(RequiresGuest.class, new GuestAnnotationHandler()); ANNOTATION_MAP.put(RequiresAuthentication.class, new AuthenticatedAnnotationHandler()); } public void filter(ContainerRequestContext context) throws IOException { Class resourceClass = resourceInfo.getResourceClass(); if (resourceClass != null) { Annotation annotation = fetchAnnotation(resourceClass .getAnnotations()); if (annotation != null) { ANNOTATION_MAP.get(annotation.annotationType()) .assertAuthorized(annotation); } } Method method = resourceInfo.getResourceMethod(); if (method != null) { Annotation annotation = fetchAnnotation(method.getAnnotations()); if (annotation != null) { ANNOTATION_MAP.get(annotation.annotationType()) .assertAuthorized(annotation); } } } private static Annotation fetchAnnotation(Annotation[] annotations) { for (Annotation annotation : annotations) { if (ANNOTATION_MAP.keySet().contains(annotation.annotationType())) { return annotation; } } return null; } }
完整的项目是 这里 。 以上内容涉及我的问题的第3部分。
对于带有SAML的Shiro,我使用Servicemix包装的openSAML jar,它似乎工作正常,直到现在。但我不得不写一些代码来使Shiro与SAML2一起工作。它与shiro-cas几乎在同一条线上,但与其他IdP一起使用时更为通用。代码有点大,所以共享项目的链接,而不是将类复制到SO。它可以找到 这里 。
现在我的代码和我的IdP之间有一些抽象,WSO2集成看起来有点简单。
附:感谢Achim的意见和建议。