【发布时间】:2017-04-16 21:29:55
【问题描述】:
在我的简单 Web 应用程序中,我有两种 Web 服务方法。一个是storeName(),另一个是viewAllNames() 方法。
管理员角色可以访问这两种方法。但用户角色应该是访问 viewAllNames() 方法。
我将使用 Apache shiro,maven 以及基于 Web 的项目和休息服务。仅为这两种方法提供授权。
我的实际休息网址是:
http://localhost:8080/SimpleRest/simpleservice/store/jackreobert --> admin only
http://localhost:8080/SimpleRest/simpleservice/viewall/ --> user only
如何配置shiro.ini、web.xml和annotaion/xml。
对于 shiro 方法,我是否需要将任何其他信息传递到 Web 服务 url,如何实现这一点。
SimpleService.java
package com.simple.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.json.JSONException;
@Path("/simpleservice")
public class SimpleService {
@Path("/store/{name}")
@GET
@Produces("application/json")
public Response storeName(@PathParam("name") String name) throws JSONException {
/**
* Here insert logic
*/
String result = "Given name: " + name + " successfully stored";
return Respo}nse.status(200).entity(result).build();
}
@Path("/viewall")
@GET
@Produces("application/json")
public Response viewAllNames() throws JSONException {
/**
* Here retrieve logic
*/
String result = "All names are taken";
return Response.status(200).entity(result).build();
}}
感谢您阅读我的帖子。 帮我, 提前致谢。
【问题讨论】:
标签: apache rest authorization shiro