Java 如何在RESTfulWebService中排除特殊用户的安全检查验证

Java 如何在RESTfulWebService中排除特殊用户的安全检查验证,java,rest,security-constraint,Java,Rest,Security Constraint,我正在使用RESTWeb服务获取文件路径。这里我使用一个安全上下文来提供一些额外的安全性。我使用了关于登录用户必须与web服务URL中指定的用户名相同的验证(安全检查) 但我有一个特殊情况,我有一个用户,用于从服务器获取特殊文件路径。若我从web服务URL传递此用户,它将在安全上下文验证中被捕获,因为登录用户和URL指定的用户不相同 所以有任何其他方法可以将特殊用户排除在安全检查之外。 我可以在web.xml中指定一些配置来解决这个问题吗 e、 g 及 我想让它通过没有,做当用户从URL是abc

我正在使用RESTWeb服务获取文件路径。这里我使用一个安全上下文来提供一些额外的安全性。我使用了关于登录用户必须与web服务URL中指定的用户名相同的验证(安全检查

但我有一个特殊情况,我有一个用户,用于从服务器获取特殊文件路径。若我从web服务URL传递此用户,它将在安全上下文验证中被捕获,因为登录用户和URL指定的用户不相同

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

e、 g

我想让它通过没有,做当用户从URL是abc然后允许它在安全检查

以下是用于检查有效用户的web服务代码

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; 
        }

您应该使用角色和安全注释

我也不明白,为什么用户名是url的一部分。不一定要这样。你知道用户名。所有用户的Url应该相同,并且只返回当前已验证用户的相关数据。这样你就不会有这些问题了

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


@允许角色(“标准角色”)
192.168.0.132/download.ws/fileid


@允许角色(“超级用户”)
192.168.0.132/download.ws/{special_path_pattern}/fileid

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.
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; 
        }