本文整理汇总了Java中org.apache.shiro.authz.annotation.RequiresAuthentication类的典型用法代码示例。如果您正苦于以下问题:Java RequiresAuthentication类的具体用法?Java RequiresAuthentication怎么用?Java RequiresAuthentication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequiresAuthentication类属于org.apache.shiro.authz.annotation包,在下文中一共展示了RequiresAuthentication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addProblemTestCase
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("添加一道题目的一个测试用例")
@RequiresAuthentication
@PostMapping("/{pid}/test_cases")
public ResponseEntity addProblemTestCase(
@PathVariable("pid") int pid,
@RequestBody @Valid AddProblemTestCaseFormat format) {
ProblemEntity problemEntity = problemService.getProblemByPid(pid);
haveProblem(problemEntity);
havePermission(problemEntity);
// 添加test_case
int tid = testCasesService.addTestCase(pid, format.getStdin(), format.getStdout(), format.getStrength());
if (tid == 0) {
throw new WebErrorException("添加失败");
}
return new ResponseEntity("添加成功", tid);
}
示例2: deleteProblemTestCase
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("删除指定的test_case")
@RequiresAuthentication
@DeleteMapping("/{pid}/test_case/{tid}")
public ResponseEntity deleteProblemTestCase(@PathVariable("pid") int pid,
@PathVariable("tid") int tid) {
ProblemEntity problemEntity = problemService.getProblemByPid(pid);
haveProblem(problemEntity);
havePermission(problemEntity);
// 删除test_case
if (! testCasesService.deleteTestCaseByTid(tid)) {
throw new WebErrorException("删除失败");
}
return new ResponseEntity("删除成功");
}
示例3: updateProblemTestCase
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("更新指定的test_case")
@RequiresAuthentication
@PutMapping("/{pid}/test_case/{tid}")
public ResponseEntity updateProblemTestCase(@PathVariable("pid") int pid,
@PathVariable("tid") int tid,
@RequestBody @Valid AddProblemTestCaseFormat format) {
ProblemEntity problemEntity = problemService.getProblemByPid(pid);
haveProblem(problemEntity);
havePermission(problemEntity);
if (! testCasesService.updateTestCaseByTidPid(tid, pid, format.getStdin(), format.getStdout(),
format.getStrength())) {
throw new WebErrorException("更新失败");
}
return new ResponseEntity("更新成功");
}
示例4: addProblemModerator
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("添加指定的moderator")
@RequiresAuthentication
@PostMapping("/{pid}/moderator")
public ResponseEntity addProblemModerator(@PathVariable("pid") int pid,
@RequestBody @Valid AddProblemModeratorFormat format) {
ProblemEntity problemEntity = problemService.getProblemByPid(pid);
haveProblem(problemEntity);
if (SessionHelper.get().getUid() != problemEntity.getOwner()) {
throw new WebErrorException("非法操作");
}
UserEntity userEntity = userService.getUserByEmail(format.getEmail());
WebUtil.assertNotNull(userEntity, "此用户不存在");
if (problemModeratorService.isExist(pid, userEntity.getUid())) {
throw new WebErrorException("已存在此用户");
}
if (! problemModeratorService.add(pid, userEntity.getUid())) {
throw new WebErrorException("添加用户失败");
}
return new ResponseEntity("添加成功");
}
示例5: deleteProblemModerator
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("删除指定的moderator")
@RequiresAuthentication
@DeleteMapping("/{pid}/moderator/{uid}")
public ResponseEntity deleteProblemModerator(@PathVariable("pid") int pid,
@PathVariable("uid") int uid) {
ProblemEntity problemEntity = problemService.getProblemByPid(pid);
haveProblem(problemEntity);
if (SessionHelper.get().getUid() != problemEntity.getOwner()) {
throw new WebErrorException("非法操作");
}
if (! problemModeratorService.delete(pid, uid)) {
throw new WebErrorException("删除用户失败");
}
return new ResponseEntity("删除用户成功");
}
示例6: getMeInfo
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("获取用户在小组中的信息")
@RequiresAuthentication
@GetMapping("/{gid}/user/{uid}")
public ResponseEntity getMeInfo(@PathVariable("gid") int gid,
@PathVariable("uid") int uid) {
if (uid != SessionHelper.get().getUid()) {
throw new UnauthorizedException();
}
GroupUserEntity entity = groupUserService.getMember(gid, uid);
if (entity == null) {
throw new WebErrorException("用户不在小组中");
}
if (entity.getRealName() == null) {
entity.setRealName("");
}
return new ResponseEntity(entity);
}
示例7: kickUser
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("踢出用户或者自己退出")
@RequiresAuthentication
@DeleteMapping("/{gid}/user/{uid}")
public ResponseEntity kickUser(@PathVariable int gid,
@PathVariable int uid) {
GroupEntity groupEntity = groupService.getGroup(gid);
haveGroup(groupEntity);
// 校验被踢出或者自己退出
if (! (SessionHelper.get().getUid() == uid)) {
havePermission(groupEntity);
}
// 删除用户
if (! groupUserService.deleteMember(gid, uid)) {
throw new WebErrorException("删除用户失败");
}
return new ResponseEntity("用户删除成功");
}
示例8: updateUserRealName
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("更新用户组内名称")
@RequiresAuthentication
@PutMapping("/{gid}/user/{uid}")
public ResponseEntity updateUserRealName(@PathVariable int gid,
@PathVariable int uid,
@RequestBody @Valid UpdateGroupUserFormat format) {
if (uid != SessionHelper.get().getUid()) {
throw new UnauthorizedException();
}
if (! groupUserService.updateRealName(gid, uid, format.getRealName())) {
throw new WebErrorException("更新失败");
}
return new ResponseEntity("更新成功");
}
示例9: pullUsersIntoContest
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("将用户拉入某个比赛")
@RequiresAuthentication
@PostMapping("/{gid}/pull_contest")
public ResponseEntity pullUsersIntoContest(@PathVariable int gid,
@RequestBody @Valid PullUsersIntoContestFormat format) {
GroupEntity groupEntity = groupService.getGroup(gid);
haveGroup(groupEntity);
havePermission(groupEntity);
ContestEntity contestEntity = contestService.getContestByCid(format.getCid());
haveContest(contestEntity);
String password = contestEntity.getPassword();
if (password!= null) {
if (! password.equals(format.getPassword()) ) {
throw new WebErrorException("小组密码错误");
}
}
PullGroupUserIntoContestTask task = new PullGroupUserIntoContestTask(gid, groupEntity.getName(),
format.getCid(), contestEntity.getName());
task.setType(3);
messageQueue.addTask(task);
return new ResponseEntity("操作成功");
}
示例10: getUserInfo
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("获取用户的所有信息")
@GetMapping("/info")
@RequiresAuthentication
public ResponseEntity getUserInfo() {
int uid = SessionHelper.get().getUid();
UserEntity userEntity = userService.getUserByUid(uid);
String avatar;
if (userEntity.getAvatar() == 0) {
avatar = DEFAULT_AVATAR;
} else {
avatar = attachmentService.get(userEntity.getAvatar()).getUrl();
}
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(userEntity));
jsonObject.remove("password");
jsonObject.replace("avatar", avatar);
return new ResponseEntity(jsonObject);
}
示例11: uploadAvatar
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@ApiOperation("头像上传")
@PostMapping("/profile/avatar")
@RequiresAuthentication
public ResponseEntity uploadAvatar(@RequestParam("file") MultipartFile file) throws IOException {
int uid = SessionHelper.get().getUid();
if (file.getSize()/1000 > 2*1024) {
throw new WebErrorException("文件过大");
}
if (! file.getContentType().equals("image/jpeg")) {
throw new WebErrorException("文件格式非法");
}
String filePath = fileUtil.uploadAvatar(file.getInputStream(), "jpg");
if (filePath == null) {
throw new WebErrorException("文件上传失败");
}
int aid = attachmentService.add(uid, filePath);
if (! userService.updateUserAvatar(uid, aid)) {
throw new WebErrorException("头像更新失败");
}
return new ResponseEntity("头像更新成功");
}
示例12: index
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@RequiresAuthentication
@RequestMapping(path = {"/index","/"} ,method = RequestMethod.GET)
public String index(Model model){
model.addAttribute("name","Alex");
Subject subject = SecurityUtils.getSubject();
AdminDO admin = (AdminDO) subject.getPrincipal();
AdminInfoVO adminInfoVO = new AdminInfoVO();
BeanUtils.copyProperties(admin, adminInfoVO);
adminInfoVO.setRoleId(admin.getRole().getRoleId());
model.addAttribute("admin", adminInfoVO);
List<MenuDO> menuLists = roleMenuService.getMenusByRoleId(admin.getRole().getRoleId(), true);
MenuTreeUtil menuTreeUtil = new MenuTreeUtil(menuLists,null);
List<MenuDO> treeGrid = menuTreeUtil.buildTreeGrid();
model.addAttribute("menuLists",treeGrid);
return "index";
}
示例13: updateOutput
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@PUT
@Path("/configurations/{id}/outputs/{output_id}")
@RequiresAuthentication
@RequiresPermissions(CollectorRestPermissions.COLLECTORS_UPDATE)
@ApiOperation(value = "Update a configuration output",
notes = "This is a stateless method which updates a collector output")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "The supplied request is not valid.")
})
@AuditEvent(type = CollectorAuditEventTypes.OUTPUT_UPDATE)
public Response updateOutput(@ApiParam(name = "id", required = true)
@PathParam("id") @NotEmpty String id,
@ApiParam(name = "output_id", required = true)
@PathParam("output_id") @NotEmpty String outputId,
@ApiParam(name = "JSON body", required = true)
@Valid @NotNull CollectorOutput request) {
etagService.invalidateAll();
final CollectorConfiguration collectorConfiguration = collectorConfigurationService.updateOutputFromRequest(id, outputId, request);
collectorConfigurationService.save(collectorConfiguration);
return Response.accepted().build();
}
示例14: updateInput
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@PUT
@Path("/configurations/{id}/inputs/{input_id}")
@RequiresAuthentication
@RequiresPermissions(CollectorRestPermissions.COLLECTORS_UPDATE)
@ApiOperation(value = "Update a configuration input",
notes = "This is a stateless method which updates a collector input")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "The supplied request is not valid.")
})
@AuditEvent(type = CollectorAuditEventTypes.INPUT_UPDATE)
public Response updateInput(@ApiParam(name = "id", required = true)
@PathParam("id") @NotEmpty String id,
@ApiParam(name = "input_id", required = true)
@PathParam("input_id") @NotEmpty String inputId,
@ApiParam(name = "JSON body", required = true) @Valid @NotNull CollectorInput request) {
etagService.invalidateAll();
final CollectorConfiguration collectorConfiguration = collectorConfigurationService.updateInputFromRequest(id, inputId, request);
collectorConfigurationService.save(collectorConfiguration);
return Response.accepted().build();
}
示例15: updateSnippet
import org.apache.shiro.authz.annotation.RequiresAuthentication; //导入依赖的package包/类
@PUT
@Path("/configurations/{id}/snippets/{snippet_id}")
@RequiresAuthentication
@RequiresPermissions(CollectorRestPermissions.COLLECTORS_UPDATE)
@ApiOperation(value = "Update a configuration snippet",
notes = "This is a stateless method which updates a collector snippet")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "The supplied request is not valid.")
})
@AuditEvent(type = CollectorAuditEventTypes.SNIPPET_UPDATE)
public Response updateSnippet(@ApiParam(name = "id", required = true)
@PathParam("id") @NotEmpty String id,
@ApiParam(name = "snippet_id", required = true)
@PathParam("snippet_id") @NotEmpty String snippetId,
@ApiParam(name = "JSON body", required = true)
@Valid @NotNull CollectorConfigurationSnippet request) {
etagService.invalidateAll();
final CollectorConfiguration collectorConfiguration = collectorConfigurationService.updateSnippetFromRequest(id, snippetId, request);
collectorConfigurationService.save(collectorConfiguration);
return Response.accepted().build();
}