使用apache shiro在restful webservices中使用密码保护的网页

时间:2016-01-03 18:08:49

标签: shiro

我想让我的网站页面密码保护。我使用jersey在java中使用restful webservices制作网站。所以任何人都可以告诉我如何使用apache shiro保护我的网页。任何人已经实现了保护网站的示例如果是,请使用apache shiro而不是plz分享这个例子。我将感激不尽:)

1 个答案:

答案 0 :(得分:0)

为了使用shiro保护您的Web服务,您可以使用以下模板文件,并可以根据您自己的要求进行自定义。包括罐子或根据需要添加到pom。

将这些内容添加到 web.xml

<filter>
        <filter-name>Shiro</filter-name>
        <filter-class>
            org.apache.shiro.web.servlet.IniShiroFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Shiro</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

现在将 shiro.ini 放在 WEB-INF 中(我在shiro.ini中使用基本身份验证,可以使用数据库等中的用户名和角色)根据您的需要,假设/ rest是泽西休息服务的网址)

[main]



    [urls]
    /rest/** = noSessionCreation,authcBasic
    /**= anon

    [users]
    admin=admin