use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.
the class TeamController method updateRole.
/**
* Updates role of a team member.
* Needs role master.
*
* @param teamId
* @param id
* @param roleValue
* @return
* @throws ShepherException
*/
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/role", method = RequestMethod.POST)
public String updateRole(@PathVariable("team") long teamId, @RequestParam("id") long id, @RequestParam("role") int roleValue) throws ShepherException {
Role role = Role.get(roleValue);
if (role == null) {
throw ShepherException.createNoSuchRoleException();
}
teamService.updateRole(id, role);
return "redirect:/teams/" + teamId + "/manage";
}
use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.
the class TeamController method agree.
/**
* Agrees a user to join a team.
* Needs role master.
*
* @param teamId
* @param id
* @return
* @throws ShepherException
*/
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/agree", method = RequestMethod.POST)
public String agree(@PathVariable("team") long teamId, @RequestParam("id") long id) throws ShepherException {
User user = userHolder.getUser();
teamService.agreeJoin(user, id, teamId);
return "redirect:/teams/" + teamId + "/manage";
}
use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.
the class TeamController method addMember.
/**
* Adds a user to a team.
* Needs role master.
*
* @param teamId
* @param userName
* @param roleValue
* @return
* @throws ShepherException
*/
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/members/add", method = RequestMethod.POST)
public String addMember(@PathVariable("team") long teamId, @RequestParam("user") String userName, @RequestParam("role") int roleValue) throws ShepherException {
User member = userService.get(userName);
User user = userHolder.getUser();
Role role = Role.get(roleValue);
if (member == null) {
throw ShepherException.createNoSuchUserException();
} else if (role == null) {
throw ShepherException.createNoSuchRoleException();
}
teamService.addMember(member, teamId, role, user);
return "redirect:/teams/" + teamId + "/manage";
}
use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.
the class AuthorizationInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Auth annotation = getAnnotation(handlerMethod);
if (annotation != null && !authStrategy.validate(request, annotation.value())) {
throw ShepherException.createNoAuthorizationException();
}
}
return true;
}
use of com.xiaomi.shepher.common.Auth in project shepher by XiaoMi.
the class TeamController method refuse.
/**
* Refuses a user to join a team.
* Needs role master.
*
* @param teamId
* @param id
* @return
* @throws ShepherException
*/
@Auth(Jurisdiction.TEAM_MASTER)
@RequestMapping(value = "/{team}/refuse", method = RequestMethod.POST)
public String refuse(@PathVariable("team") long teamId, @RequestParam("id") long id) throws ShepherException {
User user = userHolder.getUser();
teamService.refuseJoin(user, id, teamId);
return "redirect:/teams/" + teamId + "/manage";
}
Aggregations