Jersey REST:How to write a jersey method including

2019-05-30 07:44发布

I am writing a Restful webservice method,which require authorization first... such as a findItems method..which need username and password in Http Authorization the sample code:

@GET
@Produce(MediaType.APPLICATION_JSON)
public String findItems(){

...
}

how to verify the http authorization before the method excutes...

标签: java rest jersey
2条回答
劳资没心,怎么记你
2楼-- · 2019-05-30 08:19

you can use Filters so you can check the authorization

查看更多
爷、活的狠高调
3楼-- · 2019-05-30 08:26

I use a user-type and role-type control with a basic JAAS authentication. After authentication, the client makes http GET requests to the REST web service. In my Facade get method, I inject the @Context SecurityContext as input parameter, and use if for user / role identification in order to provide the correct answer to the GET request, depending on the user's role.

See here for an example of what I mean: Using JaaS with Jersey on Grizzly

查看更多
登录 后发表回答