如何从 restful 网络服务中的安全检查验证中排除特殊用户

how to exclude special users from security check validation in restful webservice

我正在使用休息网络服务来获取文件路径。这里我使用安全上下文来提供一些额外的安全性。我使用验证登录用户必须与 Web 服务中指定的用户名相同 URL(安全检查)。

但我有一个特殊情况,我有一个用户用于从服务器获取特殊文件路径。如果我从网络服务 URL 传递此用户,它会陷入安全上下文验证,因为登录用户和 URL 指定用户不相同。

所以还有其他方法可以将特殊用户排除在安全检查之外。 我可以在 web.xml 中指定一些配置来解决这个问题吗?

例如

condition 1 

logged-in user - xyz
web-service URL - 192.168.0.132/download.ws/xyz/fileid

passed in security checked.

condition 2 

logged-in user - xyz
abc is valid and authorized user.
web-service URL - 192.168.0.132/download.ws/abc/fileid

failed in security checked.

我想让它在没有的情况下通过,当来自 URL 的用户是 abc 然后允许它进行安全检查时做。

这是检查有效用户的网络服务代码

public String getCallerId(SecurityContext sc) {

        // we always create a GenericPrincipal object in AuthService
        GenericPrincipal userPrincipal = (GenericPrincipal) sc.getUserPrincipal();
        String szUserEmailID= userPrincipal.getName();

        return szUserEmailID;
    }

    public boolean authorizeRequest(SecurityContext osc, String szResourceID,   String reqType) {
            if( getCallerId(osc).equalsIgnoreCase(szResourceID)) // check for logged-in user and user specified in web-service url
                return true;
            return false; 
        }

您应该使用角色和安全注释。 https://blogs.oracle.com/swchan/entry/servlet_3_0_security_annotations

我也不明白,为什么用户名是 url 的一部分。它不一定是那样的。你知道用户名。 Url 应该对所有用户都是相同的,并且只有 return 当前经过身份验证的用户的相关数据。这样你就不会遇到这些问题了。

然后您可以允许以下操作:

@RolesAllowed("StandardRole") 192.168.0.132/download.ws/fileid

@RolesAllowed("SuperUser") 192.168.0.132/download.ws/{special_path_pattern}/fileid