开发者

How to check if user has right in spring security?

I checked this question, and I know how to get and check user role in java.

But, what I want is, when user clicks some links in page, if user has no right on that, how can I get it and return some message like "no rights" in a message fields? Currently, there will be an exception.

I didn't use spring tags in page, I know the开发者_如何学Go tags that display this link if only user has some role. But I don't want to user those tags for some reasons.


You can use JavaScript, handle the click event on the link and see the server response. If it's not ok - show error message. If it is OK - redirect.

Something like this:

$('#your-link-id').click(function(event) {
    event.preventDefault();
    var url = $(this).attr('href');

    $.ajax({
        url : url,
        success : function() {
            window.location = url;
        },
        error : function() {
            alert('You cannot go to this link.');
        }
    });
});

(jQuery library is used).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜