apikey validate

This commit is contained in:
Captain.B 2020-07-01 15:53:32 +08:00
parent 32ecb65cc1
commit 571d32a4fc
1 changed files with 8 additions and 0 deletions

View File

@ -2,13 +2,16 @@ package io.metersphere.controller;
import io.metersphere.base.domain.UserKey; import io.metersphere.base.domain.UserKey;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.security.ApiKeyHandler;
import io.metersphere.service.UserKeyService; import io.metersphere.service.UserKeyService;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import java.util.List; import java.util.List;
@RestController @RestController
@ -24,6 +27,11 @@ public class UserKeysController {
return userKeyService.getUserKeysInfo(userId); return userKeyService.getUserKeysInfo(userId);
} }
@GetMapping("validate")
public String validate(ServletRequest request) {
return ApiKeyHandler.getUser(WebUtils.toHttp(request));
}
@GetMapping("generate") @GetMapping("generate")
public void generateUserKey() { public void generateUserKey() {
String userId = SessionUtils.getUser().getId(); String userId = SessionUtils.getUser().getId();