加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 访问此资源需要完全身份验证 – Rest webservice调用

发布时间:2020-12-15 01:46:30 所属栏目:大数据 来源:网络整理
导读:我的应用程序是使用spring框架开发的.我使用spring框架创建了一个新的rest webservice. @Controllerpublic class MyTestController { @Inject private MyService service; @RequestMapping(value = "/acc/Status/{accNum}",method = RequestMethod.GET) @Res

我的应用程序是使用spring框架开发的.我使用spring框架创建了一个新的rest webservice.

@Controller
public class MyTestController {
   @Inject
    private MyService service;

    @RequestMapping(value = "/acc/Status/{accNum}",method = RequestMethod.GET)
    @ResponseBody
    public String getAccStatus(@PathVariable final String accNum,final HttpServletResponse response) throws Exception
        {
        //logic goes here
        return "success";
  }

为MyService:

public interface BusinessCalendarService {

 //methods..
}

我想看看上面的webservice的响应.我正在使用邮差工具查看回复.
当我提出请求时
http://localhost:8080/myApplication/rest/acc/Status/322298973,它显示以下消息.

HTTP Status 401 - Full authentication is required to access this resource

现有的控制器工作正常,它与我的控制器显示上述消息.请建议我是否需要进行任何代码修改?我按照与编写其他控制器相同的方式进行操作.

最佳答案
您需要在发布到该uri之前对用户进行身份验证,或者,如果它是应该能够在未经过身份验证的情况下访问的uri,请将uri添加到配置的http安全性部分中的authorizeRequests().antMatcher() .

https://docs.spring.io/spring-security/site/docs/3.2.8.RELEASE/apidocs/org/springframework/security/config/annotation/web/builders/HttpSecurity.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读