Spring boot:在控制器之前使用标头进行授权

时间:2016-08-04 10:25:23

标签: java spring spring-security spring-boot

我正在使用我的spring boot REST API和控制器,如下所示: -  `

@Autowired
 HazelcastInstance hazelcastinstance;
 String username="VAKSDNDDODM#DLDM#DMOD#DI@#*@EK";
@RestController
@RequestMapping(value = "/Acode/availabile/multiple/{Code}/")
public class MultiController {

    @Resource(name = "AService")
    protected AImpl AService;

    @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Response> readMulti(
            @RequestHeader(value="Auth-Token") String token,
            @RequestBody XRequest Request,
            @PathVariable String Code)  throws Exception {
        if(token.equalsIgnoreCase(username))
        {
        Response response = AService.readMultiX(Request, Code);
        }
        else
        {
            response.setMessage("Unauthorized access!");
        response.setStatus(340);
        }
        return new ResponseEntity<Response>(response, HttpStatus.OK);
    }
}

`

我希望在API控制进入控制器之前进行标题比较,以便在控制器中不需要声明@RequestHeader。是否可以这样做或者我们是否有实现?

0 个答案:

没有答案