我正在使用shiro来验证我的休息api,我已经配置了jaxrs来使用ShiroFeature之类的
<jaxrs:server address="/" id="shiroRestService">
<jaxrs:serviceBeans>
<ref component-id="shiroRestServiceImpl"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.apache.shiro.web.jaxrs.ShiroFeature"/>
</jaxrs:providers>
</jaxrs:server>
在我的休息服务中,我使用了@RequiresAuthentication之类的
@Path("shiro")
@RequiresAuthentication
public interface ShiroRestService {
@GET
@Path("hello/{name}")
public String handleGet(@PathParam("name") String name);
}
我的shiro.ini文件是
exampleuser = examplepassword, examplerole
[roles]
examplerole = something:readpermission
[urls]
/** = noSessionCreation, authcBasic
但是我可以在没有身份验证的情况下访问我的其他api,我已经检查了这里提到的所有解决方案和其他博客中的教程,但是所有这些都讨论了在Web应用程序(war文件)中验证rest api我的是没有web的jar文件。 XML。请让我知道如何解决这个问题
完整的代码可以在github找到
我已经使用shiro为jax-rs实现了基本身份验证,并且源代码可以在https://github.com/nmojir/rest-basic-auth上获得。另外我意识到RequiresAuthentication批注不适用于接口,它适用于我的具体类。但我没有意识到为什么!