繁体   English   中英

如何在web.xml中为安全注释配置实体过滤范围?

[英]How do I configure my entity-filtering scope for security annotations in the web.xml?

阅读球衣文档: https : //jersey.java.net/documentation/latest/entity-filtering.html我能够通过将SecurityEntityFilteringFeature以及其他激活的功能添加到我的web.xml中来激活它。

所以我的web.xml的功能部分看起来像这样:

    ...
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>
            org.glassfish.jersey.server.gae.GaeFeature;
            org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
            org.glassfish.jersey.media.multipart.MultiPartFeature;
            org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
            org.glassfish.jersey.message.filtering.SecurityEntityFilteringFeature;
        </param-value>
    </init-param>
    ...

注释@PermitAll(什么都不会改变)和@DenyAll(总是从json中删除实体)非常有用。

问题是:要使用@RolesAllowed注释,我还需要按照文档中所述在实体过滤范围中注册角色

EntityFilteringFeature.ENTITY_FILTERING_SCOPE-“ jersey.config.entityFiltering.scope”

定义一个或多个注释,在读取/写入实体时应将其用作实体过滤范围。

但是我只能通过web.xml对其进行配置,并且无处可做:

new ResourceConfig()
// Set entity-filtering scope via configuration.
.property(EntityFilteringFeature.ENTITY_FILTERING_SCOPE, new Annotation[] {SecurityAnnotations.rolesAllowed("manager")})
// Register the SecurityEntityFilteringFeature.
.register(SecurityEntityFilteringFeature.class)
// Further configuration of ResourceConfig.
.register( ... );

有什么猜想吗?

您可以一起使用ResourceConfig web.xml。 它不是“一个或另一个”。 例如

<servlet>
    <servlet-name>MyApplication</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>org.foo.JerseyConfig</param-value>
    </init-param>
</servlet>

package org.foo;

public class JerseyConfig extends ResourceConfig {
    public JerseyConfig() {
        register(...);
        property(...);
    }
}

web.xml和ResourceConfig注册/配置/属性等都将被使用。 您可以在此处查看其他一些部署选项。

如果您确实必须远离ResourceConfig (不确定为什么会出现这种问题),则可以随时创建Feature

@Provider
public class MyFilteringFeature implements Feature {

    @Override
    public boolean configure(FeatureContext context) {
        context.property(...);
        context.register(...);
        return true;
    }
}

然后,只需注册该功能(除非您正在扫描软件包,否则应使用@Provider注释将其@Provider )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM